// File: /workspace/github_c_makefile_star2_O1/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 0x4c82
testl %eax, %eax
setne %cl
testq %r14, %r14
sete %dl
orb %cl, %dl
jne 0x8eed
movq 0x8(%rsp), %r15
leaq 0x18(%rsp), %rdi
movq %r15, (%rdi)
movl $0x0, 0xc(%rdi)
xorl %esi, %esi
callq 0x7545
testl %eax, %eax
jne 0x8ee2
leaq 0x18(%rsp), %rdi
movl $0x1, %esi
callq 0x7708
testl %eax, %eax
jne 0x8ee2
cmpb $0x4, (%r15)
movq 0x58(%rsp), %r15
jne 0x8e60
xorl %r12d, %r12d
cmpb $0x0, 0x1(%r15)
je 0x8ec6
xorl %r13d, %r13d
xorl %ebp, %ebp
movzbl 0x3(%r15,%r13,2), %ecx
movl %ecx, %edx
shll $0x8, %edx
movzbl 0x2(%r15,%r13,2), %eax
orl %edx, %eax
testw %bp, %bp
jne 0x8e28
andl $-0x8, %ecx
movzwl %cx, %ecx
cmpl $0xd8, %ecx
je 0x8e4f
movl %ebp, %edi
shll $0x10, %edi
orl %eax, %edi
movl %r12d, %esi
addq %r14, %rsi
movl $0x4, %edx
callq 0x8f47
testb %al, %al
je 0x8eca
movzbl %al, %eax
addl %eax, %r12d
xorl %eax, %eax
incq %r13
movzbl 0x1(%r15), %ecx
movl %eax, %ebp
cmpq %rcx, %r13
jb 0x8e02
jmp 0x8ecf
xorl %r12d, %r12d
xorl %ebp, %ebp
movzbl (%r15,%r12), %edi
movl $0x1b5, %esi            # imm = 0x1B5
callq 0xbe1b
testw %ax, %ax
je 0x8e8e
movzwl %ax, %edi
movl %ebp, %esi
addq %r14, %rsi
movl $0x4, %edx
callq 0x8f47
movzbl %al, %eax
testw %ax, %ax
je 0x8ea3
incq %r12
movzwl %ax, %eax
addl %eax, %ebp
cmpq $0xb, %r12
jne 0x8e65
jmp 0x8ea5
xorl %ebp, %ebp
movl %ebp, %ecx
decq %rcx
xorl %eax, %eax
movb $0x0, 0x1(%r14,%rcx)
cmpq $-0x1, %rcx
je 0x8ee2
movl %ecx, %edx
decq %rcx
cmpb $0x20, (%r14,%rdx)
je 0x8eac
jmp 0x8ee2
xorl %ecx, %ecx
jmp 0x8edb
xorl %r12d, %r12d
movl %ebp, %eax
xorl %ecx, %ecx
testw %ax, %ax
movl %r12d, %eax
cmoveq %rax, %rcx
movb $0x0, (%r14,%rcx)
xorl %eax, %eax
cmpl $0x4, %eax
jne 0x8eed
movb $0x0, (%r14)
xorl %eax, %eax
testl %eax, %eax
setne %cl
testq %rbx, %rbx
sete %dl
orb %cl, %dl
jne 0x8f38
movq 0x8(%rsp), %r14
movq 0x30(%r14), %rsi
movq %r14, %rdi
callq 0x6314
testl %eax, %eax
jne 0x8f38
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