// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl $0x4, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movb $-0x1, -0x1b(%rbp)
movb $-0x1, -0x1c(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x877f
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rsi
callq 0x6480
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
je 0x85a7
jmp 0x877f
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movb (%rax), %al
movb %al, -0x1a(%rbp)
movzbl -0x1a(%rbp), %eax
cmpl $0x0, %eax
jne 0x85c9
movl $0x4, -0x10(%rbp)
jmp 0x877f
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x4, %eax
jne 0x863c
cmpl $0x0, -0xc(%rbp)
je 0x85ed
movzbl -0x1a(%rbp), %eax
cmpl $0x83, %eax
jne 0x85eb
jmp 0x877f
jmp 0x8637
movzbl -0x1a(%rbp), %eax
cmpl $0x85, %eax
jne 0x8635
movq -0x8(%rbp), %rax
movl 0x30(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x54(%rax)
movq -0x8(%rbp), %rdi
callq 0xf760
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jne 0x8630
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movzbl 0x4(%rax), %eax
andl $0x3f, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0xa(%rax)
jmp 0x877f
jmp 0x8637
jmp 0x8764
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movzbl 0xb(%rax), %eax
andl $0x3f, %eax
movb %al, %cl
movb %cl, -0x19(%rbp)
movq -0x8(%rbp), %rax
movb %cl, 0xa(%rax)
movzbl -0x1a(%rbp), %eax
cmpl $0xe5, %eax
je 0x8682
movzbl -0x1a(%rbp), %eax
cmpl $0x2e, %eax
je 0x8682
movzbl -0x19(%rbp), %eax
andl $-0x21, %eax
cmpl $0x8, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
cmpl -0xc(%rbp), %eax
je 0x868b
movb $-0x1, -0x1b(%rbp)
jmp 0x8762
movzbl -0x19(%rbp), %eax
cmpl $0xf, %eax
jne 0x872a
movzbl -0x1a(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x86d2
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movb 0xd(%rax), %al
movb %al, -0x1c(%rbp)
movzbl -0x1a(%rbp), %eax
andl $0xbf, %eax
movb %al, -0x1a(%rbp)
movb -0x1a(%rbp), %al
movb %al, -0x1b(%rbp)
movq -0x8(%rbp), %rax
movl 0x30(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x54(%rax)
movzbl -0x1a(%rbp), %eax
movzbl -0x1b(%rbp), %ecx
cmpl %ecx, %eax
jne 0x8718
movzbl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x40(%rcx), %rcx
movzbl 0xd(%rcx), %ecx
cmpl %ecx, %eax
jne 0x8718
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rsi
callq 0xf9c0
cmpl $0x0, %eax
je 0x8718
movzbl -0x1b(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x8722
movl $0xff, %eax
movl %eax, -0x20(%rbp)
jmp 0x8722
movl -0x20(%rbp), %eax
movb %al, -0x1b(%rbp)
jmp 0x8760
movzbl -0x1b(%rbp), %eax
cmpl $0x0, %eax
jne 0x8753
movzbl -0x1c(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0xecd0
movb %al, %cl
movl -0x24(%rbp), %eax
movzbl %cl, %ecx
cmpl %ecx, %eax
je 0x875e
movq -0x8(%rbp), %rax
movl $0xffffffff, 0x54(%rax) # imm = 0xFFFFFFFF
jmp 0x877f
jmp 0x8762
jmp 0x8764
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x8b90
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
je 0x877a
jmp 0x877f
jmp 0x8579
cmpl $0x0, -0x10(%rbp)
je 0x8791
movq -0x8(%rbp), %rax
movq $0x0, 0x38(%rax)
movl -0x10(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)