// File: /workspace/github_c_makefile_star2_O1/lb3361[P]dosfs/ff.c
// Function: dir_read
static FRESULT dir_read (
	DIR* dp,		/* Pointer to the directory object */
	int vol			/* Filtered by 0:file/directory or 1:volume label */
)
{
	FRESULT res = FR_NO_FILE;
	FATFS *fs = dp->obj.fs;
	BYTE attr, b;
#if FF_USE_LFN
	BYTE ord = 0xFF, sum = 0xFF;
#endif

	while (dp->sect) {
		res = move_window(fs, dp->sect);
		if (res != FR_OK) break;
		b = dp->dir[DIR_Name];	/* Test for the entry type */
		if (b == 0) {
			res = FR_NO_FILE; break; /* Reached to end of the directory */
		}
#if FF_FS_EXFAT
		if (fs->fs_type == FS_EXFAT) {	/* On the exFAT volume */
			if (FF_USE_LABEL && vol) {
				if (b == ET_VLABEL) break;	/* Volume label entry? */
			} else {
				if (b == ET_FILEDIR) {		/* Start of the file entry block? */
					dp->blk_ofs = dp->dptr;	/* Get location of the block */
					res = load_xdir(dp);	/* Load the entry block */
					if (res == FR_OK) {
						dp->obj.attr = fs->dirbuf[XDIR_Attr] & AM_MASK;	/* Get attribute */
					}
					break;
				}
			}
		} else
#endif
		{	/* On the FAT/FAT32 volume */
			dp->obj.attr = attr = dp->dir[DIR_Attr] & AM_MASK;	/* Get attribute */
#if FF_USE_LFN		/* LFN configuration */
			if (b == DDEM || b == '.' || (int)((attr & ~AM_ARC) == AM_VOL) != vol) {	/* An entry without valid data */
				ord = 0xFF;
			} else {
				if (attr == AM_LFN) {			/* An LFN entry is found */
					if (b & LLEF) {			/* Is it start of an LFN sequence? */
						sum = dp->dir[LDIR_Chksum];
						b &= (BYTE)~LLEF; ord = b;
						dp->blk_ofs = dp->dptr;
					}
					/* Check LFN validity and capture it */
					ord = (b == ord && sum == dp->dir[LDIR_Chksum] && pick_lfn(fs->lfnbuf, dp->dir)) ? ord - 1 : 0xFF;
				} else {					/* An SFN entry is found */
					if (ord != 0 || sum != sum_sfn(dp->dir)) {	/* Is there a valid LFN? */
						dp->blk_ofs = 0xFFFFFFFF;			/* It has no LFN. */
					}
					break;
				}
			}
#else		/* Non LFN configuration */
			if (b != DDEM && b != '.' && attr != AM_LFN && (int)((attr & ~AM_ARC) == AM_VOL) == vol) {	/* Is it a valid entry? */
				break;
			}
#endif
		}
		res = dir_next(dp, 0);		/* Next entry */
		if (res != FR_OK) break;
	}

	if (res != FR_OK) dp->sect = 0;		/* Terminate the read operation on error or EOT */
	return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %r15d
movq %rdi, %rbx
movq 0x38(%rdi), %rsi
movl $0x4, %ebp
testq %rsi, %rsi
je 0x78f8
movq (%rbx), %r14
movb $-0x1, %r12b
movb $-0x1, %r13b
movq %r14, %rdi
callq 0x6314
testl %eax, %eax
jne 0x78b5
movq 0x40(%rbx), %rax
movzbl (%rax), %ecx
testl %ecx, %ecx
je 0x78f8
cmpb $0x4, (%r14)
jne 0x7770
testl %r15d, %r15d
je 0x77ef
cmpb $-0x7d, %cl
jne 0x77f8
jmp 0x78f6
movb 0xb(%rax), %sil
movl %esi, %edx
andb $0x3f, %dl
movb %dl, 0xa(%rbx)
cmpl $0x2e, %ecx
je 0x77ea
cmpl $0xe5, %ecx
je 0x77ea
andb $0x1f, %sil
xorl %edi, %edi
cmpb $0x8, %sil
sete %dil
cmpl %r15d, %edi
jne 0x77ea
cmpb $0xf, %dl
jne 0x78b9
testb $0x40, %cl
je 0x77ba
movb 0xd(%rax), %r12b
andb $-0x41, %cl
movl 0x30(%rbx), %edx
movl %edx, 0x54(%rbx)
movl %ecx, %r13d
cmpb %r13b, %cl
jne 0x77ea
cmpb 0xd(%rax), %r12b
jne 0x77ea
movb 0x1a(%rax), %dl
movb $0x1, %cl
orb 0x1b(%rax), %dl
leaq 0x5c7c(%rip), %r10      # 0xd450
je 0x781c
decb %r13b
movzbl %r13b, %r13d
testb %cl, %cl
movl $0xff, %eax
cmovnel %eax, %r13d
jmp 0x77f8
movb $-0x1, %r13b
jmp 0x77f8
cmpb $-0x7b, %cl
je 0x78a3
movq %rbx, %rdi
xorl %esi, %esi
callq 0x7c47
testl %eax, %eax
jne 0x78b5
movq 0x38(%rbx), %rsi
testq %rsi, %rsi
jne 0x7734
jmp 0x78f6
movq 0x10(%r14), %rdx
movzbl (%rax), %esi
andl $-0x41, %esi
leal (%rsi,%rsi,2), %edi
leal (%rsi,%rdi,4), %esi
addl $-0xd, %esi
movw $0x1, %r8w
xorl %edi, %edi
movzbl (%rdi,%r10), %r9d
movzwl (%rax,%r9), %r9d
testw %r8w, %r8w
je 0x785d
cmpl $0xff, %esi
ja 0x77d6
movl %esi, %r8d
incl %esi
movw %r9w, (%rdx,%r8,2)
movl %r9d, %r8d
jmp 0x7868
cmpw $-0x1, %r9w
jne 0x77d6
incq %rdi
cmpq $0xd, %rdi
jne 0x7836
xorl %ecx, %ecx
testb $0x40, (%rax)
je 0x77d6
testw %r8w, %r8w
je 0x77d6
movb $0x1, %cl
cmpl $0xff, %esi
ja 0x77d6
movl %esi, %eax
movw $0x0, (%rdx,%rax,2)
xorl %ecx, %ecx
jmp 0x77d6
movl 0x30(%rbx), %eax
movl %eax, 0x54(%rbx)
movq %rbx, %rdi
callq 0xbc3b
testl %eax, %eax
je 0x78ea
movl %eax, %ebp
jmp 0x78f8
testb %r13b, %r13b
jne 0x78e1
xorl %ecx, %ecx
xorl %edx, %edx
movzbl %dl, %esi
movl %esi, %edx
shrl %edx
shll $0x7, %esi
orl %edx, %esi
movzbl (%rax,%rcx), %edx
addl %esi, %edx
incq %rcx
cmpl $0xb, %ecx
jne 0x78c2
cmpb %dl, %r12b
je 0x78f6
movl $0xffffffff, 0x54(%rbx) # imm = 0xFFFFFFFF
jmp 0x78f6
movq 0x18(%r14), %rax
movb 0x4(%rax), %al
andb $0x3f, %al
movb %al, 0xa(%rbx)
xorl %ebp, %ebp
testl %ebp, %ebp
je 0x7904
movq $0x0, 0x38(%rbx)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq