// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x53(%rax), %eax
andl $0xa0, %eax
cmpl $0x0, %eax
je 0x5af8
movl $0x6, -0x4(%rbp)
jmp 0x5ef5
movl $0x0, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x28(%rbp), %ecx
cmpw $0x0, (%rax,%rcx,2)
je 0x5b1e
jmp 0x5b13
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x5aff
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x4, %eax
jne 0x5cc0
movl -0x28(%rbp), %eax
addl $0xe, %eax
movl $0xf, %ecx
xorl %edx, %edx
divl %ecx
addl $0x2, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0xafc0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x5b63
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5ef5
movq -0x10(%rbp), %rax
movl 0x30(%rax), %ecx
movl -0x2c(%rbp), %eax
subl $0x1, %eax
shll $0x5, %eax
subl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x54(%rax)
movq -0x10(%rbp), %rax
movzbl 0xb(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x5c9f
movq -0x10(%rbp), %rax
movzbl 0xb(%rax), %ecx
andl $-0x5, %ecx
movb %cl, 0xb(%rax)
movq -0x10(%rbp), %rdi
callq 0x7820
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x5bbb
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5ef5
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x34(%rax), %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x78b0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x5be4
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5ef5
movq -0x10(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x5c9d
movq -0x10(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x7950
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x5c16
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5ef5
movq -0x20(%rbp), %rax
movzwl 0xa(%rax), %eax
shll $0x9, %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
addq $0x38, %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x79f0
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
addq $0x28, %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x79f0
movq -0x10(%rbp), %rax
movzbl 0xb(%rax), %eax
orl $0x1, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movb %cl, 0x21(%rax)
leaq -0xa0(%rbp), %rdi
callq 0x6040
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x5c9b
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5ef5
jmp 0x5c9d
jmp 0x5c9f
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0xed20
movl $0x0, -0x4(%rbp)
jmp 0x5ef5
leaq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x48, %rsi
movl $0xc, %edx
callq 0x6d20
movzbl -0x2d(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x5d61
movq -0x10(%rbp), %rax
movb $0x40, 0x53(%rax)
movl $0x1, -0x24(%rbp)
cmpl $0x64, -0x24(%rbp)
jae 0x5d34
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
leaq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdx
movl -0x24(%rbp), %ecx
callq 0xee40
movq -0x10(%rbp), %rdi
callq 0xe7a0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x5d27
jmp 0x5d34
jmp 0x5d29
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x5cf1
cmpl $0x64, -0x24(%rbp)
jne 0x5d46
movl $0x7, -0x4(%rbp)
jmp 0x5ef5
cmpl $0x4, -0x14(%rbp)
je 0x5d57
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5ef5
movb -0x2d(%rbp), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x53(%rax)
movzbl -0x2d(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x5d87
movl -0x28(%rbp), %eax
addl $0xc, %eax
movl $0xd, %ecx
xorl %edx, %edx
divl %ecx
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x5d94
movl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x5d94
movl -0xa4(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0xafc0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x5e7f
movl -0x2c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
je 0x5e7f
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x30(%rax), %esi
movl -0x2c(%rbp), %eax
shll $0x5, %eax
subl %eax, %esi
callq 0x82b0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x5e7d
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
callq 0xecd0
movb %al, -0x39(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
callq 0x6480
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x5e19
jmp 0x5e7b
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rsi
movl -0x2c(%rbp), %eax
movzbl %al, %edx
movzbl -0x39(%rbp), %ecx
callq 0xf000
movq -0x20(%rbp), %rax
movb $0x1, 0x3(%rax)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x8b90
movl %eax, -0x14(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x14(%rbp)
movb %al, -0xa5(%rbp)
jne 0x5e71
movl -0x2c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
setne %al
movb %al, -0xa5(%rbp)
movb -0xa5(%rbp), %al
testb $0x1, %al
jne 0x5dfd
jmp 0x5e7d
jmp 0x5e7f
cmpl $0x0, -0x14(%rbp)
jne 0x5eef
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
callq 0x6480
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x5eed
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x5f80
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x48, %rsi
movl $0xb, %edx
callq 0x6d20
movq -0x10(%rbp), %rax
movzbl 0x53(%rax), %eax
andl $0x18, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movb %cl, 0xc(%rax)
movq -0x20(%rbp), %rax
movb $0x1, 0x3(%rax)
jmp 0x5eef
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)