// File: /workspace/github_c_makefile_star2_O2/lb3361[P]dosfs/ff.c
// Function: f_getlabel
FRESULT f_getlabel (
	const TCHAR* path,	/* Logical drive number */
	TCHAR* label,		/* Buffer to store the volume label */
	DWORD* vsn			/* Variable to store the volume serial number */
)
{
	FRESULT res;
	DIR dj;
	FATFS *fs;
	UINT si, di;
	WCHAR wc;

	/* Get logical drive */
	res = mount_volume(&path, &fs, 0);

	/* Get volume label */
	if (res == FR_OK && label) {
		dj.obj.fs = fs; dj.obj.sclust = 0;	/* Open root directory */
		res = dir_sdi(&dj, 0);
		if (res == FR_OK) {
		 	res = DIR_READ_LABEL(&dj);		/* Find a volume label entry */
		 	if (res == FR_OK) {
#if FF_FS_EXFAT
				if (fs->fs_type == FS_EXFAT) {
					WCHAR hs;

					for (si = di = hs = 0; si < dj.dir[XDIR_NumLabel]; si++) {	/* Extract volume label from 83 entry */
						wc = ld_word(dj.dir + XDIR_Label + si * 2);
						if (hs == 0 && IsSurrogate(wc)) {	/* Is the code a surrogate? */
							hs = wc; continue;
						}
						wc = put_utf((DWORD)hs << 16 | wc, &label[di], 4);
						if (wc == 0) { di = 0; break; }
						di += wc;
						hs = 0;
					}
					if (hs != 0) di = 0;	/* Broken surrogate pair? */
					label[di] = 0;
				} else
#endif
				{
					si = di = 0;		/* Extract volume label from AM_VOL entry */
					while (si < 11) {
						wc = dj.dir[si++];
#if FF_USE_LFN && FF_LFN_UNICODE >= 1 	/* Unicode output */
						if (dbc_1st((BYTE)wc) && si < 11) wc = wc << 8 | dj.dir[si++];	/* Is it a DBC? */
						wc = ff_oem2uni(wc, CODEPAGE);					/* Convert it into Unicode */
						if (wc != 0) wc = put_utf(wc, &label[di], 4);	/* Put it in Unicode */
						if (wc == 0) { di = 0; break; }
						di += wc;
#else									/* ANSI/OEM output */
						label[di++] = (TCHAR)wc;
#endif
					}
					do {				/* Truncate trailing spaces */
						label[di] = 0;
						if (di == 0) break;
					} while (label[--di] == ' ');
				}
			}
		}
		if (res == FR_NO_FILE) {	/* No label entry and return nul string */
			label[0] = 0;
			res = FR_OK;
		}
	}

	/* Get volume serial number */
	if (res == FR_OK && vsn) {
		res = move_window(fs, fs->volbase);
		if (res == FR_OK) {
			switch (fs->fs_type) {
			case FS_EXFAT:
				di = BPB_VolIDEx;
				break;

			case FS_FAT32:
				di = BS_VolID32;
				break;

			default:
				di = BS_VolID;
			}
			*vsn = ld_dword(fs->win + di);
		}
	}

	LEAVE_FF(fs, res);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, %rbx
movq %rsi, %r14
leaq 0x10(%rsp), %rax
movq %rdi, (%rax)
leaq 0x8(%rsp), %rsi
movq %rax, %rdi
xorl %edx, %edx
callq 0x473a
testl %eax, %eax
setne %cl
testq %r14, %r14
sete %dl
orb %cl, %dl
jne 0x8384
movq 0x8(%rsp), %r15
leaq 0x18(%rsp), %rdi
movq %r15, (%rdi)
andl $0x0, 0xc(%rdi)
xorl %esi, %esi
callq 0x6d3b
testl %eax, %eax
jne 0x83c9
leaq 0x18(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x6ee7
cmpl $0x4, %eax
je 0x837e
testl %eax, %eax
jne 0x83c9
cmpb $0x4, (%r15)
movq 0x58(%rsp), %r15
jne 0x8306
xorl %r13d, %r13d
xorl %r12d, %r12d
xorl %ebp, %ebp
movzbl 0x1(%r15), %eax
cmpq %rax, %r13
jae 0x836f
movzwl 0x2(%r15,%r13,2), %eax
movl %eax, %ecx
andl $0xfffff800, %ecx       # imm = 0xFFFFF800
xorl $0xd800, %ecx           # imm = 0xD800
orw %bp, %cx
je 0x82ff
movzwl %ax, %eax
movl %ebp, %edi
shll $0x10, %edi
orl %eax, %edi
movl %r12d, %esi
addq %r14, %rsi
pushq $0x4
popq %rdx
callq 0x83d8
testb %al, %al
je 0x836c
movzbl %al, %eax
addl %eax, %r12d
xorl %eax, %eax
incq %r13
movl %eax, %ebp
jmp 0x82b4
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %ebp, %ebp
cmpq $0xb, %r12
je 0x8348
movzbl (%r15,%r12), %edi
movl $0x1b5, %esi            # imm = 0x1B5
callq 0xad4d
testw %ax, %ax
je 0x834b
incq %r12
movzwl %ax, %edi
movl %r13d, %esi
addq %r14, %rsi
pushq $0x4
popq %rdx
callq 0x83d8
movzbl %al, %eax
addl %eax, %r13d
testb %al, %al
jne 0x830e
jmp 0x834b
movl %r13d, %ebp
movl %ebp, %ecx
decq %rcx
xorl %eax, %eax
movb $0x0, 0x1(%r14,%rcx)
cmpq $-0x1, %rcx
je 0x8384
movl %ecx, %edx
decq %rcx
cmpb $0x20, (%r14,%rdx)
je 0x8352
jmp 0x8384
xorl %r12d, %r12d
xorl %eax, %eax
testw %bp, %bp
movl %r12d, %ecx
cmoveq %rcx, %rax
addq %rax, %r14
movb $0x0, (%r14)
xorl %eax, %eax
testl %eax, %eax
setne %cl
testq %rbx, %rbx
sete %dl
orb %cl, %dl
jne 0x83c9
movq 0x8(%rsp), %r14
movq 0x30(%r14), %rsi
movq %r14, %rdi
callq 0x5bf6
testl %eax, %eax
jne 0x83c9
movb (%r14), %al
cmpb $0x3, %al
pushq $0x43
popq %rcx
pushq $0x27
popq %rdx
cmoveq %rcx, %rdx
cmpb $0x4, %al
pushq $0x64
popq %rax
cmovneq %rdx, %rax
movl 0x60(%r14,%rax), %eax
movl %eax, (%rbx)
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq