// File: /workspace/github_c_makefile_star2_O3/lb3361[P]dosfs/ff.c
// Function: f_mkdir
FRESULT f_mkdir (
	const TCHAR* path		/* Pointer to the directory path */
)
{
	FRESULT res;
	DIR dj;
	FFOBJID sobj;
	FATFS *fs;
	DWORD dcl, pcl, tm;
	DEF_NAMBUF


	res = mount_volume(&path, &fs, FA_WRITE);	/* Get logical drive */
	if (res == FR_OK) {
		dj.obj.fs = fs;
		INIT_NAMBUF(fs);
		res = follow_path(&dj, path);			/* Follow the file path */
		if (res == FR_OK) res = FR_EXIST;		/* Name collision? */
		if (FF_FS_RPATH && res == FR_NO_FILE && (dj.fn[NSFLAG] & NS_DOT)) {	/* Invalid name? */
			res = FR_INVALID_NAME;
		}
		if (res == FR_NO_FILE) {				/* It is clear to create a new directory */
			sobj.fs = fs;						/* New object id to create a new chain */
			dcl = create_chain(&sobj, 0);		/* Allocate a cluster for the new directory */
			res = FR_OK;
			if (dcl == 0) res = FR_DENIED;		/* No space to allocate a new cluster? */
			if (dcl == 1) res = FR_INT_ERR;		/* Any insanity? */
			if (dcl == 0xFFFFFFFF) res = FR_DISK_ERR;	/* Disk error? */
			tm = GET_FATTIME();
			if (res == FR_OK) {
				res = dir_clear(fs, dcl);		/* Clean up the new table */
				if (res == FR_OK) {
					if (!FF_FS_EXFAT || fs->fs_type != FS_EXFAT) {	/* Create dot entries (FAT only) */
						mem_set(fs->win + DIR_Name, ' ', 11);	/* Create "." entry */
						fs->win[DIR_Name] = '.';
						fs->win[DIR_Attr] = AM_DIR;
						st_dword(fs->win + DIR_ModTime, tm);
						st_clust(fs, fs->win, dcl);
						mem_cpy(fs->win + SZDIRE, fs->win, SZDIRE); /* Create ".." entry */
						fs->win[SZDIRE + 1] = '.'; pcl = dj.obj.sclust;
						st_clust(fs, fs->win + SZDIRE, pcl);
						fs->wflag = 1;
					}
					res = dir_register(&dj);	/* Register the object to the parent directoy */
				}
			}
			if (res == FR_OK) {
#if FF_FS_EXFAT
				if (fs->fs_type == FS_EXFAT) {	/* Initialize directory entry block */
					st_dword(fs->dirbuf + XDIR_ModTime, tm);	/* Created time */
					st_dword(fs->dirbuf + XDIR_FstClus, dcl);	/* Table start cluster */
					st_dword(fs->dirbuf + XDIR_FileSize, (DWORD)fs->csize * SS(fs));	/* Directory size needs to be valid */
					st_dword(fs->dirbuf + XDIR_ValidFileSize, (DWORD)fs->csize * SS(fs));
					fs->dirbuf[XDIR_GenFlags] = 3;				/* Initialize the object flag */
					fs->dirbuf[XDIR_Attr] = AM_DIR;				/* Attribute */
					res = store_xdir(&dj);
				} else
#endif
				{
					st_dword(dj.dir + DIR_ModTime, tm);	/* Created time */
					st_clust(fs, dj.dir, dcl);			/* Table start cluster */
					dj.dir[DIR_Attr] = AM_DIR;			/* Attribute */
					fs->wflag = 1;
				}
				if (res == FR_OK) {
					res = sync_fs(fs);
				}
			} else {
				remove_chain(&sobj, dcl, 0);		/* Could not register, remove the allocated cluster */
			}
		}
		FREE_NAMBUF();
	}

	LEAVE_FF(fs, res);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x500, %rsp            # imm = 0x500
leaq 0x8(%rsp), %rax
movq %rdi, (%rax)
movq %rsp, %rsi
movq %rax, %rdi
movl $0x2, %edx
callq 0x4ada
testl %eax, %eax
je 0x8221
movl %eax, %ebp
jmp 0x83e2
movq (%rsp), %rbx
leaq 0x10(%rsp), %rdi
movq %rbx, (%rdi)
leaq 0xa0(%rsp), %rax
movq %rax, 0x10(%rbx)
leaq 0x2a0(%rsp), %rax
movq %rax, 0x18(%rbx)
movq 0x8(%rsp), %rsi
callq 0x554e
testl %eax, %eax
movl $0x8, %ebp
cmovnel %eax, %ebp
cmpl $0x4, %ebp
jne 0x83e2
leaq 0x70(%rsp), %rdi
movq %rbx, (%rdi)
xorl %ebp, %ebp
xorl %esi, %esi
callq 0x68e6
movl %eax, %r14d
testl %eax, %eax
movl $0x7, %eax
cmovnel %ebp, %eax
cmpl $0x1, %r14d
movl $0x2, %ebp
cmovnel %eax, %ebp
cmpl $-0x1, %r14d
movl $0x1, %eax
cmovel %eax, %ebp
callq 0x2e66
testl %ebp, %ebp
jne 0x83d3
movq %rbx, %rdi
movl %r14d, %esi
movl %eax, %r12d
callq 0x84db
movl $0x1, %ebp
testl %eax, %eax
jne 0x83d3
movl %r14d, %r15d
movb (%rbx), %al
cmpb $0x4, %al
je 0x83c0
movl %r12d, %edx
movabsq $0x2020202020202020, %rcx # imm = 0x2020202020202020
movq %rcx, 0x61(%rbx)
movw $0x2020, 0x69(%rbx)     # imm = 0x2020
movb $0x2e, 0x60(%rbx)
movb $0x10, 0x6b(%rbx)
movb %dl, 0x76(%rbx)
movb %dh, 0x77(%rbx)
movl %r12d, %ecx
shrl $0x10, %ecx
movb %cl, 0x78(%rbx)
movl %r12d, %ecx
shrl $0x18, %ecx
movb %cl, 0x79(%rbx)
movl %r15d, %ecx
movb %cl, 0x7a(%rbx)
movb %ch, 0x7b(%rbx)
cmpb $0x3, %al
jne 0x8321
movl %ecx, %eax
shrl $0x10, %eax
movb %al, 0x74(%rbx)
movl %ecx, %eax
shrl $0x18, %eax
movb %al, 0x75(%rbx)
movb 0x60(%rbx), %al
movb %al, 0x80(%rbx)
movq 0x61(%rbx), %rax
movq %rax, 0x81(%rbx)
movzwl 0x69(%rbx), %eax
movw %ax, 0x89(%rbx)
movb 0x6b(%rbx), %al
movb %al, 0x8b(%rbx)
movl 0x6c(%rbx), %eax
movl %eax, 0x8c(%rbx)
movl 0x70(%rbx), %eax
movl %eax, 0x90(%rbx)
movb 0x74(%rbx), %al
movb %al, 0x94(%rbx)
movb 0x75(%rbx), %al
movb %al, 0x95(%rbx)
movl 0x76(%rbx), %eax
movl %eax, 0x96(%rbx)
movb 0x7a(%rbx), %al
movb %al, 0x9a(%rbx)
movl 0x7b(%rbx), %eax
movl %eax, 0x9b(%rbx)
movb 0x7f(%rbx), %al
movb %al, 0x9f(%rbx)
movb $0x2e, 0x81(%rbx)
movl 0x1c(%rsp), %eax
movw %ax, 0x9a(%rbx)
cmpb $0x3, (%rbx)
jne 0x83bc
movl %eax, %ecx
shrl $0x10, %ecx
movb %cl, 0x94(%rbx)
shrl $0x18, %eax
movb %al, 0x95(%rbx)
movb $0x1, 0x3(%rbx)
leaq 0x10(%rsp), %rdi
callq 0x5a07
movl %eax, %ebp
testl %eax, %eax
movl %r15d, %r14d
je 0x83f4
leaq 0x70(%rsp), %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x5f9a
movl %ebp, %eax
addq $0x500, %rsp            # imm = 0x500
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl %r12d, %edx
movl %r14d, %ecx
shrl $0x8, %ecx
cmpb $0x4, (%rbx)
jne 0x848f
movq 0x18(%rbx), %rax
movl %edx, 0xc(%rax)
movq 0x18(%rbx), %rax
movb %r14b, 0x34(%rax)
movb %cl, 0x35(%rax)
movl %r14d, %ecx
shrl $0x10, %ecx
movb %cl, 0x36(%rax)
shrl $0x18, %r14d
movb %r14b, 0x37(%rax)
movq 0x18(%rbx), %rax
movzwl 0xa(%rbx), %ecx
xorl %edx, %edx
movb %dl, 0x38(%rax)
leal (%rcx,%rcx), %esi
movb %sil, 0x39(%rax)
movl %ecx, %esi
shrl $0x7, %esi
movb %sil, 0x3a(%rax)
shrl $0xf, %ecx
movb %cl, 0x3b(%rax)
movq 0x18(%rbx), %rax
movzwl 0xa(%rbx), %ecx
movb %dl, 0x28(%rax)
leal (%rcx,%rcx), %edx
movb %dl, 0x29(%rax)
movl %ecx, %edx
shrl $0x7, %edx
movb %dl, 0x2a(%rax)
shrl $0xf, %ecx
movb %cl, 0x2b(%rax)
movq 0x18(%rbx), %rax
movb $0x3, 0x21(%rax)
movq 0x18(%rbx), %rax
movb $0x10, 0x4(%rax)
leaq 0x10(%rsp), %rdi
callq 0x5ee7
testl %eax, %eax
jne 0x821a
jmp 0x84ce
movq 0x50(%rsp), %rax
movb %dl, 0x16(%rax)
movb %dh, 0x17(%rax)
movl %edx, %esi
shrl $0x10, %edx
movb %dl, 0x18(%rax)
shrl $0x18, %esi
movb %sil, 0x19(%rax)
movb %r15b, 0x1a(%rax)
movb %cl, 0x1b(%rax)
cmpb $0x3, (%rbx)
jne 0x84c6
movl %r15d, %ecx
shrl $0x10, %ecx
movb %cl, 0x14(%rax)
shrl $0x18, %r15d
movb %r15b, 0x15(%rax)
movb $0x10, 0xb(%rax)
movb $0x1, 0x3(%rbx)
movq %rbx, %rdi
callq 0x6ea3
jmp 0x821a