	.include "global.inc"
	.include "asm/macros.inc"

	.data

	.global __files
__files: ; 0x02106A58
	; stdin
	.byte 0x00, 0x00, 0x00, 0x00, 0x24, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.word stdin_buff
	.byte 0x00, 0x01, 0x00, 0x00
	.word stdin_buff
	.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.word __read_console
	.word __write_console
	.word __close_console
	.byte 0x00, 0x00, 0x00, 0x00

	; stdout
	.byte 0x01, 0x00, 0x00, 0x00, 0x28, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.word stdout_buff
	.byte 0x00, 0x01, 0x00, 0x00
	.word stdout_buff
	.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.word __read_console
	.word __write_console
	.word __close_console
	.byte 0x00, 0x00, 0x00, 0x00

	; stderr
	.byte 0x02, 0x00, 0x00, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.word stderr_buff
	.byte 0x00, 0x01, 0x00, 0x00
	.word stderr_buff
	.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.word __read_console
	.word __write_console
	.word __close_console
	.byte 0x00, 0x00, 0x00, 0x00
	.size __files,.-__files

	.bss

	.global stderr_buff
stderr_buff: ; 0x021D71A8
	.space 0x100
	.size stderr_buff,.-stderr_buff

	.global stdout_buff
stdout_buff: ; 0x021D72A8
	.space 0x100
	.size stdout_buff,.-stdout_buff

	.global stdin_buff
stdin_buff: ; 0x021D73A8
	.space 0x100
	.size stdin_buff,.-stdin_buff

	.text

	arm_func_start __flush_line_buffered_output_files
__flush_line_buffered_output_files:
	stmdb sp!, {r3-r9,lr}
	ldr r0, _020DE384 ; =__files
	mov r4, #0x0
	mov r5, #0x1
	mov r8, r0
	mvn r9, #0x0
	mov r7, r4
	mov r6, #0x4c
_020DE31C:
	ldr r1, [r0, #0x4]
	mov r2, r1, lsl #0x16
	movs r2, r2, lsr #0x1d
	beq _020DE35C
	mov r1, r1, lsl #0x19
	mov r1, r1, lsr #0x1e
	tst r1, #0x1
	beq _020DE35C
	ldr r1, [r0, #0x8]
	mov r1, r1, lsl #0x1d
	mov r1, r1, lsr #0x1d
	cmp r1, #0x1
	bne _020DE35C
	bl fflush
	cmp r0, #0x0
	movne r4, r9
_020DE35C:
	cmp r5, #0x3
	movge r0, r7
	bge _020DE374
	mul r0, r5, r6
	add r5, r5, #0x1
	add r0, r8, r0
_020DE374:
	cmp r0, #0x0
	bne _020DE31C
	mov r0, r4
	ldmia sp!, {r3-r9,pc}
	.balign 4
_020DE384: .word __files
	arm_func_end __flush_line_buffered_output_files

	arm_func_start __flush_all
__flush_all: ; 0x020DE388
	stmdb sp!, {r3-r9,lr}
	ldr r0, _020DE3EC ; =__files
	mov r4, #0x0
	mov r5, #0x1
	mov r8, r0
	mvn r9, #0x0
	mov r7, r4
	mov r6, #0x4c
_020DE3A8:
	ldr r1, [r0, #0x4]
	mov r1, r1, lsl #0x16
	movs r1, r1, lsr #0x1d
	beq _020DE3C4
	bl fflush
	cmp r0, #0x0
	movne r4, r9
_020DE3C4:
	cmp r5, #0x3
	movge r0, r7
	bge _020DE3DC
	mul r0, r5, r6
	add r5, r5, #0x1
	add r0, r8, r0
_020DE3DC:
	cmp r0, #0x0
	bne _020DE3A8
	mov r0, r4
	ldmia sp!, {r3-r9,pc}
	.balign 4
_020DE3EC: .word __files
	arm_func_end __flush_all

	exception __flush_line_buffered_output_files, 141, 0x00403F00
	exception __flush_all, 105, 0x00403F00
