// File: /workspace/github_c_makefile_star2_O0/lb3361[P]dosfs/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);		/* Update start cluster */
						st_qword(fs->dirbuf + XDIR_FileSize, fp->obj.objsize);		/* Update file size */
						st_qword(fs->dirbuf + XDIR_ValidFileSize, fp->obj.objsize);	/* (FatFs does not support Valid File Size feature) */
						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 $0x4f0, %rsp            # imm = 0x4F0
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x6c70
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x780b
movq -0x10(%rbp), %rax
movzbl 0x30(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x7809
movq -0x10(%rbp), %rax
movzbl 0x30(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x75f2
movq -0x20(%rbp), %rax
movb 0x1(%rax), %al
movq -0x10(%rbp), %rsi
addq $0x60, %rsi
movq -0x10(%rbp), %rcx
movq 0x48(%rcx), %rdx
movl $0x1, %ecx
movzbl %al, %edi
callq 0x1a40
cmpl $0x0, %eax
je 0x75e4
movl $0x1, -0x4(%rbp)
jmp 0x7811
movq -0x10(%rbp), %rax
movzbl 0x30(%rax), %ecx
andl $0x7f, %ecx
movb %cl, 0x30(%rax)
callq 0x1be0
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x4, %eax
jne 0x775b
movq -0x10(%rbp), %rdi
callq 0x7820
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x7634
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x40(%rax), %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x78b0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x7756
leaq -0x290(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
leaq -0x4f0(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x7950
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x7754
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movzbl 0x4(%rax), %ecx
orl $0x20, %ecx
movb %cl, 0x4(%rax)
movq -0x10(%rbp), %rax
movzbl 0xb(%rax), %eax
orl $0x1, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movb %cl, 0x21(%rax)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
addq $0x34, %rdi
movq -0x10(%rbp), %rax
movl 0xc(%rax), %esi
callq 0x5fc0
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
addq $0x38, %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x79f0
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
addq $0x28, %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x79f0
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
addq $0xc, %rdi
movl -0x24(%rbp), %esi
callq 0x5fc0
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movb $0x0, 0x15(%rax)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
addq $0x10, %rdi
xorl %esi, %esi
callq 0x5fc0
leaq -0x90(%rbp), %rdi
callq 0x6040
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x7752
movq -0x20(%rbp), %rdi
callq 0x7b10
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x30(%rax), %ecx
andl $0xbf, %ecx
movb %cl, 0x30(%rax)
jmp 0x7754
jmp 0x7756
jmp 0x7807
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rsi
callq 0x6480
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x7805
movq -0x10(%rbp), %rax
movq 0x58(%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
movl 0xc(%rax), %edx
callq 0x6430
movq -0x30(%rbp), %rdi
addq $0x1c, %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %esi
callq 0x5fc0
movq -0x30(%rbp), %rdi
addq $0x16, %rdi
movl -0x24(%rbp), %esi
callq 0x5fc0
movq -0x30(%rbp), %rdi
addq $0x12, %rdi
xorl %esi, %esi
callq 0x7c50
movq -0x20(%rbp), %rax
movb $0x1, 0x3(%rax)
movq -0x20(%rbp), %rdi
callq 0x7b10
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x30(%rax), %ecx
andl $0xbf, %ecx
movb %cl, 0x30(%rax)
jmp 0x7807
jmp 0x7809
jmp 0x780b
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x4f0, %rsp            # imm = 0x4F0
popq %rbp
retq
nopl (%rax)