// File: /workspace/github_c_makefile_star2_O1/lb3361[P]dosfs/ff.c
// Function: dir_register
static FRESULT dir_register (	/* FR_OK:succeeded, FR_DENIED:no free entry or too many SFN collision, FR_DISK_ERR:disk error */
	DIR* dp						/* Target directory with object name to be created */
)
{
	FRESULT res;
	FATFS *fs = dp->obj.fs;
#if FF_USE_LFN		/* LFN configuration */
	UINT n, len, n_ent;
	BYTE sn[12], sum;


	if (dp->fn[NSFLAG] & (NS_DOT | NS_NONAME)) return FR_INVALID_NAME;	/* Check name validity */
	for (len = 0; fs->lfnbuf[len]; len++) ;	/* Get lfn length */

#if FF_FS_EXFAT
	if (fs->fs_type == FS_EXFAT) {	/* On the exFAT volume */
		n_ent = (len + 14) / 15 + 2;	/* Number of entries to allocate (85+C0+C1s) */
		res = dir_alloc(dp, n_ent);		/* Allocate directory entries */
		if (res != FR_OK) return res;
		dp->blk_ofs = dp->dptr - SZDIRE * (n_ent - 1);	/* Set the allocated entry block offset */

		if (dp->obj.stat & 4) {			/* Has the directory been stretched by new allocation? */
			dp->obj.stat &= ~4;
			res = fill_first_frag(&dp->obj);	/* Fill the first fragment on the FAT if needed */
			if (res != FR_OK) return res;
			res = fill_last_frag(&dp->obj, dp->clust, 0xFFFFFFFF);	/* Fill the last fragment on the FAT if needed */
			if (res != FR_OK) return res;
			if (dp->obj.sclust != 0) {		/* Is it a sub-directory? */
				DIR dj;

				res = load_obj_xdir(&dj, &dp->obj);	/* Load the object status */
				if (res != FR_OK) return res;
				dp->obj.objsize += (DWORD)fs->csize * SS(fs);			/* Increase the directory size by cluster size */
				st_qword(fs->dirbuf + XDIR_FileSize, dp->obj.objsize);
				st_qword(fs->dirbuf + XDIR_ValidFileSize, dp->obj.objsize);
				fs->dirbuf[XDIR_GenFlags] = dp->obj.stat | 1;			/* Update the allocation status */
				res = store_xdir(&dj);				/* Store the object status */
				if (res != FR_OK) return res;
			}
		}

		create_xdir(fs->dirbuf, fs->lfnbuf);	/* Create on-memory directory block to be written later */
		return FR_OK;
	}
#endif
	/* On the FAT/FAT32 volume */
	mem_cpy(sn, dp->fn, 12);
	if (sn[NSFLAG] & NS_LOSS) {			/* When LFN is out of 8.3 format, generate a numbered name */
		dp->fn[NSFLAG] = NS_NOLFN;		/* Find only SFN */
		for (n = 1; n < 100; n++) {
			gen_numname(dp->fn, sn, fs->lfnbuf, n);	/* Generate a numbered name */
			res = dir_find(dp);				/* Check if the name collides with existing SFN */
			if (res != FR_OK) break;
		}
		if (n == 100) return FR_DENIED;		/* Abort if too many collisions */
		if (res != FR_NO_FILE) return res;	/* Abort if the result is other than 'not collided' */
		dp->fn[NSFLAG] = sn[NSFLAG];
	}

	/* Create an SFN with/without LFNs. */
	n_ent = (sn[NSFLAG] & NS_LFN) ? (len + 12) / 13 + 1 : 1;	/* Number of entries to allocate */
	res = dir_alloc(dp, n_ent);		/* Allocate entries */
	if (res == FR_OK && --n_ent) {	/* Set LFN entry if needed */
		res = dir_sdi(dp, dp->dptr - n_ent * SZDIRE);
		if (res == FR_OK) {
			sum = sum_sfn(dp->fn);	/* Checksum value of the SFN tied to the LFN */
			do {					/* Store LFN entries in bottom first */
				res = move_window(fs, dp->sect);
				if (res != FR_OK) break;
				put_lfn(fs->lfnbuf, dp->dir, (BYTE)n_ent, sum);
				fs->wflag = 1;
				res = dir_next(dp, 0);	/* Next entry */
			} while (res == FR_OK && --n_ent);
		}
	}

#else	/* Non LFN configuration */
	res = dir_alloc(dp, 1);		/* Allocate an entry for SFN */

#endif

	/* Set SFN entry */
	if (res == FR_OK) {
		res = move_window(fs, dp->sect);
		if (res == FR_OK) {
			mem_set(dp->dir, 0, SZDIRE);	/* Clean the entry */
			mem_cpy(dp->dir + DIR_Name, dp->fn, 11);	/* Put SFN */
#if FF_USE_LFN
			dp->dir[DIR_NTres] = dp->fn[NSFLAG] & (NS_BODY | NS_EXT);	/* Put NT flag */
#endif
			fs->wflag = 1;
		}
	}

	return res;
}

