// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x570, %rsp            # imm = 0x570
movq %rdi, -0x8(%rbp)
movl $0x0, -0xd4(%rbp)
leaq -0x8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
movl $0x2, %edx
callq 0x4940
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x975c
movq -0xe0(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0x310(%rbp), %rcx
movq -0xe0(%rbp), %rax
movq %rcx, 0x10(%rax)
leaq -0x570(%rbp), %rcx
movq -0xe0(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x5910
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x975a
movzbl -0x1d(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x95fb
movl $0x6, -0xc(%rbp)
jmp 0x9610
movzbl -0x66(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x960e
movl $0x7, -0xc(%rbp)
jmp 0x9610
cmpl $0x0, -0xc(%rbp)
jne 0x9709
movq -0xe0(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0xe0(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x4, %eax
jne 0x9658
movq -0xe0(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x5f10
movl -0x104(%rbp), %eax
movl %eax, -0xd4(%rbp)
jmp 0x966e
movq -0xe0(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x63d0
movl %eax, -0xd4(%rbp)
movzbl -0x66(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x9707
movq -0xe0(%rbp), %rax
movq %rax, -0xd0(%rbp)
movl -0xd4(%rbp), %eax
movl %eax, -0xc4(%rbp)
movq -0xe0(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x4, %eax
jne 0x96c1
movq -0x100(%rbp), %rax
movq %rax, -0xc0(%rbp)
movb -0x105(%rbp), %al
movb %al, -0xc5(%rbp)
leaq -0xd0(%rbp), %rdi
xorl %esi, %esi
callq 0x82b0
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x9705
leaq -0xd0(%rbp), %rdi
xorl %esi, %esi
callq 0x8550
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x96f6
movl $0x7, -0xc(%rbp)
cmpl $0x4, -0xc(%rbp)
jne 0x9703
movl $0x0, -0xc(%rbp)
jmp 0x9705
jmp 0x9707
jmp 0x9709
cmpl $0x0, -0xc(%rbp)
jne 0x9758
leaq -0x70(%rbp), %rdi
callq 0x9770
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x9741
cmpl $0x0, -0xd4(%rbp)
je 0x9741
movl -0xd4(%rbp), %esi
leaq -0x110(%rbp), %rdi
xorl %edx, %edx
callq 0x6140
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x9756
movq -0xe0(%rbp), %rdi
callq 0x7b10
movl %eax, -0xc(%rbp)
jmp 0x9758
jmp 0x975a
jmp 0x975c
movl -0xc(%rbp), %eax
addq $0x570, %rsp            # imm = 0x570
popq %rbp
retq
nopl (%rax,%rax)