// File: /workspace/github_c_makefile_star2_O0/dlbeer[P]ufat/ufat_dir.c
// Function: ufat_dir_read
int ufat_dir_read(struct ufat_directory *dir, struct ufat_dirent *inf,
		  char *lfn_buf, int max_len)
{
	struct ufat_lfn_parser lfn;

	ufat_lfn_reset(&lfn);

	for (;;) {
		uint8_t data[UFAT_DIRENT_SIZE];
		int err;

		inf->dirent_block = dir->cur_block;
		inf->dirent_pos = dir->cur_pos;

		err = ufat_read_raw_dirent(dir, data);
		if (err)
			return err;

		err = ufat_advance_raw_dirent(dir, 0);
		if (err)
			return err;

		if (data[0x0b] == 0x0f && data[0] != 0xe5) {
			ufat_lfn_parse(&lfn, data,
				       inf->dirent_block, inf->dirent_pos);
		} else if (data[0] && data[0] != 0xe5) {
			ufat_parse_dirent(dir->uf->bpb.type, data, inf);

			if (ufat_short_checksum(inf->short_name,
						inf->short_ext) !=
			    lfn.short_checksum)
				ufat_lfn_reset(&lfn);

			if (inf->attributes & 0x08) {
				ufat_lfn_reset(&lfn);
				continue;
			}

			if (ufat_lfn_ok(&lfn)) {
				inf->lfn_block = lfn.start_block;
				inf->lfn_pos = lfn.start_pos;
			} else {
				inf->lfn_block = UFAT_BLOCK_NONE;
				inf->lfn_pos = 0;
			}

			if (lfn_buf)
				return format_name(&lfn, inf, lfn_buf, max_len);

			return 0;
		} else {
			ufat_lfn_reset(&lfn);
		}
	}

	return 0;
}

// Assembly:
subq $0x278, %rsp            # imm = 0x278
movq %rdi, 0x268(%rsp)
movq %rsi, 0x260(%rsp)
movq %rdx, 0x258(%rsp)
movl %ecx, 0x254(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x4010
movq 0x268(%rsp), %rax
movq 0x10(%rax), %rcx
movq 0x260(%rsp), %rax
movq %rcx, (%rax)
movq 0x268(%rsp), %rax
movl 0x8(%rax), %ecx
movq 0x260(%rsp), %rax
movl %ecx, 0x8(%rax)
movq 0x268(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x6380
movl %eax, 0xc(%rsp)
cmpl $0x0, 0xc(%rsp)
je 0x3e5a
movl 0xc(%rsp), %eax
movl %eax, 0x274(%rsp)
jmp 0x3ffa
movq 0x268(%rsp), %rdi
xorl %esi, %esi
callq 0x60e0
movl %eax, 0xc(%rsp)
cmpl $0x0, 0xc(%rsp)
je 0x3e84
movl 0xc(%rsp), %eax
movl %eax, 0x274(%rsp)
jmp 0x3ffa
movzbl 0x1b(%rsp), %eax
cmpl $0xf, %eax
jne 0x3ec4
movzbl 0x10(%rsp), %eax
cmpl $0xe5, %eax
je 0x3ec4
leaq 0x10(%rsp), %rsi
movq 0x260(%rsp), %rax
movq (%rax), %rdx
movq 0x260(%rsp), %rax
movl 0x8(%rax), %ecx
leaq 0x38(%rsp), %rdi
callq 0x7150
jmp 0x3ff5
movzbl 0x10(%rsp), %eax
cmpl $0x0, %eax
je 0x3fe9
movzbl 0x10(%rsp), %eax
cmpl $0xe5, %eax
je 0x3fe9
movq 0x268(%rsp), %rax
movq (%rax), %rax
movl 0x28(%rax), %edi
leaq 0x10(%rsp), %rsi
movq 0x260(%rsp), %rdx
callq 0x6670
movq 0x260(%rsp), %rdi
addq $0x1c, %rdi
movq 0x260(%rsp), %rsi
addq $0x25, %rsi
callq 0x7560
movzbl %al, %eax
movzbl 0x44(%rsp), %ecx
cmpl %ecx, %eax
je 0x3f35
leaq 0x38(%rsp), %rdi
callq 0x4010
movq 0x260(%rsp), %rax
movl 0x2c(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x3f57
leaq 0x38(%rsp), %rdi
callq 0x4010
jmp 0x3e00
leaq 0x38(%rsp), %rdi
callq 0x4030
cmpl $0x0, %eax
je 0x3f88
movq 0x38(%rsp), %rcx
movq 0x260(%rsp), %rax
movq %rcx, 0x10(%rax)
movl 0x40(%rsp), %ecx
movq 0x260(%rsp), %rax
movl %ecx, 0x18(%rax)
jmp 0x3fa7
movq 0x260(%rsp), %rax
movq $-0x1, 0x10(%rax)
movq 0x260(%rsp), %rax
movl $0x0, 0x18(%rax)
cmpq $0x0, 0x258(%rsp)
je 0x3fdc
movq 0x260(%rsp), %rsi
movq 0x258(%rsp), %rdx
movl 0x254(%rsp), %ecx
leaq 0x38(%rsp), %rdi
callq 0x4050
movl %eax, 0x274(%rsp)
jmp 0x3ffa
movl $0x0, 0x274(%rsp)
jmp 0x3ffa
leaq 0x38(%rsp), %rdi
callq 0x4010
jmp 0x3ff5
jmp 0x3e00
movl 0x274(%rsp), %eax
addq $0x278, %rsp            # imm = 0x278
retq
nopl (%rax)