// Assembly:
movl $0x6, %eax
testb $-0x60, 0x53(%rdi)
je 0x5bdd
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %r14
movq (%rdi), %rbx
leaq 0x48(%rdi), %r12
movq 0x10(%rbx), %rax
movl $0xb, %r13d
leal -0xb(%r13), %ecx
incl %r13d
cmpw $0x0, (%rax,%rcx,2)
jne 0x5bff
cmpb $0x4, (%rbx)
jne 0x5cee
addl $0x2, %r13d
movl $0x88888889, %r15d      # imm = 0x88888889
imulq %r13, %r15
shrq $0x23, %r15
leal 0x2(%r15), %esi
movq %r14, %rdi
callq 0x941e
testl %eax, %eax
jne 0x5ff4
movl 0x30(%r14), %eax
shll $0x5, %r15d
negl %r15d
addl %r15d, %eax
addl $-0x20, %eax
movl %eax, 0x54(%r14)
movb 0xb(%r14), %al
testb $0x4, %al
jne 0x5fcd
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movups %xmm0, 0x20(%rbx)
movups %xmm0, 0x30(%rbx)
movups %xmm0, 0x10(%rbx)
movb $-0x7b, (%rbx)
movb $-0x40, 0x20(%rbx)
movw $0x1, %cx
movl $0x40, %eax
xorl %r8d, %r8d
xorl %edx, %edx
movl %r8d, %esi
leal 0x1(%rax), %r8d
movl %eax, %r9d
movb $-0x3f, (%rbx,%r9)
addl $0x2, %eax
movb $0x0, (%rbx,%r8)
testw %cx, %cx
je 0x5cb6
movzbl %dl, %edx
movzwl (%rdi,%rdx,2), %ecx
cmpw $0x1, %cx
sbbb $-0x1, %dl
movl %eax, %r8d
movw %cx, (%rbx,%r8)
addl $0x2, %eax
testb $0x1f, %al
jne 0x5ca3
leal 0x1(%rsi), %r8d
movzbl %dl, %r9d
cmpw $0x0, (%rdi,%r9,2)
jne 0x5c8c
movb %dl, 0x23(%rbx)
addb $0x2, %sil
movb %sil, 0x1(%rbx)
callq 0xb968
movw %ax, 0x24(%rbx)
jmp 0x5d8e
movl 0x7(%r12), %eax
movl %eax, 0xf(%rsp)
movq (%r12), %rax
movq %rax, 0x8(%rsp)
movb 0x53(%r14), %bpl
testb $0x1, %bpl
jne 0x5d95
movl $0x1, %r15d
testb $0x2, %bpl
je 0x5d2b
movl %r13d, %eax
imulq $0x4ec4ec4f, %rax, %r15 # imm = 0x4EC4EC4F
shrq $0x22, %r15
incl %r15d
movq %r14, %rdi
movl %r15d, %esi
callq 0x941e
testl %eax, %eax
je 0x5ecb
testl %eax, %eax
jne 0x5ff4
movq 0x38(%r14), %rsi
movq %rbx, %rdi
callq 0x6314
testl %eax, %eax
jne 0x5ff4
movq 0x40(%r14), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq 0x40(%r14), %rax
xorl %ecx, %ecx
movb (%r12,%rcx), %dl
movb %dl, (%rax,%rcx)
incq %rcx
cmpl $0xb, %ecx
jne 0x5d6e
movb 0x53(%r14), %al
andb $0x18, %al
movq 0x40(%r14), %rcx
movb %al, 0xc(%rcx)
movb $0x1, 0x3(%rbx)
xorl %eax, %eax
jmp 0x5ff4
movb $0x40, 0x53(%r14)
movl $0x1, %r15d
movq 0x10(%rbx), %rax
movl 0xf(%rsp), %ecx
movl %ecx, 0x7(%r12)
movq 0x8(%rsp), %rcx
movq %rcx, (%r12)
movl %r15d, %ecx
cmpl $0x5, %r15d
jbe 0x5e04
movzwl (%rax), %edx
movl %r15d, %ecx
movl %r15d, %edi
testw %dx, %dx
je 0x5e04
movl $0x10, %esi
movl %edi, %ecx
movl %edx, %edi
andl $0x1, %edi
movzwl %dx, %edx
leal (%rdi,%rcx,2), %edi
shrl %edx
movl %edi, %r8d
xorl $0x11021, %r8d          # imm = 0x11021
testw %cx, %cx
movl %r8d, %ecx
cmovnsl %edi, %ecx
decl %esi
jne 0x5dd4
movzwl 0x2(%rax), %edx
addq $0x2, %rax
movl %ecx, %edi
jmp 0x5dc8
movl $0x7, %eax
movl $0x6, %esi
movl %ecx, %edx
movl %ecx, %edi
andb $0xf, %dil
leal 0x30(%rdi), %r8d
addb $0x37, %dil
cmpb $0x3a, %r8b
movzbl %dil, %edi
movzbl %r8b, %r8d
cmovael %edi, %r8d
movl %esi, %edi
movl %eax, %esi
decl %eax
movb %r8b, (%rsp,%rsi)
shrl $0x4, %edx
leal -0x1(%rdi), %esi
cmpl $0xf, %ecx
movl %edx, %ecx
ja 0x5e10
movl %eax, %ecx
movb $0x7e, (%rsp,%rcx)
testl %eax, %eax
je 0x5e66
movl %edi, %edx
xorl %ecx, %ecx
cmpb $0x20, (%r12,%rcx)
je 0x5e68
incq %rcx
cmpq %rcx, %rdx
jne 0x5e53
movl %eax, %ecx
jmp 0x5e68
xorl %ecx, %ecx
movb $0x20, %dl
cmpl $0x7, %eax
ja 0x5e76
movl %eax, %edx
incl %eax
movb (%rsp,%rdx), %dl
movl %ecx, %esi
incl %ecx
movb %dl, (%r12,%rsi)
cmpl $0x8, %ecx
jb 0x5e68
movq %r14, %rdi
callq 0xb68e
testl %eax, %eax
jne 0x5ea6
incl %r15d
cmpl $0x64, %r15d
jne 0x5da0
xorl %ecx, %ecx
movl $0x64, %r15d
jmp 0x5ea8
movl %eax, %ecx
movl $0x7, %eax
cmpl $0x64, %r15d
je 0x5ff4
movl %ecx, %eax
cmpl $0x4, %ecx
jne 0x5ff4
movb %bpl, 0x53(%r14)
jmp 0x5d0e
decl %r15d
je 0x6003
movl 0x30(%r14), %esi
movl %r15d, %eax
shll $0x5, %eax
subl %eax, %esi
movq %r14, %rdi
callq 0x7545
testl %eax, %eax
jne 0x5d3e
xorl %ebp, %ebp
movl $0x48, %eax
movzbl %bpl, %ecx
movl %ecx, %edx
shrl %edx
shll $0x7, %ecx
orl %edx, %ecx
movzbl (%r14,%rax), %ebp
addl %ecx, %ebp
incq %rax
cmpl $0x53, %eax
jne 0x5ef7
leaq 0x7536(%rip), %r13      # 0xd450
movq 0x38(%r14), %rsi
movq %rbx, %rdi
callq 0x6314
testl %eax, %eax
jne 0x5d3e
movq 0x10(%rbx), %rcx
movq 0x40(%r14), %rax
movb %bpl, 0xd(%rax)
movw $0xf, 0xb(%rax)
movw $0x0, 0x1a(%rax)
movzbl %r15b, %edx
leal (%rdx,%rdx,2), %esi
leal (%rdx,%rsi,4), %edx
addl $-0xd, %edx
xorl %esi, %esi
xorl %edi, %edi
cmpw $-0x1, %di
je 0x5f65
movl %edx, %edi
incl %edx
movzwl (%rcx,%rdi,2), %edi
movzbl (%rsi,%r13), %r8d
movw %di, (%rax,%r8)
cmpw $0x1, %di
movl $0x0, %r8d
sbbl %r8d, %r8d
orl %edi, %r8d
movl %r8d, %edi
incq %rsi
cmpq $0xd, %rsi
jne 0x5f57
cmpw $-0x1, %di
je 0x5f9f
movl %edx, %edx
cmpw $0x0, (%rcx,%rdx,2)
je 0x5f9f
movl %r15d, %ecx
jmp 0x5fa5
movl %r15d, %ecx
orb $0x40, %cl
movb %cl, (%rax)
movb $0x1, 0x3(%rbx)
movq %r14, %rdi
xorl %esi, %esi
callq 0x7c47
testl %eax, %eax
jne 0x5d3e
xorl %eax, %eax
decl %r15d
jne 0x5f1a
jmp 0x5d3e
andb $-0x5, %al
movb %al, 0xb(%r14)
movq %r14, %rdi
callq 0x701f
testl %eax, %eax
jne 0x5ff4
movl 0x34(%r14), %esi
movq %r14, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x706c
testl %eax, %eax
je 0x600a
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x5d3e
cmpl $0x0, 0xc(%r14)
je 0x5c5d
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x70be
testl %eax, %eax
je 0x602a
xorl %ecx, %ecx
jmp 0x60a3
movzwl 0xa(%rbx), %eax
shll $0x9, %eax
movq 0x10(%r14), %rdx
addq %rdx, %rax
movq %rax, 0x10(%r14)
movq 0x18(%rbx), %rcx
movb %dl, 0x38(%rcx)
movb %ah, 0x39(%rcx)
movl %eax, %edx
shrl $0x10, %edx
movb %dl, 0x3a(%rcx)
movl %eax, %edx
shrl $0x18, %edx
movb %dl, 0x3b(%rcx)
movq %rax, %rdx
shrq $0x20, %rdx
movb %dl, 0x3c(%rcx)
movq %rax, %rdx
shrq $0x28, %rdx
movb %dl, 0x3d(%rcx)
movq %rax, %rdx
shrq $0x30, %rdx
movb %dl, 0x3e(%rcx)
shrq $0x38, %rax
movb %al, 0x3f(%rcx)
movq 0x18(%rbx), %rax
movq 0x10(%r14), %rcx
movq %rcx, 0x28(%rax)
movb 0xb(%r14), %al
orb $0x1, %al
movq 0x18(%rbx), %rcx
movb %al, 0x21(%rcx)
leaq 0x8(%rsp), %rdi
callq 0x60e7
testl %eax, %eax
sete %cl
testb %cl, %cl
jne 0x5c5d
jmp 0x5ff4