// File: /workspace/github_c_makefile_star2_O2/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, %ebp
movq %rdi, %rbx
movq (%rdi), %r14
movb $-0x1, %r12b
pushq $0x4
popq %r15
xorl %ecx, %ecx
movb $-0x1, %r13b
movq 0x38(%rbx), %rsi
testq %rsi, %rsi
je 0x7047
movq %r14, %rdi
callq 0x5bf6
testl %eax, %eax
jne 0x7069
movq 0x40(%rbx), %rdi
movzbl (%rdi), %eax
testl %eax, %eax
je 0x7051
cmpb $0x4, (%r14)
jne 0x6f48
testl %ebp, %ebp
je 0x6f83
cmpl $0x83, %eax
jne 0x6fae
jmp 0x704c
movb 0xb(%rdi), %dl
movl %edx, %ecx
andb $0x3f, %cl
movb %cl, 0xa(%rbx)
cmpl $0x2e, %eax
je 0x6fab
cmpl $0xe5, %eax
je 0x6fab
andb $0x1f, %dl
xorl %esi, %esi
cmpb $0x8, %dl
sete %sil
cmpl %ebp, %esi
jne 0x6fab
cmpb $0xf, %cl
jne 0x7083
testb $0x40, %al
jne 0x6f8f
cmpb %r12b, %al
je 0x6f9e
jmp 0x6fab
cmpl $0x85, %eax
jne 0x6fae
jmp 0x7057
movb 0xd(%rdi), %r13b
andb $-0x41, %al
movl 0x30(%rbx), %ecx
movl %ecx, 0x54(%rbx)
movl %eax, %r12d
cmpb 0xd(%rdi), %r13b
jne 0x6fab
cmpw $0x0, 0x1a(%rdi)
je 0x6fca
movb $-0x1, %r12b
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x7336
movb $0x1, %cl
testl %eax, %eax
je 0x6f06
jmp 0x7069
movq 0x10(%r14), %rax
movzbl (%rdi), %ecx
andl $-0x41, %ecx
imull $0xd, %ecx, %ecx
addl $-0xd, %ecx
movw $0x1, %r9w
xorl %edx, %edx
leaq 0x5478(%rip), %r10      # 0xc460
movl %ecx, %esi
cmpq $0xd, %rdx
je 0x7023
movzbl (%rdx,%r10), %r8d
movzwl (%rdi,%r8), %r8d
testw %r9w, %r9w
je 0x7011
cmpl $0xff, %ecx
ja 0x6fab
incl %ecx
movw %r8w, (%rax,%rsi,2)
jmp 0x701b
cmpw $-0x1, %r8w
jne 0x6fab
xorl %r8d, %r8d
incq %rdx
movl %r8d, %r9d
jmp 0x6fe8
testb $0x40, (%rdi)
je 0x703f
testw %r9w, %r9w
je 0x703f
cmpl $0xff, %ecx
ja 0x6fab
andw $0x0, (%rax,%rsi,2)
decb %r12b
jmp 0x6fae
testb $0x1, %cl
je 0x706c
xorl %r15d, %r15d
jmp 0x7071
pushq $0x4
popq %r15
jmp 0x706c
movl 0x30(%rbx), %eax
movl %eax, 0x54(%rbx)
movq %rbx, %rdi
callq 0xab38
testl %eax, %eax
je 0x7098
movl %eax, %r15d
andq $0x0, 0x38(%rbx)
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb %r12b, %r12b
jne 0x7092
callq 0xa87f
cmpb %al, %r13b
je 0x704c
orl $-0x1, 0x54(%rbx)
jmp 0x704c
movq 0x18(%r14), %rax
movb 0x4(%rax), %al
andb $0x3f, %al
movb %al, 0xa(%rbx)
jmp 0x704c