// File: /workspace/github_c_makefile_star2_O3/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 %r12
pushq %rbx
subq $0xb0, %rsp
leaq -0x30(%rbp), %rax
movq %rdi, (%rax)
leaq -0x28(%rbp), %rsi
movq %rax, %rdi
movl $0x2, %edx
callq 0x144b
testl %eax, %eax
jne 0x347f
movq -0x28(%rbp), %rbx
leaq -0x80(%rbp), %rdi
movq %rbx, (%rdi)
movq -0x30(%rbp), %rsi
callq 0x1b32
testl %eax, %eax
je 0x348f
addq $0xb0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, -0x35(%rbp)
js 0x350e
movb -0x76(%rbp), %cl
movl $0x7, %eax
testb $0x1, %cl
jne 0x347f
movq -0x48(%rbp), %r12
movzwl 0x1a(%r12), %r14d
cmpb $0x3, (%rbx)
jne 0x34bd
movzwl 0x14(%r12), %eax
shll $0x10, %eax
orq %rax, %r14
testb $0x10, %cl
jne 0x3518
movq -0x80(%rbp), %r15
movq -0x50(%rbp), %rsi
movq %r15, %rdi
callq 0x1f5d
testl %eax, %eax
jne 0x347f
movb $-0x1b, (%r12)
movb $0x1, 0x3(%r15)
testq %r14, %r14
je 0x34f7
leaq -0x80(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x1eb2
testl %eax, %eax
jne 0x347f
movq %rbx, %rdi
addq $0xb0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x2952
movl $0x6, %eax
jmp 0x347f
leaq -0xd0(%rbp), %rdi
movq %rbx, (%rdi)
movq %r14, 0x10(%rdi)
callq 0x2d33
testl %eax, %eax
jne 0x347f
leaq -0xd0(%rbp), %rdi
callq 0x2e95
movl %eax, %ecx
testl %eax, %eax
movl $0x7, %eax
cmovnel %ecx, %eax
cmpl $0x4, %eax
jne 0x347f
jmp 0x34c2