// File: /workspace/github_c_makefile_star2_O0/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: f_mkdir
FRESULT f_mkdir (
	const TCHAR* path		/* Pointer to the directory path */
)
{
	FRESULT res;
	DIR dj;
	FATFS *fs;
	BYTE *dir;
	DWORD dcl, pcl, tm;
	DEF_NAMBUF


	/* Get logical drive */
	res = find_volume(&path, &fs, FA_WRITE);
	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;		/* Any object with same name is already existing */
		if (FF_FS_RPATH && res == FR_NO_FILE && (dj.fn[NSFLAG] & NS_DOT)) {
			res = FR_INVALID_NAME;
		}
		if (res == FR_NO_FILE) {				/* Can create a new directory */
			dcl = create_chain(&dj.obj, 0);		/* Allocate a cluster for the new directory table */
			dj.obj.objsize = (DWORD)fs->csize * SS(fs);
			res = FR_OK;
			if (dcl == 0) res = FR_DENIED;		/* No space to allocate a new cluster */
			if (dcl == 1) res = FR_INT_ERR;
			if (dcl == 0xFFFFFFFF) res = FR_DISK_ERR;
			if (res == FR_OK) res = sync_window(fs);	/* Flush FAT */
			tm = GET_FATTIME();
			if (res == FR_OK) {					/* Initialize the new directory table */
				res = dir_clear(fs, dcl);		/* Clean up the new table */
				if (res == FR_OK && (!FF_FS_EXFAT || fs->fs_type != FS_EXFAT)) {	/* Create dot entries (FAT only) */
					dir = fs->win;
					mem_set(dir + DIR_Name, ' ', 11);	/* Create "." entry */
					dir[DIR_Name] = '.';
					dir[DIR_Attr] = AM_DIR;
					st_dword(dir + DIR_ModTime, tm);
					st_clust(fs, dir, dcl);
					mem_cpy(dir + SZDIRE, dir, SZDIRE); /* Create ".." entry */
					dir[SZDIRE + 1] = '.'; pcl = dj.obj.sclust;
					st_clust(fs, dir + SZDIRE, pcl);
					fs->wflag = 1;
				}
			}
			if (res == FR_OK) {
				res = dir_register(&dj);	/* Register the object to the 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)dj.obj.objsize);	/* File size needs to be valid */
					st_dword(fs->dirbuf + XDIR_ValidFileSize, (DWORD)dj.obj.objsize);
					fs->dirbuf[XDIR_GenFlags] = 3;				/* Initialize the object flag */
					fs->dirbuf[XDIR_Attr] = AM_DIR;				/* Attribute */
					res = store_xdir(&dj);
				} else
#endif
				{
					dir = dj.dir;
					st_dword(dir + DIR_ModTime, tm);	/* Created time */
					st_clust(fs, dir, dcl);				/* Table start cluster */
					dir[DIR_Attr] = AM_DIR;				/* Attribute */
					fs->wflag = 1;
				}
				if (res == FR_OK) {
					res = sync_fs(fs);
				}
			} else {
				remove_chain(&dj.obj, dcl, 0);		/* Could not register, remove cluster chain */
			}
		}
		FREE_NAMBUF();
	}

	LEAVE_FF(fs, res);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
leaq -0x8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
movl $0x2, %edx
callq 0x1770
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x4f1b
movq -0x68(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x2440
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x4d63
movl $0x8, -0xc(%rbp)
cmpl $0x4, -0xc(%rbp)
jne 0x4f19
leaq -0x60(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3540
movq %rax, -0x78(%rbp)
movq -0x68(%rbp), %rax
movzwl 0xa(%rax), %eax
shlq $0x9, %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0xc(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x4da3
movl $0x7, -0xc(%rbp)
cmpq $0x1, -0x78(%rbp)
jne 0x4db1
movl $0x2, -0xc(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x78(%rbp)
jne 0x4dc3
movl $0x1, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x4dd5
movq -0x68(%rbp), %rdi
callq 0x4f30
movl %eax, -0xc(%rbp)
callq 0x15c0
movq %rax, -0x88(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x4e9d
movq -0x68(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x4ff0
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x4e9b
movq -0x68(%rbp), %rax
addq $0x58, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
movl $0x20, %esi
movl $0xb, %edx
callq 0x29a0
movq -0x70(%rbp), %rax
movb $0x2e, (%rax)
movq -0x70(%rbp), %rax
movb $0x10, 0xb(%rax)
movq -0x70(%rbp), %rdi
addq $0x16, %rdi
movq -0x88(%rbp), %rsi
callq 0x2680
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq -0x78(%rbp), %rdx
callq 0x2710
movq -0x70(%rbp), %rdi
addq $0x20, %rdi
movq -0x70(%rbp), %rsi
movl $0x20, %edx
callq 0x3090
movq -0x70(%rbp), %rax
movb $0x2e, 0x21(%rax)
movq -0x50(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rsi
addq $0x20, %rsi
movq -0x80(%rbp), %rdx
callq 0x2710
movq -0x68(%rbp), %rax
movb $0x1, 0x3(%rax)
jmp 0x4e9d
cmpl $0x0, -0xc(%rbp)
jne 0x4eaf
leaq -0x60(%rbp), %rdi
callq 0x2590
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x4f06
movq -0x28(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
addq $0x16, %rdi
movq -0x88(%rbp), %rsi
callq 0x2680
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq -0x78(%rbp), %rdx
callq 0x2710
movq -0x70(%rbp), %rax
movb $0x10, 0xb(%rax)
movq -0x68(%rbp), %rax
movb $0x1, 0x3(%rax)
cmpl $0x0, -0xc(%rbp)
jne 0x4f04
movq -0x68(%rbp), %rdi
callq 0x39b0
movl %eax, -0xc(%rbp)
jmp 0x4f17
leaq -0x60(%rbp), %rdi
movq -0x78(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x2770
jmp 0x4f19
jmp 0x4f1b
movl -0xc(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)