// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x520, %rsp            # imm = 0x520
movq %rdi, -0x8(%rbp)
leaq -0x8(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
movl $0x2, %edx
callq 0x4940
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x9b7f
movq -0xa8(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0x2c0(%rbp), %rcx
movq -0xa8(%rbp), %rax
movq %rcx, 0x10(%rax)
leaq -0x520(%rbp), %rcx
movq -0xa8(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x5910
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x98cd
movl $0x8, -0xc(%rbp)
cmpl $0x4, -0xc(%rbp)
jne 0x9b7d
movq -0xa8(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
callq 0x71d0
movl %eax, -0xac(%rbp)
movl $0x0, -0xc(%rbp)
cmpl $0x0, -0xac(%rbp)
jne 0x9910
movl $0x7, -0xc(%rbp)
cmpl $0x1, -0xac(%rbp)
jne 0x9920
movl $0x2, -0xc(%rbp)
cmpl $-0x1, -0xac(%rbp)
jne 0x9930
movl $0x1, -0xc(%rbp)
callq 0x1be0
movl %eax, -0xb4(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x9a53
movq -0xa8(%rbp), %rdi
movl -0xac(%rbp), %esi
callq 0x9b90
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x9a51
movq -0xa8(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x4, %eax
je 0x9a45
movq -0xa8(%rbp), %rdi
addq $0x60, %rdi
movl $0x20, %esi
movl $0xb, %edx
callq 0x5f80
movq -0xa8(%rbp), %rax
movb $0x2e, 0x60(%rax)
movq -0xa8(%rbp), %rax
movb $0x10, 0x6b(%rax)
movq -0xa8(%rbp), %rdi
addq $0x60, %rdi
addq $0x16, %rdi
movl -0xb4(%rbp), %esi
callq 0x5fc0
movq -0xa8(%rbp), %rdi
movq -0xa8(%rbp), %rsi
addq $0x60, %rsi
movl -0xac(%rbp), %edx
callq 0x6430
movq -0xa8(%rbp), %rdi
addq $0x60, %rdi
addq $0x20, %rdi
movq -0xa8(%rbp), %rsi
addq $0x60, %rsi
movl $0x20, %edx
callq 0x6d20
movq -0xa8(%rbp), %rax
movb $0x2e, 0x81(%rax)
movl -0x64(%rbp), %eax
movl %eax, -0xb0(%rbp)
movq -0xa8(%rbp), %rdi
movq -0xa8(%rbp), %rsi
addq $0x60, %rsi
addq $0x20, %rsi
movl -0xb0(%rbp), %edx
callq 0x6430
movq -0xa8(%rbp), %rax
movb $0x1, 0x3(%rax)
leaq -0x70(%rbp), %rdi
callq 0x5ac0
movl %eax, -0xc(%rbp)
jmp 0x9a53
cmpl $0x0, -0xc(%rbp)
jne 0x9b67
movq -0xa8(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x4, %eax
jne 0x9b14
movq -0xa8(%rbp), %rax
movq 0x18(%rax), %rdi
addq $0xc, %rdi
movl -0xb4(%rbp), %esi
callq 0x5fc0
movq -0xa8(%rbp), %rax
movq 0x18(%rax), %rdi
addq $0x34, %rdi
movl -0xac(%rbp), %esi
callq 0x5fc0
movq -0xa8(%rbp), %rax
movq 0x18(%rax), %rdi
addq $0x38, %rdi
movq -0xa8(%rbp), %rax
movzwl 0xa(%rax), %esi
shll $0x9, %esi
callq 0x5fc0
movq -0xa8(%rbp), %rax
movq 0x18(%rax), %rdi
addq $0x28, %rdi
movq -0xa8(%rbp), %rax
movzwl 0xa(%rax), %esi
shll $0x9, %esi
callq 0x5fc0
movq -0xa8(%rbp), %rax
movq 0x18(%rax), %rax
movb $0x3, 0x21(%rax)
movq -0xa8(%rbp), %rax
movq 0x18(%rax), %rax
movb $0x10, 0x4(%rax)
leaq -0x70(%rbp), %rdi
callq 0x6040
movl %eax, -0xc(%rbp)
jmp 0x9b50
movq -0x30(%rbp), %rdi
addq $0x16, %rdi
movl -0xb4(%rbp), %esi
callq 0x5fc0
movq -0xa8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl -0xac(%rbp), %edx
callq 0x6430
movq -0x30(%rbp), %rax
movb $0x10, 0xb(%rax)
movq -0xa8(%rbp), %rax
movb $0x1, 0x3(%rax)
cmpl $0x0, -0xc(%rbp)
jne 0x9b65
movq -0xa8(%rbp), %rdi
callq 0x7b10
movl %eax, -0xc(%rbp)
jmp 0x9b7b
movl -0xac(%rbp), %esi
leaq -0xa0(%rbp), %rdi
xorl %edx, %edx
callq 0x6140
jmp 0x9b7d
jmp 0x9b7f
movl -0xc(%rbp), %eax
addq $0x520, %rsp            # imm = 0x520
popq %rbp
retq
nopl (%rax,%rax)