// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x2
popq %r15
movq %rax, %rdi
movl %r15d, %edx
callq 0x1480
movl %eax, %r12d
testl %eax, %eax
jne 0x351a
movq -0x40(%rbp), %rbx
leaq -0x98(%rbp), %rdi
movq %rbx, (%rdi)
movq -0x48(%rbp), %rsi
callq 0x1a6d
testl %eax, %eax
pushq $0x8
popq %r12
cmovnel %eax, %r12d
cmpl $0x4, %r12d
jne 0x351a
xorl %r13d, %r13d
leaq -0x98(%rbp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x2595
movq %rax, %r14
movzwl 0xa(%rbx), %eax
shll $0x9, %eax
movq %rax, 0x18(%r12)
testq %r14, %r14
pushq $0x7
popq %r12
cmovnel %r13d, %r12d
cmpq $0x1, %r14
cmovel %r15d, %r12d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %r14
pushq $0x1
popq %r13
cmovel %r13d, %r12d
testl %r12d, %r12d
jne 0x344a
movq %rbx, %rdi
callq 0x357b
movl %eax, %r12d
callq 0x13c3
testl %r12d, %r12d
jne 0x3509
movq %rax, %r15
movq %rbx, %rdi
movq %r14, %rsi
callq 0x35f1
movl %r13d, %r12d
testl %eax, %eax
jne 0x3509
leaq 0x58(%rbx), %r12
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rax, 0x59(%rbx)
movw $0x2020, 0x61(%rbx)     # imm = 0x2020
movb $0x2e, %al
movb %al, 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)
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1dc1
leaq 0x78(%rbx), %r13
pushq $0x20
popq %rdx
movq %r13, %rdi
movq %r12, %rsi
callq 0x22ea
movb $0x2e, %al
movb %al, 0x79(%rbx)
leaq -0x98(%rbp), %r12
movq 0x10(%r12), %rdx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1dc1
movb $0x1, 0x3(%rbx)
movq %r12, %rdi
callq 0x1d24
movl %eax, %r12d
testl %eax, %eax
je 0x352c
leaq -0x98(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x1dde
movl %r12d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x60(%rbp), %r12
movb %r15b, 0x16(%r12)
movl -0x34(%rbp), %eax
movb %al, 0x17(%r12)
movl -0x30(%rbp), %eax
movb %al, 0x18(%r12)
movl -0x2c(%rbp), %eax
movb %al, 0x19(%r12)
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1dc1
movb $0x10, 0xb(%r12)
movb $0x1, 0x3(%rbx)
movq %rbx, %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x281f