// File: /workspace/github_c_makefile_star2_O2/lb3361[P]dosfs/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 = mount_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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x560, %rsp            # imm = 0x560
leaq 0x8(%rsp), %rax
movq %rdi, (%rax)
movq %rsp, %rsi
pushq $0x2
popq %rdx
movq %rax, %rdi
callq 0x473a
testl %eax, %eax
jne 0x79de
movq (%rsp), %rbx
leaq 0xa0(%rsp), %rdi
movq %rbx, (%rdi)
leaq 0x100(%rsp), %rax
movq %rax, 0x10(%rbx)
leaq 0x300(%rsp), %rax
movq %rax, 0x18(%rbx)
movq 0x8(%rsp), %rsi
callq 0x50b1
testl %eax, %eax
jne 0x79de
cmpb $0x0, 0xf3(%rsp)
js 0x79d7
movb 0xaa(%rsp), %r12b
testb $0x1, %r12b
jne 0x79db
movq %rbx, 0x10(%rsp)
movb (%rbx), %r15b
cmpb $0x4, %r15b
jne 0x79ee
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x59a3
movl 0xc(%r14), %ebp
jmp 0x7a09
pushq $0x6
jmp 0x79dd
pushq $0x7
popq %rax
addq $0x560, %rsp            # imm = 0x560
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0xe0(%rsp), %rax
movzwl 0x1a(%rax), %ebp
cmpb $0x3, %r15b
jne 0x7a09
movzwl 0x14(%rax), %eax
shll $0x10, %eax
orl %eax, %ebp
testb $0x10, %r12b
jne 0x7a40
leaq 0xa0(%rsp), %rdi
callq 0x7a99
testl %eax, %eax
jne 0x7a32
testl %ebp, %ebp
je 0x7a32
leaq 0x10(%rsp), %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x5a5f
testl %eax, %eax
jne 0x79de
movq %rbx, %rdi
callq 0x68ea
jmp 0x79de
movq %rbx, 0x40(%rsp)
movl %ebp, 0x4c(%rsp)
cmpb $0x4, %r15b
jne 0x7a61
movq 0x20(%rsp), %rax
movq %rax, 0x50(%rsp)
movb 0x1b(%rsp), %al
movb %al, 0x4b(%rsp)
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x6d3b
testl %eax, %eax
jne 0x79de
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x6ee7
movl %eax, %ecx
testl %eax, %eax
pushq $0x7
popq %rax
cmovnel %ecx, %eax
cmpl $0x4, %eax
je 0x7a0f
jmp 0x79de