// File: /workspace/github_c_makefile_star2_O1/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: f_unlink
FRESULT f_unlink (
	const TCHAR* path		/* Pointer to the file or directory path */
)
{
	FRESULT res;
	DIR dj, sdj;
	DWORD dclst = 0;
	FATFS *fs;
#if FF_FS_EXFAT
	FFOBJID obj;
#endif
	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 (FF_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT)) {
			res = FR_INVALID_NAME;			/* Cannot remove dot entry */
		}
#if FF_FS_LOCK != 0
		if (res == FR_OK) res = chk_lock(&dj, 2);	/* Check if it is an open object */
#endif
		if (res == FR_OK) {					/* The object is accessible */
			if (dj.fn[NSFLAG] & NS_NONAME) {
				res = FR_INVALID_NAME;		/* Cannot remove the origin directory */
			} else {
				if (dj.obj.attr & AM_RDO) {
					res = FR_DENIED;		/* Cannot remove R/O object */
				}
			}
			if (res == FR_OK) {
#if FF_FS_EXFAT
				obj.fs = fs;
				if (fs->fs_type == FS_EXFAT) {
					init_alloc_info(fs, &obj);
					dclst = obj.sclust;
				} else
#endif
				{
					dclst = ld_clust(fs, dj.dir);
				}
				if (dj.obj.attr & AM_DIR) {			/* Is it a sub-directory? */
#if FF_FS_RPATH != 0
					if (dclst == fs->cdir) {		 	/* Is it the current directory? */
						res = FR_DENIED;
					} else
#endif
					{
						sdj.obj.fs = fs;				/* Open the sub-directory */
						sdj.obj.sclust = dclst;
#if FF_FS_EXFAT
						if (fs->fs_type == FS_EXFAT) {
							sdj.obj.objsize = obj.objsize;
							sdj.obj.stat = obj.stat;
						}
#endif
						res = dir_sdi(&sdj, 0);
						if (res == FR_OK) {
							res = dir_read_file(&sdj);			/* Test if the directory is empty */
							if (res == FR_OK) res = FR_DENIED;	/* Not empty? */
							if (res == FR_NO_FILE) res = FR_OK;	/* Empty? */
						}
					}
				}
			}
			if (res == FR_OK) {
				res = dir_remove(&dj);			/* Remove the directory entry */
				if (res == FR_OK && dclst != 0) {	/* Remove the cluster chain if exist */
#if FF_FS_EXFAT
					res = remove_chain(&obj, dclst, 0);
#else
					res = remove_chain(&dj.obj, dclst, 0);
#endif
				}
				if (res == FR_OK) res = sync_fs(fs);
			}
		}
		FREE_NAMBUF();
	}

	LEAVE_FF(fs, res);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0xb8, %rsp
leaq -0x28(%rbp), %rax
movq %rdi, (%rax)
leaq -0x20(%rbp), %rsi
movq %rax, %rdi
movl $0x2, %edx
callq 0x146e
testl %eax, %eax
jne 0x3570
movq -0x20(%rbp), %rbx
leaq -0x78(%rbp), %rdi
movq %rbx, (%rdi)
movq -0x28(%rbp), %rsi
callq 0x1b33
testl %eax, %eax
jne 0x3570
xorl %r14d, %r14d
testb $0x1, -0x6e(%rbp)
sete %cl
movl $0x7, %edx
cmovel %r14d, %edx
cmpb $0x0, -0x2d(%rbp)
setns %sil
movl $0x6, %eax
cmovnsl %edx, %eax
andb %cl, %sil
cmpb $0x1, %sil
jne 0x3531
movq -0x40(%rbp), %rax
movzwl 0x1a(%rax), %r14d
cmpb $0x3, (%rbx)
jne 0x34f4
movzbl 0x14(%rax), %ecx
movzbl 0x15(%rax), %eax
shll $0x18, %eax
shll $0x10, %ecx
orl %eax, %ecx
orq %rcx, %r14
xorl %eax, %eax
testb $0x10, -0x6e(%rbp)
je 0x3531
leaq -0xc8(%rbp), %rdi
movq %rbx, (%rdi)
movq %r14, 0x10(%rdi)
callq 0x2d55
testl %eax, %eax
jne 0x3531
leaq -0xc8(%rbp), %rdi
callq 0x2ec3
testl %eax, %eax
movl $0x7, %ecx
cmovnel %eax, %ecx
xorl %eax, %eax
cmpl $0x4, %ecx
cmovnel %ecx, %eax
testl %eax, %eax
jne 0x3570
movq -0x78(%rbp), %r15
movq -0x48(%rbp), %rsi
movq %r15, %rdi
callq 0x1f73
testl %eax, %eax
jne 0x3555
movq -0x40(%rbp), %rcx
movb $-0x1b, (%rcx)
movb $0x1, 0x3(%r15)
testl %eax, %eax
jne 0x356c
testq %r14, %r14
je 0x356c
leaq -0x78(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x1ec8
testl %eax, %eax
je 0x357e
addq $0xb8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
addq $0xb8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2970