// File: /workspace/github_c_makefile_star2_O0/lb3361[P]dosfs/ff.c
// Function: dir_find
static FRESULT dir_find (	/* FR_OK(0):succeeded, !=0:error */
	DIR* dp					/* Pointer to the directory object with the file name */
)
{
	FRESULT res;
	FATFS *fs = dp->obj.fs;
	BYTE c;
#if FF_USE_LFN
	BYTE a, ord, sum;
#endif

	res = dir_sdi(dp, 0);			/* Rewind directory object */
	if (res != FR_OK) return res;
#if FF_FS_EXFAT
	if (fs->fs_type == FS_EXFAT) {	/* On the exFAT volume */
		BYTE nc;
		UINT di, ni;
		WORD hash = xname_sum(fs->lfnbuf);		/* Hash value of the name to find */

		while ((res = DIR_READ_FILE(dp)) == FR_OK) {	/* Read an item */
#if FF_MAX_LFN < 255
			if (fs->dirbuf[XDIR_NumName] > FF_MAX_LFN) continue;			/* Skip comparison if inaccessible object name */
#endif
			if (ld_word(fs->dirbuf + XDIR_NameHash) != hash) continue;	/* Skip comparison if hash mismatched */
			for (nc = fs->dirbuf[XDIR_NumName], di = SZDIRE * 2, ni = 0; nc; nc--, di += 2, ni++) {	/* Compare the name */
				if ((di % SZDIRE) == 0) di += 2;
				if (ff_wtoupper(ld_word(fs->dirbuf + di)) != ff_wtoupper(fs->lfnbuf[ni])) break;
			}
			if (nc == 0 && !fs->lfnbuf[ni]) break;	/* Name matched? */
		}
		return res;
	}
#endif
	/* On the FAT/FAT32 volume */
#if FF_USE_LFN
	ord = sum = 0xFF; dp->blk_ofs = 0xFFFFFFFF;	/* Reset LFN sequence */
#endif
	do {
		res = move_window(fs, dp->sect);
		if (res != FR_OK) break;
		c = dp->dir[DIR_Name];
		if (c == 0) { res = FR_NO_FILE; break; }	/* Reached to end of table */
#if FF_USE_LFN		/* LFN configuration */
		dp->obj.attr = a = dp->dir[DIR_Attr] & AM_MASK;
		if (c == DDEM || ((a & AM_VOL) && a != AM_LFN)) {	/* An entry without valid data */
			ord = 0xFF; dp->blk_ofs = 0xFFFFFFFF;	/* Reset LFN sequence */
		} else {
			if (a == AM_LFN) {			/* An LFN entry is found */
				if (!(dp->fn[NSFLAG] & NS_NOLFN)) {
					if (c & LLEF) {		/* Is it start of LFN sequence? */
						sum = dp->dir[LDIR_Chksum];
						c &= (BYTE)~LLEF; ord = c;	/* LFN start order */
						dp->blk_ofs = dp->dptr;	/* Start offset of LFN */
					}
					/* Check validity of the LFN entry and compare it with given name */
					ord = (c == ord && sum == dp->dir[LDIR_Chksum] && cmp_lfn(fs->lfnbuf, dp->dir)) ? ord - 1 : 0xFF;
				}
			} else {					/* An SFN entry is found */
				if (ord == 0 && sum == sum_sfn(dp->dir)) break;	/* LFN matched? */
				if (!(dp->fn[NSFLAG] & NS_LOSS) && !mem_cmp(dp->dir, dp->fn, 11)) break;	/* SFN matched? */
				ord = 0xFF; dp->blk_ofs = 0xFFFFFFFF;	/* Reset LFN sequence */
			}
		}
#else		/* Non LFN configuration */
		dp->obj.attr = dp->dir[DIR_Attr] & AM_MASK;
		if (!(dp->dir[DIR_Attr] & AM_VOL) && !mem_cmp(dp->dir, dp->fn, 11)) break;	/* Is it a valid entry? */
#endif
		res = dir_next(dp, 0);	/* Next entry */
	} while (res == FR_OK);

	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x82b0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0xe7d6
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xeacb
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x4, %eax
jne 0xe8ea
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0xeae0
movw %ax, -0x32(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x8550
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
jne 0xe8df
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
addq $0x24, %rdi
callq 0x9390
movzwl %ax, %eax
movzwl -0x32(%rbp), %ecx
cmpl %ecx, %eax
je 0xe82c
jmp 0xe7f7
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movb 0x23(%rax), %al
movb %al, -0x25(%rbp)
movl $0x40, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
cmpb $0x0, -0x25(%rbp)
je 0xe8bd
movl -0x2c(%rbp), %eax
andl $0x1f, %eax
cmpl $0x0, %eax
jne 0xe862
movl -0x2c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x2c(%rbp), %eax
addq %rax, %rdi
callq 0x9390
movzwl %ax, %edi
callq 0xff60
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x30(%rbp), %ecx
movzwl (%rax,%rcx,2), %edi
callq 0xff60
movl %eax, %ecx
movl -0x38(%rbp), %eax
cmpl %ecx, %eax
je 0xe89f
jmp 0xe8bd
jmp 0xe8a1
movb -0x25(%rbp), %al
addb $-0x1, %al
movb %al, -0x25(%rbp)
movl -0x2c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x2c(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xe848
movzbl -0x25(%rbp), %eax
cmpl $0x0, %eax
jne 0xe8da
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x30(%rbp), %ecx
cmpw $0x0, (%rax,%rcx,2)
jne 0xe8da
jmp 0xe8df
jmp 0xe7f7
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xeacb
movb $-0x1, -0x24(%rbp)
movb $-0x1, -0x23(%rbp)
movq -0x10(%rbp), %rax
movl $0xffffffff, 0x54(%rax) # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
callq 0x6480
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0xe91c
jmp 0xeac5
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movb (%rax), %al
movb %al, -0x21(%rbp)
movzbl -0x21(%rbp), %eax
cmpl $0x0, %eax
jne 0xe93e
movl $0x4, -0x14(%rbp)
jmp 0xeac5
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movzbl 0xb(%rax), %eax
andl $0x3f, %eax
movb %al, %cl
movb %cl, -0x22(%rbp)
movq -0x10(%rbp), %rax
movb %cl, 0xa(%rax)
movzbl -0x21(%rbp), %eax
cmpl $0xe5, %eax
je 0xe979
movzbl -0x22(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0xe98d
movzbl -0x22(%rbp), %eax
cmpl $0xf, %eax
je 0xe98d
movb $-0x1, -0x23(%rbp)
movq -0x10(%rbp), %rax
movl $0xffffffff, 0x54(%rax) # imm = 0xFFFFFFFF
jmp 0xeaad
movzbl -0x22(%rbp), %eax
cmpl $0xf, %eax
jne 0xea40
movq -0x10(%rbp), %rax
movzbl 0x53(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
jne 0xea3e
movzbl -0x21(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0xe9e8
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movb 0xd(%rax), %al
movb %al, -0x24(%rbp)
movzbl -0x21(%rbp), %eax
andl $0xbf, %eax
movb %al, -0x21(%rbp)
movb -0x21(%rbp), %al
movb %al, -0x23(%rbp)
movq -0x10(%rbp), %rax
movl 0x30(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x54(%rax)
movzbl -0x21(%rbp), %eax
movzbl -0x23(%rbp), %ecx
cmpl %ecx, %eax
jne 0xea2e
movzbl -0x24(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x40(%rcx), %rcx
movzbl 0xd(%rcx), %ecx
cmpl %ecx, %eax
jne 0xea2e
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rsi
callq 0xeb90
cmpl $0x0, %eax
je 0xea2e
movzbl -0x23(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xea38
movl $0xff, %eax
movl %eax, -0x3c(%rbp)
jmp 0xea38
movl -0x3c(%rbp), %eax
movb %al, -0x23(%rbp)
jmp 0xeaab
movzbl -0x23(%rbp), %eax
cmpl $0x0, %eax
jne 0xea6b
movzbl -0x24(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0xecd0
movb %al, %cl
movl -0x40(%rbp), %eax
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0xea6b
jmp 0xeac5
movq -0x10(%rbp), %rax
movzbl 0x53(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xea9c
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x48, %rsi
movl $0xb, %edx
callq 0xd440
cmpl $0x0, %eax
jne 0xea9c
jmp 0xeac5
movb $-0x1, -0x23(%rbp)
movq -0x10(%rbp), %rax
movl $0xffffffff, 0x54(%rax) # imm = 0xFFFFFFFF
jmp 0xeaad
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x8b90
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0xe8fd
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)