// File: /workspace/github_c_makefile_star2_O3/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
movq %rdi, %rbx
movq 0x38(%rdi), %r13
movl $0x4, %ebp
testq %r13, %r13
je 0x7641
movl %esi, %r15d
movq (%rbx), %r14
movb $-0x1, 0x7(%rsp)
movq %r13, %rsi
movb $-0x1, %r12b
movq %r14, %rdi
callq 0x6114
testl %eax, %eax
jne 0x763f
movq 0x40(%rbx), %rax
movzbl (%rax), %ecx
testl %ecx, %ecx
je 0x7641
cmpb $0x4, (%r14)
jne 0x7512
testl %r15d, %r15d
je 0x7553
cmpl $0x83, %ecx
jne 0x7586
jmp 0x768b
movb 0xb(%rax), %sil
movl %esi, %edx
andb $0x3f, %dl
movb %dl, 0xa(%rbx)
cmpl $0x2e, %ecx
je 0x7583
cmpl $0xe5, %ecx
je 0x7583
andb $0x1f, %sil
xorl %edi, %edi
cmpb $0x8, %sil
sete %dil
cmpl %r15d, %edi
jne 0x7583
cmpb $0xf, %dl
jne 0x765a
testb $0x40, %cl
jne 0x7560
cmpb %r12b, %cl
je 0x7573
jmp 0x7583
cmpl $0x85, %ecx
jne 0x7586
jmp 0x762d
movb 0xd(%rax), %dl
movb %dl, 0x7(%rsp)
andb $-0x41, %cl
movl 0x30(%rbx), %edx
movl %edx, 0x54(%rbx)
movl %ecx, %r12d
movb 0x7(%rsp), %cl
cmpb 0xd(%rax), %cl
jne 0x7583
cmpw $0x0, 0x1a(%rax)
je 0x75a7
movb $-0x1, %r12b
movq %rbx, %rdi
xorl %esi, %esi
callq 0x7952
testl %eax, %eax
jne 0x763f
movq 0x38(%rbx), %rsi
testq %rsi, %rsi
jne 0x74db
jmp 0x7624
movq 0x10(%r14), %rcx
movzbl (%rax), %edx
andl $-0x41, %edx
leal (%rdx,%rdx,2), %esi
leal (%rdx,%rsi,4), %edx
addl $-0xd, %edx
movw $0x1, %si
xorl %edi, %edi
leaq 0x5e69(%rip), %r9       # 0xd430
movl %esi, %r8d
movzbl (%rdi,%r9), %esi
movzwl (%rax,%rsi), %esi
testw %r8w, %r8w
je 0x75ed
cmpl $0xff, %edx
ja 0x7583
movl %edx, %r8d
incl %edx
movw %si, (%rcx,%r8,2)
jmp 0x75f5
cmpw $-0x1, %si
jne 0x7583
xorl %esi, %esi
incq %rdi
cmpq $0xd, %rdi
jne 0x75c7
testb $0x40, (%rax)
je 0x761c
testw %si, %si
je 0x761c
cmpl $0xff, %edx
ja 0x7583
movl %edx, %eax
movw $0x0, (%rcx,%rax,2)
decb %r12b
jmp 0x7586
xorl %ebp, %ebp
testq %r13, %r13
jne 0x7649
jmp 0x7641
movl 0x30(%rbx), %eax
movl %eax, 0x54(%rbx)
movq %rbx, %rdi
callq 0xb89f
testl %eax, %eax
je 0x767f
movl %eax, %ebp
movq $0x0, 0x38(%rbx)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb %r12b, %r12b
jne 0x7676
xorl %ecx, %ecx
xorl %edx, %edx
rorb %dl
addb (%rax,%rcx), %dl
incq %rcx
cmpl $0xb, %ecx
jne 0x7663
cmpb %dl, 0x7(%rsp)
je 0x768b
movl $0xffffffff, 0x54(%rbx) # imm = 0xFFFFFFFF
jmp 0x768b
movq 0x18(%r14), %rax
movb 0x4(%rax), %al
andb $0x3f, %al
movb %al, 0xa(%rbx)
xorl %ebp, %ebp
jmp 0x7649