// File: /workspace/github_c_makefile_star2_O0/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: f_sync
FRESULT f_sync (
	FIL* fp		/* Pointer to the file object */
)
{
	FRESULT res;
	FATFS *fs;
	DWORD tm;
	BYTE *dir;


	res = validate(&fp->obj, &fs);	/* Check validity of the file object */
	if (res == FR_OK) {
		if (fp->flag & FA_MODIFIED) {	/* Is there any change to the file? */
#if !FF_FS_TINY
			if (fp->flag & FA_DIRTY) {	/* Write-back cached data if needed */
				if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) LEAVE_FF(fs, FR_DISK_ERR);
				fp->flag &= (BYTE)~FA_DIRTY;
			}
#endif
			/* Update the directory entry */
			tm = GET_FATTIME();				/* Modified time */
#if FF_FS_EXFAT
			if (fs->fs_type == FS_EXFAT) {
				res = fill_first_frag(&fp->obj);	/* Fill first fragment on the FAT if needed */
				if (res == FR_OK) {
					res = fill_last_frag(&fp->obj, fp->clust, 0xFFFFFFFF);	/* Fill last fragment on the FAT if needed */
				}
				if (res == FR_OK) {
					DIR dj;
					DEF_NAMBUF

					INIT_NAMBUF(fs);
					res = load_obj_xdir(&dj, &fp->obj);	/* Load directory entry block */
					if (res == FR_OK) {
						fs->dirbuf[XDIR_Attr] |= AM_ARC;				/* Set archive attribute to indicate that the file has been changed */
						fs->dirbuf[XDIR_GenFlags] = fp->obj.stat | 1;	/* Update file allocation information */
						st_dword(fs->dirbuf + XDIR_FstClus, fp->obj.sclust);
						st_qword(fs->dirbuf + XDIR_FileSize, fp->obj.objsize);
						st_qword(fs->dirbuf + XDIR_ValidFileSize, fp->obj.objsize);
						st_dword(fs->dirbuf + XDIR_ModTime, tm);		/* Update modified time */
						fs->dirbuf[XDIR_ModTime10] = 0;
						st_dword(fs->dirbuf + XDIR_AccTime, 0);
						res = store_xdir(&dj);	/* Restore it to the directory */
						if (res == FR_OK) {
							res = sync_fs(fs);
							fp->flag &= (BYTE)~FA_MODIFIED;
						}
					}
					FREE_NAMBUF();
				}
			} else
#endif
			{
				res = move_window(fs, fp->dir_sect);
				if (res == FR_OK) {
					dir = fp->dir_ptr;
					dir[DIR_Attr] |= AM_ARC;						/* Set archive attribute to indicate that the file has been changed */
					st_clust(fp->obj.fs, dir, fp->obj.sclust);		/* Update file allocation information  */
					st_dword(dir + DIR_FileSize, (DWORD)fp->obj.objsize);	/* Update file size */
					st_dword(dir + DIR_ModTime, tm);				/* Update modified time */
					st_word(dir + DIR_LstAccDate, 0);
					fs->wflag = 1;
					res = sync_fs(fs);					/* Restore it to the directory */
					fp->flag &= (BYTE)~FA_MODIFIED;
				}
			}
		}
	}

	LEAVE_FF(fs, res);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x2fe0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x3946
movq -0x10(%rbp), %rax
movzbl 0x20(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x3944
movq -0x10(%rbp), %rax
movzbl 0x20(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x388f
movq -0x20(%rbp), %rax
movb 0x1(%rax), %al
movq -0x10(%rbp), %rsi
addq $0x50, %rsi
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rdx
movl $0x1, %ecx
movzbl %al, %edi
callq 0x14c0
cmpl $0x0, %eax
je 0x3881
movl $0x1, -0x4(%rbp)
jmp 0x394c
movq -0x10(%rbp), %rax
movzbl 0x20(%rax), %ecx
andl $0x7f, %ecx
movb %cl, 0x20(%rax)
callq 0x15c0
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rsi
callq 0x28b0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x3942
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movzbl 0xb(%rax), %ecx
orl $0x20, %ecx
movb %cl, 0xb(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x30(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
callq 0x2710
movq -0x30(%rbp), %rdi
addq $0x1c, %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x2680
movq -0x30(%rbp), %rdi
addq $0x16, %rdi
movq -0x28(%rbp), %rsi
callq 0x2680
movq -0x30(%rbp), %rdi
addq $0x12, %rdi
xorl %esi, %esi
callq 0x3960
movq -0x20(%rbp), %rax
movb $0x1, 0x3(%rax)
movq -0x20(%rbp), %rdi
callq 0x39b0
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x20(%rax), %ecx
andl $0xbf, %ecx
movb %cl, 0x20(%rax)
jmp 0x3944
jmp 0x3946
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)