// File: /workspace/github_c_makefile_star2_O1/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 %r12
pushq %rbx
subq $0x60, %rsp
leaq -0x30(%rbp), %rax
movq %rdi, (%rax)
leaq -0x28(%rbp), %rsi
movq %rax, %rdi
movl $0x2, %edx
callq 0x146e
movl %eax, %r14d
testl %eax, %eax
jne 0x3730
movq -0x28(%rbp), %rbx
leaq -0x80(%rbp), %rdi
movq %rbx, (%rdi)
movq -0x30(%rbp), %rsi
callq 0x1b33
testl %eax, %eax
movl $0x8, %r14d
cmovnel %eax, %r14d
cmpl $0x4, %r14d
jne 0x3730
xorl %r15d, %r15d
leaq -0x80(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x26c3
movzwl 0xa(%rbx), %ecx
shll $0x9, %ecx
movq %rcx, 0x18(%r14)
testq %rax, %rax
movl $0x7, %edx
cmovnel %r15d, %edx
cmpq $0x1, %rax
movl $0x2, %ecx
cmovnel %edx, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rax, %r15
cmpq %rdx, %rax
movl $0x1, %r14d
cmovnel %ecx, %r14d
testl %r14d, %r14d
jne 0x3648
movq %rbx, %rdi
callq 0x3796
movl %eax, %r14d
callq 0x13c7
movq %rax, %r12
testl %r14d, %r14d
movq %r15, %rdx
jne 0x3709
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x380f
movq %r15, %rdx
movl %eax, %r14d
testl %eax, %eax
jne 0x3709
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rax, 0x58(%rbx)
movl $0x20202020, 0x5f(%rbx) # imm = 0x20202020
movb $0x2e, 0x58(%rbx)
movb $0x10, 0x63(%rbx)
movq %r12, %rcx
movb %cl, 0x6e(%rbx)
movb %ch, 0x6f(%rbx)
movl %ecx, %eax
shrl $0x10, %eax
movb %al, 0x70(%rbx)
movl %ecx, %eax
shrl $0x18, %eax
movb %al, 0x71(%rbx)
movb %dl, 0x72(%rbx)
movb %dh, 0x73(%rbx)
cmpb $0x3, (%rbx)
jne 0x36c6
movl %edx, %eax
shrl $0x10, %eax
movb %al, 0x6c(%rbx)
movl %edx, %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 0x36cb
movb $0x2e, 0x79(%rbx)
movq -0x70(%rbp), %rax
movw %ax, 0x92(%rbx)
cmpb $0x3, (%rbx)
jne 0x3702
movl %eax, %ecx
shrl $0x10, %ecx
movb %cl, 0x8c(%rbx)
shrl $0x18, %eax
movb %al, 0x8d(%rbx)
movb $0x1, 0x3(%rbx)
xorl %r14d, %r14d
testl %r14d, %r14d
jne 0x371d
leaq -0x80(%rbp), %rdi
callq 0x1e2c
movq %r15, %rdx
movl %eax, %r14d
testl %r14d, %r14d
je 0x3740
leaq -0x80(%rbp), %rdi
movq %rdx, %rsi
xorl %edx, %edx
callq 0x1ec8
movl %r14d, %eax
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq -0x48(%rbp), %rax
movq %rdx, %rsi
movq %r12, %rdx
movb %dl, 0x16(%rax)
movb %dh, 0x17(%rax)
movl %edx, %ecx
shrl $0x10, %ecx
movb %cl, 0x18(%rax)
shrl $0x18, %edx
movb %dl, 0x19(%rax)
movq %rsi, %rdx
movb %dl, 0x1a(%rax)
movb %dh, 0x1b(%rax)
cmpb $0x3, (%rbx)
jne 0x377a
movl %edx, %ecx
shrl $0x10, %ecx
movb %cl, 0x14(%rax)
shrl $0x18, %edx
movb %dl, 0x15(%rax)
movb $0x10, 0xb(%rax)
movb $0x1, 0x3(%rbx)
movq %rbx, %rdi
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x2970