// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
leaq -0x48(%rbp), %rax
movq %rdi, (%rax)
leaq -0x40(%rbp), %rsi
movq %rax, %rdi
movl $0x2, %edx
callq 0x144b
movl %eax, %r12d
testl %eax, %eax
jne 0x371a
movq -0x40(%rbp), %rbx
leaq -0x98(%rbp), %rdi
movq %rbx, (%rdi)
movq -0x48(%rbp), %rsi
callq 0x1b32
testl %eax, %eax
movl $0x8, %r12d
cmovnel %eax, %r12d
cmpl $0x4, %r12d
jne 0x371a
xorl %r12d, %r12d
leaq -0x98(%rbp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x26be
movq %rax, %r14
movzwl 0xa(%rbx), %eax
shll $0x9, %eax
movq %rax, 0x18(%r15)
testq %r14, %r14
movl $0x7, %eax
cmovnel %r12d, %eax
cmpq $0x1, %r14
movl $0x2, %r15d
cmovnel %eax, %r15d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %r14
movl $0x1, %r12d
cmovel %r12d, %r15d
testl %r15d, %r15d
je 0x361a
callq 0x13c5
movl %r15d, %r12d
jmp 0x3709
movq %rbx, %rdi
callq 0x3782
movl %eax, %r13d
callq 0x13c5
testl %r13d, %r13d
jne 0x3709
movq %rax, %r15
movq %rbx, %rdi
movq %r14, %rsi
callq 0x37fb
testl %eax, %eax
jne 0x3709
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rax, 0x59(%rbx)
movw $0x2020, 0x61(%rbx)     # imm = 0x2020
movb $0x2e, 0x58(%rbx)
movb $0x10, 0x63(%rbx)
movb %r15b, 0x6e(%rbx)
movl %r15d, %eax
shrl $0x8, %eax
movl %eax, -0x34(%rbp)
movb %al, 0x6f(%rbx)
movl %r15d, %eax
shrl $0x10, %eax
movl %eax, -0x30(%rbp)
movb %al, 0x70(%rbx)
movl %r15d, %eax
shrl $0x18, %eax
movl %eax, -0x2c(%rbp)
movb %al, 0x71(%rbx)
movb %r14b, 0x72(%rbx)
movl %r14d, %r13d
shrl $0x8, %r13d
movb %r13b, 0x73(%rbx)
cmpb $0x3, (%rbx)
jne 0x36b3
movl %r14d, %eax
shrl $0x10, %eax
movb %al, 0x6c(%rbx)
movl %r14d, %eax
shrl $0x18, %eax
movb %al, 0x6d(%rbx)
movl $0x58, %eax
movb (%rbx,%rax), %cl
movb %cl, 0x20(%rbx,%rax)
incq %rax
cmpl $0x78, %eax
jne 0x36b8
movb $0x2e, 0x79(%rbx)
movq -0x88(%rbp), %rax
movw %ax, 0x92(%rbx)
cmpb $0x3, (%rbx)
jne 0x36f2
movl %eax, %ecx
shrl $0x10, %ecx
movb %cl, 0x8c(%rbx)
shrl $0x18, %eax
movb %al, 0x8d(%rbx)
movb $0x1, 0x3(%rbx)
leaq -0x98(%rbp), %rdi
callq 0x1e19
movl %eax, %r12d
testl %eax, %eax
je 0x372c
leaq -0x98(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x1eb2
movl %r12d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x60(%rbp), %rax
movb %r15b, 0x16(%rax)
movl -0x34(%rbp), %ecx
movb %cl, 0x17(%rax)
movl -0x30(%rbp), %ecx
movb %cl, 0x18(%rax)
movl -0x2c(%rbp), %ecx
movb %cl, 0x19(%rax)
movb %r14b, 0x1a(%rax)
movb %r13b, 0x1b(%rax)
cmpb $0x3, (%rbx)
jne 0x3764
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)
movq %rbx, %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2952