// File: /workspace/github_c_makefile_star2_O2/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, %r14
movq (%rdi), %rdi
movq 0x38(%r14), %rsi
movq 0x18(%rdi), %rbx
callq 0x5bf6
testl %eax, %eax
je 0xab5e
movl %eax, %ebp
jmp 0xab9e
movq 0x40(%r14), %rsi
pushq $0x2
popq %rbp
cmpb $-0x7b, (%rsi)
jne 0xab9e
pushq $0x20
popq %rdx
movq %rbx, %rdi
callq 0x60c7
movzbl 0x1(%rbx), %r12d
leal -0x13(%r12), %eax
cmpb $-0x11, %al
jb 0xab9e
movq %r14, %rdi
xorl %esi, %esi
callq 0x7336
movl %eax, %ebp
cmpl $0x4, %eax
pushq $0x2
popq %r15
cmovel %r15d, %ebp
testl %ebp, %ebp
je 0xabaf
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rdi
movq 0x38(%r14), %rsi
callq 0x5bf6
testl %eax, %eax
jne 0xab5a
movq 0x40(%r14), %rsi
cmpb $-0x40, (%rsi)
jne 0xac81
shll $0x5, %r12d
addq $0x20, %r12
leaq 0x20(%rbx), %rdi
pushq $0x20
popq %rdx
callq 0x60c7
movzbl 0x23(%rbx), %eax
addl $0x2c, %eax
movw $0xf, %cx
xorl %edx, %edx
divw %cx
shll $0x5, %eax
movzwl %ax, %eax
movl %r15d, %ebp
cmpl %eax, %r12d
jb 0xab9e
pushq $0x40
popq %r15
pushq $0x2
popq %r13
movq %r14, %rdi
xorl %esi, %esi
callq 0x7336
movl %eax, %ebp
cmpl $0x4, %eax
cmovel %r13d, %ebp
testl %ebp, %ebp
jne 0xab9e
movq (%r14), %rdi
movq 0x38(%r14), %rsi
callq 0x5bf6
testl %eax, %eax
jne 0xab5a
movq 0x40(%r14), %rsi
cmpb $-0x3f, (%rsi)
jne 0xac89
cmpq $0x25f, %r15            # imm = 0x25F
ja 0xac4f
leaq (%rbx,%r15), %rdi
pushq $0x20
popq %rdx
callq 0x60c7
addq $0x20, %r15
cmpq %r12, %r15
jb 0xac06
addq $-0x20, %r15
cmpq $0x240, %r15            # imm = 0x240
ja 0xac7a
movq %rbx, %rdi
callq 0xa891
movl %r13d, %ebp
cmpw 0x2(%rbx), %ax
jne 0xab9e
xorl %ebp, %ebp
jmp 0xab9e
movl %r15d, %ebp
jmp 0xab9e
movl %r13d, %ebp
jmp 0xab9e