// File: /workspace/github_c_makefile_star2_O1/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 %rbx
subq $0x508, %rsp            # imm = 0x508
leaq 0x8(%rsp), %rax
movq %rdi, (%rax)
movq %rsp, %rsi
movq %rax, %rdi
movl $0x2, %edx
callq 0x4c82
movl %eax, %ebp
testl %eax, %eax
jne 0x878e
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 0x5747
testl %eax, %eax
movl $0x8, %ebp
cmovnel %eax, %ebp
cmpl $0x4, %ebp
jne 0x878e
leaq 0x70(%rsp), %rdi
movq %rbx, (%rdi)
xorl %ebp, %ebp
xorl %esi, %esi
callq 0x6ae6
testl %eax, %eax
movl $0x7, %edx
cmovnel %ebp, %edx
cmpl $0x1, %eax
movl $0x2, %ecx
cmovnel %edx, %ecx
movl %eax, %r14d
cmpl $-0x1, %eax
movl $0x1, %ebp
cmovnel %ecx, %ebp
callq 0x2e38
movl %eax, %r15d
testl %ebp, %ebp
jne 0x868e
movq %rbx, %rdi
movl %r14d, %esi
callq 0x879e
movl %eax, %ebp
testl %eax, %eax
jne 0x868e
movb (%rbx), %al
cmpb $0x4, %al
je 0x8682
movabsq $0x2020202020202020, %rcx # imm = 0x2020202020202020
movq %rcx, 0x60(%rbx)
movl $0x20202020, 0x67(%rbx) # imm = 0x20202020
movb $0x2e, 0x60(%rbx)
movb $0x10, 0x6b(%rbx)
movl %r15d, %edx
movb %dl, 0x76(%rbx)
movb %dh, 0x77(%rbx)
movl %r15d, %ecx
shrl $0x10, %ecx
movb %cl, 0x78(%rbx)
movl %r15d, %ecx
shrl $0x18, %ecx
movb %cl, 0x79(%rbx)
movl %r14d, %ecx
movb %cl, 0x7a(%rbx)
movb %ch, 0x7b(%rbx)
cmpb $0x3, %al
jne 0x863d
movl %ecx, %eax
shrl $0x10, %eax
movb %al, 0x74(%rbx)
movl %ecx, %eax
shrl $0x18, %eax
movb %al, 0x75(%rbx)
movl $0x60, %eax
movb (%rbx,%rax), %cl
movb %cl, 0x20(%rbx,%rax)
incq %rax
cmpl $0x80, %eax
jne 0x8642
movb $0x2e, 0x81(%rbx)
movl 0x1c(%rsp), %eax
movw %ax, 0x9a(%rbx)
cmpb $0x3, (%rbx)
jne 0x867e
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 0x5bd1
movl %eax, %ebp
testl %ebp, %ebp
je 0x86a6
leaq 0x70(%rsp), %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x619a
jmp 0x878e
movl %r14d, %esi
shrl $0x8, %esi
cmpb $0x4, (%rbx)
jne 0x873a
movl %r14d, %edx
movq 0x18(%rbx), %rax
movl %r15d, 0xc(%rax)
movq 0x18(%rbx), %rax
movb %dl, 0x34(%rax)
movb %sil, 0x35(%rax)
movl %r14d, %ecx
shrl $0x10, %ecx
movb %cl, 0x36(%rax)
shrl $0x18, %edx
movb %dl, 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 0x60e7
movl %eax, %ebp
jmp 0x877f
movq 0x50(%rsp), %rax
movl %r15d, %ecx
movb %cl, 0x16(%rax)
movb %ch, 0x17(%rax)
movl %r15d, %edx
shrl $0x10, %edx
movb %dl, 0x18(%rax)
shrl $0x18, %ecx
movb %cl, 0x19(%rax)
movb %r14b, 0x1a(%rax)
movb %sil, 0x1b(%rax)
cmpb $0x3, (%rbx)
jne 0x8775
movl %r14d, %ecx
shrl $0x10, %ecx
movb %cl, 0x14(%rax)
shrl $0x18, %r14d
movb %r14b, 0x15(%rax)
movb $0x10, 0xb(%rax)
movb $0x1, 0x3(%rbx)
xorl %ebp, %ebp
testl %ebp, %ebp
jne 0x878e
movq (%rsp), %rdi
callq 0x70fe
movl %eax, %ebp
movl %ebp, %eax
addq $0x508, %rsp            # imm = 0x508
popq %rbx
popq %r14
popq %r15
popq %rbp
retq