// File: /workspace/github_c_makefile_star2_O3/lb3361[P]dosfs/ff.c
// Function: load_xdir
static FRESULT load_xdir (	/* FR_INT_ERR: invalid entry block */
	DIR* dp					/* Reading direcotry object pointing top of the entry block to load */
)
{
	FRESULT res;
	UINT i, sz_ent;
	BYTE* dirb = dp->obj.fs->dirbuf;	/* Pointer to the on-memory direcotry entry block 85+C0+C1s */


	/* Load file-directory entry */
	res = move_window(dp->obj.fs, dp->sect);
	if (res != FR_OK) return res;
	if (dp->dir[XDIR_Type] != ET_FILEDIR) return FR_INT_ERR;	/* Invalid order */
	mem_cpy(dirb + 0 * SZDIRE, dp->dir, SZDIRE);
	sz_ent = (dirb[XDIR_NumSec] + 1) * SZDIRE;
	if (sz_ent < 3 * SZDIRE || sz_ent > 19 * SZDIRE) return FR_INT_ERR;

	/* Load stream-extension entry */
	res = dir_next(dp, 0);
	if (res == FR_NO_FILE) res = FR_INT_ERR;	/* It cannot be */
	if (res != FR_OK) return res;
	res = move_window(dp->obj.fs, dp->sect);
	if (res != FR_OK) return res;
	if (dp->dir[XDIR_Type] != ET_STREAM) return FR_INT_ERR;	/* Invalid order */
	mem_cpy(dirb + 1 * SZDIRE, dp->dir, SZDIRE);
	if (MAXDIRB(dirb[XDIR_NumName]) > sz_ent) return FR_INT_ERR;

	/* Load file-name entries */
	i = 2 * SZDIRE;	/* Name offset to load */
	do {
		res = dir_next(dp, 0);
		if (res == FR_NO_FILE) res = FR_INT_ERR;	/* It cannot be */
		if (res != FR_OK) return res;
		res = move_window(dp->obj.fs, dp->sect);
		if (res != FR_OK) return res;
		if (dp->dir[XDIR_Type] != ET_FILENAME) return FR_INT_ERR;	/* Invalid order */
		if (i < MAXDIRB(FF_MAX_LFN)) mem_cpy(dirb + i, dp->dir, SZDIRE);
	} while ((i += SZDIRE) < sz_ent);

	/* Sanity check (do it for only accessible object) */
	if (i <= MAXDIRB(FF_MAX_LFN)) {
		if (xdir_sum(dirb) != ld_word(dirb + XDIR_SetSum)) return FR_INT_ERR;
	}
	return FR_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq (%rdi), %rdi
movq 0x38(%rbx), %rsi
movq 0x18(%rdi), %r14
callq 0x6114
testl %eax, %eax
jne 0xb967
movq 0x40(%rbx), %rcx
movl $0x2, %eax
cmpb $-0x7b, (%rcx)
jne 0xb967
xorl %edx, %edx
movb (%rcx,%rdx), %sil
movb %sil, (%r14,%rdx)
incq %rdx
cmpl $0x20, %edx
jne 0xb8d9
movzbl 0x1(%r14), %r15d
leal -0x13(%r15), %ecx
cmpb $-0x11, %cl
jb 0xb967
movq %rbx, %rdi
xorl %esi, %esi
callq 0x7952
movl %eax, %ecx
cmpl $0x4, %eax
movl $0x2, %eax
cmovnel %ecx, %eax
testl %eax, %eax
jne 0xb967
movq (%rbx), %rdi
movq 0x38(%rbx), %rsi
callq 0x6114
testl %eax, %eax
jne 0xb967
movq 0x40(%rbx), %rcx
movl $0x2, %eax
cmpb $-0x40, (%rcx)
jne 0xb967
shll $0x5, %r15d
addq $0x20, %r15
xorl %edx, %edx
movb (%rcx,%rdx), %sil
movb %sil, 0x20(%r14,%rdx)
incq %rdx
cmpl $0x20, %edx
jne 0xb93a
movzbl 0x23(%r14), %ecx
imull $0x1112, %ecx, %ecx     # imm = 0x1112
addl $0x2ef18, %ecx          # imm = 0x2EF18
shrl $0xb, %ecx
andl $-0x20, %ecx
cmpl %ecx, %r15d
jae 0xb976
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x40(%r14), %r12
movl $0x40, %ecx
movl $0x2, %ebp
movq %rcx, %r13
movq %rbx, %rdi
xorl %esi, %esi
callq 0x7952
cmpl $0x4, %eax
cmovel %ebp, %eax
testl %eax, %eax
jne 0xb967
movq (%rbx), %rdi
movq 0x38(%rbx), %rsi
callq 0x6114
testl %eax, %eax
jne 0xb967
movq 0x40(%rbx), %rcx
movl $0x2, %eax
cmpb $-0x3f, (%rcx)
jne 0xb967
cmpq $0x25f, %r13            # imm = 0x25F
ja 0xb9d4
xorl %edx, %edx
movb (%rcx,%rdx), %sil
movb %sil, (%r12,%rdx)
incq %rdx
cmpl $0x20, %edx
jne 0xb9c4
leaq 0x20(%r13), %rcx
addq $0x20, %r12
cmpq %r15, %rcx
jb 0xb984
cmpq $0x240, %r13            # imm = 0x240
ja 0xba2a
movzbl 0x1(%r14), %ecx
shll $0x5, %ecx
addl $0x20, %ecx
xorl %edx, %edx
xorl %esi, %esi
movl $0x4, %edi
cmpl $0x2, %esi
jne 0xba07
movl %edi, %esi
jmp 0xba1b
rorw %dx
movl %esi, %edi
movzbl (%r14,%rdi), %r8d
addl %edx, %r8d
incl %esi
movl %esi, %edi
movl %r8d, %edx
cmpl %ecx, %edi
jb 0xb9f9
cmpw 0x2(%r14), %dx
jne 0xb967
xorl %eax, %eax
jmp 0xb967
nopl (%rax)