// File: /workspace/github_c_makefile_star2_O0/gadget114514[P]fatfs-example/fatfs/source/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 a, c;
#if FF_USE_LFN
	BYTE ord = 0xFF, sum = 0xFF;
#endif

	while (dp->sect) {
		res = move_window(fs, dp->sect);
		if (res != FR_OK) break;
		c = dp->dir[DIR_Name];	/* Test for the entry type */
		if (c == 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 (c == 0x83) break;	/* Volume label entry? */
			} else {
				if (c == 0x85) {		/* 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 = a = dp->dir[DIR_Attr] & AM_MASK;	/* Get attribute */
#if FF_USE_LFN		/* LFN configuration */
			if (c == DDEM || c == '.' || (int)((a & ~AM_ARC) == AM_VOL) != vol) {	/* An entry without valid data */
				ord = 0xFF;
			} else {
				if (a == AM_LFN) {			/* An LFN entry is found */
					if (c & LLEF) {			/* Is it start of an LFN sequence? */
						sum = dp->dir[LDIR_Chksum];
						c &= (BYTE)~LLEF; ord = c;
						dp->blk_ofs = dp->dptr;
					}
					/* Check LFN validity and capture it */
					ord = (c == 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 (c != DDEM && c != '.' && a != AM_LFN && (int)((a & ~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 $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl $0x4, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x437a
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rsi
callq 0x28b0
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
je 0x42ef
jmp 0x437a
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movb (%rax), %al
movb %al, -0x1a(%rbp)
movzbl -0x1a(%rbp), %eax
cmpl $0x0, %eax
jne 0x430e
movl $0x4, -0x10(%rbp)
jmp 0x437a
movq -0x8(%rbp), %rax
movq 0x38(%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 0x435f
movzbl -0x1a(%rbp), %eax
cmpl $0x2e, %eax
je 0x435f
movzbl -0x19(%rbp), %eax
cmpl $0xf, %eax
je 0x435f
movzbl -0x19(%rbp), %eax
andl $-0x21, %eax
cmpl $0x8, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
cmpl -0xc(%rbp), %eax
jne 0x435f
jmp 0x437a
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x44c0
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
je 0x4375
jmp 0x437a
jmp 0x42c1
cmpl $0x0, -0x10(%rbp)
je 0x438c
movq -0x8(%rbp), %rax
movq $0x0, 0x30(%rax)
movl -0x10(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)