// File: /workspace/github_c_makefile_star2_O3/lb3361[P]dosfs/ff.c
// Function: get_fileinfo
static void get_fileinfo (
	DIR* dp,			/* Pointer to the directory object */
	FILINFO* fno		/* Pointer to the file information to be filled */
)
{
	UINT si, di;
#if FF_USE_LFN
	BYTE lcf;
	WCHAR wc, hs;
	FATFS *fs = dp->obj.fs;
#else
	TCHAR c;
#endif


	fno->fname[0] = 0;			/* Invaidate file info */
	if (dp->sect == 0) return;	/* Exit if read pointer has reached end of directory */

#if FF_USE_LFN		/* LFN configuration */
#if FF_FS_EXFAT
	if (fs->fs_type == FS_EXFAT) {	/* On the exFAT volume */
		get_xfileinfo(fs->dirbuf, fno);
		return;
	} else
#endif
	{	/* On the FAT/FAT32 volume */
		if (dp->blk_ofs != 0xFFFFFFFF) {	/* Get LFN if available */
			si = di = hs = 0;
			while (fs->lfnbuf[si] != 0) {
				wc = fs->lfnbuf[si++];		/* Get an LFN character (UTF-16) */
				if (hs == 0 && IsSurrogate(wc)) {	/* Is it a surrogate? */
					hs = wc; continue;		/* Get low surrogate */
				}
				wc = put_utf((DWORD)hs << 16 | wc, &fno->fname[di], FF_LFN_BUF - di);	/* Store it in UTF-16 or UTF-8 encoding */
				if (wc == 0) { di = 0; break; }	/* Invalid char or buffer overflow? */
				di += wc;
				hs = 0;
			}
			if (hs != 0) di = 0;	/* Broken surrogate pair? */
			fno->fname[di] = 0;		/* Terminate the LFN (null string means LFN is invalid) */
		}
	}

	si = di = 0;
	while (si < 11) {		/* Get SFN from SFN entry */
		wc = dp->dir[si++];			/* Get a char */
		if (wc == ' ') continue;	/* Skip padding spaces */
		if (wc == RDDEM) wc = DDEM;	/* Restore replaced DDEM character */
		if (si == 9 && di < FF_SFN_BUF) fno->altname[di++] = '.';	/* Insert a . if extension is exist */
#if FF_LFN_UNICODE >= 1	/* Unicode output */
		if (dbc_1st((BYTE)wc) && si != 8 && si != 11 && dbc_2nd(dp->dir[si])) {	/* Make a DBC if needed */
			wc = wc << 8 | dp->dir[si++];
		}
		wc = ff_oem2uni(wc, CODEPAGE);		/* ANSI/OEM -> Unicode */
		if (wc == 0) { di = 0; break; }		/* Wrong char in the current code page? */
		wc = put_utf(wc, &fno->altname[di], FF_SFN_BUF - di);	/* Store it in Unicode */
		if (wc == 0) { di = 0; break; }		/* Buffer overflow? */
		di += wc;
#else					/* ANSI/OEM output */
		fno->altname[di++] = (TCHAR)wc;	/* Store it without any conversion */
#endif
	}
	fno->altname[di] = 0;	/* Terminate the SFN  (null string means SFN is invalid) */

	if (fno->fname[0] == 0) {	/* If LFN is invalid, altname[] needs to be copied to fname[] */
		if (di == 0) {	/* If LFN and SFN both are invalid, this object is inaccesible */
			fno->fname[di++] = '?';
		} else {
			for (si = di = 0, lcf = NS_BODY; fno->altname[si]; si++, di++) {	/* Copy altname[] to fname[] with case information */
				wc = (WCHAR)fno->altname[si];
				if (wc == '.') lcf = NS_EXT;
				if (IsUpper(wc) && (dp->dir[DIR_NTres] & lcf)) wc += 0x20;
				fno->fname[di] = (TCHAR)wc;
			}
		}
		fno->fname[di] = 0;	/* Terminate the LFN */
		if (!dp->dir[DIR_NTres]) fno->altname[0] = 0;	/* Altname is not needed if neither LFN nor case info is exist. */
	}

#else	/* Non-LFN configuration */
	si = di = 0;
	while (si < 11) {		/* Copy name body and extension */
		c = (TCHAR)dp->dir[si++];
		if (c == ' ') continue;		/* Skip padding spaces */
		if (c == RDDEM) c = DDEM;	/* Restore replaced DDEM character */
		if (si == 9) fno->fname[di++] = '.';/* Insert a . if extension is exist */
		fno->fname[di++] = c;
	}
	fno->fname[di] = 0;
#endif

	fno->fattrib = dp->dir[DIR_Attr];					/* Attribute */
	fno->fsize = ld_dword(dp->dir + DIR_FileSize);		/* Size */
	fno->ftime = ld_word(dp->dir + DIR_ModTime + 0);	/* Time */
	fno->fdate = ld_word(dp->dir + DIR_ModTime + 2);	/* Date */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq (%rdi), %r12
movb $0x0, 0x1a(%rsi)
cmpq $0x0, 0x38(%rdi)
je 0x7943
movq %rsi, %rbx
leaq 0x1a(%rsi), %r15
cmpb $0x4, (%r12)
jne 0x775c
movq 0x18(%r12), %r14
movl $0x40, %r13d
xorl %ebp, %ebp
xorl %r12d, %r12d
movzbl 0x23(%r14), %eax
cmpl %eax, %r12d
cmoval %r12d, %eax
incl %eax
xorl %ecx, %ecx
movl %ecx, %edi
incl %r12d
cmpl %r12d, %eax
je 0x78bf
cmpl $0x25f, %r13d           # imm = 0x25F
ja 0x78c8
movl %r13d, %esi
orl $0x2, %esi
testb $0x1f, %r13b
cmovnel %r13d, %esi
movzbl (%r14,%rsi), %r8d
movzbl 0x1(%r14,%rsi), %edx
movl %edx, %ecx
shll $0x8, %ecx
orl %r8d, %ecx
movl %esi, %r13d
addl $0x2, %r13d
testw %di, %di
jne 0x7734
andl $-0x8, %edx
movzwl %dx, %edx
cmpl $0xd8, %edx
je 0x76de
shll $0x10, %edi
orl %ecx, %edi
movl %ebp, %esi
addq %r15, %rsi
movl $0xff, %edx
subl %ebp, %edx
callq 0x8c74
movzbl %al, %eax
addl %eax, %ebp
testb %al, %al
jne 0x76ce
jmp 0x78c8
movq %rdi, %r14
cmpl $-0x1, 0x54(%rdi)
movq %rbx, (%rsp)
je 0x77d7
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x10(%r12), %rcx
xorl %eax, %eax
movl %eax, %r13d
movl %ebx, %eax
movzwl (%rcx,%rax,2), %eax
testl %eax, %eax
je 0x77c2
incl %ebx
testw %r13w, %r13w
jne 0x779c
movl %eax, %edx
andl $0xf800, %edx           # imm = 0xF800
movzwl %dx, %edx
cmpl $0xd800, %edx           # imm = 0xD800
je 0x7774
movl %r13d, %edi
shll $0x10, %edi
orl %eax, %edi
movl %ebp, %esi
addq %r15, %rsi
movl $0xff, %edx
subl %ebp, %edx
callq 0x8c74
movzbl %al, %eax
addl %eax, %ebp
testb %al, %al
jne 0x776d
xorl %ecx, %ecx
jmp 0x77c4
movl %ebp, %ecx
xorl %eax, %eax
testw %r13w, %r13w
cmoveq %rcx, %rax
movb $0x0, (%r15,%rax)
movq (%rsp), %rbx
leaq 0xd(%rbx), %r12
xorl %ebp, %ebp
movl $0xb, %ecx
movl $0xe5, %edx
xorl %eax, %eax
xorl %ebx, %ebx
movl %eax, %r13d
cmpl $0xc, %eax
cmovbl %ecx, %eax
cmpq %r13, %rax
je 0x7867
movq 0x40(%r14), %rcx
movb (%rcx,%r13), %cl
incq %r13
cmpb $0x20, %cl
je 0x77f4
cmpb $0x5, %cl
movzbl %cl, %eax
cmovel %edx, %eax
cmpq $0x9, %r13
jne 0x7826
cmpl $0xb, %ebp
ja 0x7826
movl %ebp, %ecx
incl %ebp
movb $0x2e, (%r12,%rcx)
movzbl %al, %eax
movzwl %ax, %edi
movl $0x1b5, %esi            # imm = 0x1B5
callq 0xba7f
testw %ax, %ax
je 0x7869
movzwl %ax, %edi
movl %ebp, %esi
addq %r12, %rsi
movl $0xc, %edx
subl %ebp, %edx
callq 0x8c74
movzbl %al, %ecx
addl %ecx, %ebp
movl %r13d, %eax
testb %cl, %cl
movl $0xb, %ecx
movl $0xe5, %edx
jne 0x77eb
jmp 0x7869
movl %ebp, %ebx
movl %ebx, %eax
movb $0x0, (%r12,%rax)
cmpb $0x0, (%r15)
movq (%rsp), %rbx
jne 0x791c
testq %rax, %rax
je 0x78fe
movb $0x8, %al
xorl %ecx, %ecx
movl %ecx, %ecx
movzbl (%r12,%rcx), %edx
cmpl $0x2e, %edx
je 0x78b5
testl %edx, %edx
je 0x7908
leal -0x41(%rdx), %esi
cmpb $0x19, %sil
ja 0x78b7
movq 0x40(%r14), %rsi
movzbl %dl, %edi
orb $0x20, %dl
testb %al, 0xc(%rsi)
movzbl %dl, %edx
cmovel %edi, %edx
jmp 0x78b7
movb $0x10, %al
movb %dl, (%r15,%rcx)
incl %ecx
jmp 0x7887
testw %di, %di
jne 0x78c8
testl %ebp, %ebp
jne 0x78d1
movb $0x3f, (%r15)
movl $0x1, %ebp
movl %ebp, %ecx
xorl %eax, %eax
movb %al, 0x1a(%rbx,%rcx)
movb %al, 0xd(%rbx)
movb 0x4(%r14), %cl
movb %cl, 0xc(%rbx)
testb $0x10, %cl
jne 0x78ec
movq 0x38(%r14), %rax
movq %rax, (%rbx)
movzwl 0xc(%r14), %eax
movw %ax, 0xa(%rbx)
addq $0xe, %r14
jmp 0x793b
movb $0x3f, (%r15,%rax)
movl $0x1, %ecx
movb $0x0, (%r15,%rcx)
movq 0x40(%r14), %rax
cmpb $0x0, 0xc(%rax)
jne 0x791c
movb $0x0, (%r12)
movq 0x40(%r14), %r14
movb 0xb(%r14), %al
movb %al, 0xc(%rbx)
movl 0x1c(%r14), %eax
movq %rax, (%rbx)
movzwl 0x16(%r14), %eax
movw %ax, 0xa(%rbx)
addq $0x18, %r14
movzwl (%r14), %eax
movw %ax, 0x8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq