// File: /workspace/github_c_makefile_star2_O3/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 0x4ada
testl %eax, %eax
setne %cl
testq %r14, %r14
sete %dl
orb %cl, %dl
jne 0x8c1a
movq 0x8(%rsp), %r15
leaq 0x18(%rsp), %rdi
movq %r15, (%rdi)
movl $0x0, 0xc(%rdi)
xorl %esi, %esi
callq 0x72ea
testl %eax, %eax
jne 0x8c65
leaq 0x18(%rsp), %rdi
movl $0x1, %esi
callq 0x74aa
cmpl $0x4, %eax
je 0x8c14
testl %eax, %eax
jne 0x8c65
cmpb $0x4, (%r15)
movq 0x58(%rsp), %r15
jne 0x8b9a
movb 0x1(%r15), %al
xorl %r12d, %r12d
testb %al, %al
je 0x8bfc
xorl %r13d, %r13d
xorl %ebp, %ebp
movzbl 0x2(%r15,%r13,2), %esi
movzbl 0x3(%r15,%r13,2), %edx
movl %edx, %ecx
shll $0x8, %ecx
orl %esi, %ecx
testw %bp, %bp
jne 0x8b60
andl $-0x8, %edx
movzwl %dx, %edx
cmpl $0xd8, %edx
je 0x8b8b
movl %ebp, %edi
shll $0x10, %edi
orl %ecx, %edi
movl %r12d, %esi
addq %r14, %rsi
movl $0x4, %edx
callq 0x8c74
testb %al, %al
je 0x8c00
movzbl %al, %eax
addl %eax, %r12d
movb 0x1(%r15), %al
xorl %ecx, %ecx
incq %r13
movzbl %al, %edx
movl %ecx, %ebp
cmpq %rdx, %r13
jb 0x8b3a
jmp 0x8c05
xorl %r12d, %r12d
xorl %ebp, %ebp
movzbl (%r15,%r12), %edi
movl $0x1b5, %esi            # imm = 0x1B5
callq 0xba7f
testw %ax, %ax
je 0x8bd9
movzwl %ax, %edi
movl %ebp, %esi
addq %r14, %rsi
movl $0x4, %edx
callq 0x8c74
testb %al, %al
je 0x8bd9
movzbl %al, %eax
addl %eax, %ebp
incq %r12
cmpq $0xb, %r12
jne 0x8b9f
jmp 0x8bdb
xorl %ebp, %ebp
movl %ebp, %ecx
decq %rcx
xorl %eax, %eax
movb $0x0, 0x1(%r14,%rcx)
cmpq $-0x1, %rcx
je 0x8c1a
movl %ecx, %edx
decq %rcx
cmpb $0x20, (%r14,%rdx)
je 0x8be2
jmp 0x8c1a
xorl %eax, %eax
jmp 0x8c11
xorl %r12d, %r12d
movl %ebp, %ecx
xorl %eax, %eax
testw %cx, %cx
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 0x8c65
movq 0x8(%rsp), %r14
movq 0x30(%r14), %rsi
movq %r14, %rdi
callq 0x6114
testl %eax, %eax
jne 0x8c65
movb (%r14), %al
cmpb $0x3, %al
movl $0x43, %ecx
movl $0x27, %edx
cmoveq %rcx, %rdx
cmpb $0x4, %al
movl $0x64, %eax
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