// File: /workspace/github_c_makefile_star2_O3/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 %rbx
subq $0x568, %rsp            # imm = 0x568
leaq 0x8(%rsp), %rax
movq %rdi, (%rax)
movq %rsp, %rsi
movq %rax, %rdi
movl $0x2, %edx
callq 0x4ada
testl %eax, %eax
jne 0x806b
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 0x554e
testl %eax, %eax
je 0x8079
addq $0x568, %rsp            # imm = 0x568
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0xf3(%rsp)
js 0x80dd
movb 0xaa(%rsp), %r15b
movl $0x7, %eax
testb $0x1, %r15b
jne 0x806b
movq %rbx, 0x10(%rsp)
movb (%rbx), %al
cmpb $0x4, %al
jne 0x80e4
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %r14
movq %r14, %rsi
callq 0x5ec9
movl 0xc(%r14), %ebp
testb $0x10, %r15b
je 0x8141
movq %rbx, 0x40(%rsp)
movl %ebp, 0x4c(%rsp)
movb 0x1b(%rsp), %al
movq 0x20(%rsp), %rcx
movq %rcx, 0x50(%rsp)
movb %al, 0x4b(%rsp)
jmp 0x810c
movl $0x6, %eax
jmp 0x806b
movq 0xe0(%rsp), %rcx
movzwl 0x1a(%rcx), %ebp
cmpb $0x3, %al
jne 0x80fd
movzwl 0x14(%rcx), %eax
shll $0x10, %eax
orl %eax, %ebp
testb $0x10, %r15b
je 0x8141
movq %rbx, 0x40(%rsp)
movl %ebp, 0x4c(%rsp)
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x72ea
testl %eax, %eax
jne 0x806b
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x74aa
movl %eax, %ecx
testl %eax, %eax
movl $0x7, %eax
cmovnel %ecx, %eax
cmpl $0x4, %eax
jne 0x806b
leaq 0xa0(%rsp), %rdi
callq 0x8179
testl %eax, %eax
jne 0x8164
testl %ebp, %ebp
je 0x8164
leaq 0x10(%rsp), %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x5f9a
testl %eax, %eax
jne 0x806b
movq %rbx, %rdi
callq 0x6ea3
jmp 0x806b