// File: /workspace/github_c_makefile_star2_O0/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
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq $0x0, -0xb8(%rbp)
leaq -0x8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
movl $0x2, %edx
callq 0x1770
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x4cb4
movq -0xc0(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x2440
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x4cb2
movzbl -0x15(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x4bb8
movl $0x6, -0xc(%rbp)
jmp 0x4bcd
movzbl -0x56(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x4bcb
movl $0x7, -0xc(%rbp)
jmp 0x4bcd
cmpl $0x0, -0xc(%rbp)
jne 0x4c60
movq -0xc0(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x2620
movq %rax, -0xb8(%rbp)
movzbl -0x56(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x4c5e
movq -0xc0(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0xb0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4020
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x4c5c
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
callq 0x42a0
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x4c4d
movl $0x7, -0xc(%rbp)
cmpl $0x4, -0xc(%rbp)
jne 0x4c5a
movl $0x0, -0xc(%rbp)
jmp 0x4c5c
jmp 0x4c5e
jmp 0x4c60
cmpl $0x0, -0xc(%rbp)
jne 0x4cb0
leaq -0x60(%rbp), %rdi
callq 0x4cc0
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x4c99
cmpq $0x0, -0xb8(%rbp)
je 0x4c99
leaq -0x60(%rbp), %rdi
movq -0xb8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x2770
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x4cae
movq -0xc0(%rbp), %rdi
callq 0x39b0
movl %eax, -0xc(%rbp)
jmp 0x4cb0
jmp 0x4cb2
jmp 0x4cb4
movl -0xc(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq