// File: /workspace/github_c_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
subq $0x508, %rsp            # imm = 0x508
leaq 0x8(%rsp), %rax
movq %rdi, (%rax)
movq %rsp, %rsi
pushq $0x2
popq %r15
movq %rax, %rdi
movl %r15d, %edx
callq 0x473a
testl %eax, %eax
je 0x7b44
movl %eax, %r14d
jmp 0x7c7a
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 0x50b1
testl %eax, %eax
pushq $0x8
popq %r14
cmovnel %eax, %r14d
cmpl $0x4, %r14d
jne 0x7c7a
leaq 0x70(%rsp), %rdi
movq %rbx, (%rdi)
xorl %r12d, %r12d
xorl %esi, %esi
callq 0x6373
movl %eax, %ebp
testl %eax, %eax
pushq $0x7
popq %r14
cmovnel %r12d, %r14d
cmpl $0x1, %eax
cmovel %r15d, %r14d
cmpl $-0x1, %eax
pushq $0x1
popq %r15
cmovel %r15d, %r14d
callq 0x2992
testl %r14d, %r14d
jne 0x7c6c
movl %eax, %r13d
movq %rbx, %rdi
movl %ebp, %esi
callq 0x7d35
movl %r15d, %r14d
testl %eax, %eax
jne 0x7c6c
cmpb $0x4, (%rbx)
je 0x7c5b
leaq 0x60(%rbx), %r14
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rax, 0x61(%rbx)
movw $0x2020, 0x69(%rbx)     # imm = 0x2020
movb $0x2e, %r12b
movb %r12b, 0x60(%rbx)
movb $0x10, 0x6b(%rbx)
movl %r13d, %ecx
movb %cl, 0x76(%rbx)
movb %ch, 0x77(%rbx)
movl %r13d, %eax
shrl $0x10, %eax
movb %al, 0x78(%rbx)
movl %r13d, %eax
shrl $0x18, %eax
movb %al, 0x79(%rbx)
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x5bde
leaq 0x80(%rbx), %r15
pushq $0x20
popq %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x60c7
movb %r12b, 0x81(%rbx)
movl 0x1c(%rsp), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5bde
movb $0x1, 0x3(%rbx)
leaq 0x10(%rsp), %rdi
callq 0x555a
movl %eax, %r14d
testl %eax, %eax
je 0x7c8f
leaq 0x70(%rsp), %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x5a5f
movl %r14d, %eax
addq $0x508, %rsp            # imm = 0x508
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x4, (%rbx)
jne 0x7d09
movq 0x18(%rbx), %rax
movl %r13d, 0xc(%rax)
movq 0x18(%rbx), %rax
movl %ebp, 0x34(%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 0x59d7
testl %eax, %eax
jne 0x7b3c
jmp 0x7d28
movq 0x50(%rsp), %r14
movl %r13d, 0x16(%r14)
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x5bde
movb $0x10, 0xb(%r14)
movb $0x1, 0x3(%rbx)
movq %rbx, %rdi
callq 0x68ea
jmp 0x7b3c