// File: /workspace/github_c_makefile_star2_O0/lb3361[P]dosfs/ff.c
// Function: put_fat
static FRESULT put_fat (	/* FR_OK(0):succeeded, !=0:error */
	FATFS* fs,		/* Corresponding filesystem object */
	DWORD clst,		/* FAT index number (cluster number) to be changed */
	DWORD val		/* New value to be set to the entry */
)
{
	UINT bc;
	BYTE *p;
	FRESULT res = FR_INT_ERR;


	if (clst >= 2 && clst < fs->n_fatent) {	/* Check if in valid range */
		switch (fs->fs_type) {
		case FS_FAT12:
			bc = (UINT)clst; bc += bc / 2;	/* bc: byte offset of the entry */
			res = move_window(fs, fs->fatbase + (bc / SS(fs)));
			if (res != FR_OK) break;
			p = fs->win + bc++ % SS(fs);
			*p = (clst & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val;		/* Update 1st byte */
			fs->wflag = 1;
			res = move_window(fs, fs->fatbase + (bc / SS(fs)));
			if (res != FR_OK) break;
			p = fs->win + bc % SS(fs);
			*p = (clst & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F));	/* Update 2nd byte */
			fs->wflag = 1;
			break;

		case FS_FAT16:
			res = move_window(fs, fs->fatbase + (clst / (SS(fs) / 2)));
			if (res != FR_OK) break;
			st_word(fs->win + clst * 2 % SS(fs), (WORD)val);	/* Simple WORD array */
			fs->wflag = 1;
			break;

		case FS_FAT32:
#if FF_FS_EXFAT
		case FS_EXFAT:
#endif
			res = move_window(fs, fs->fatbase + (clst / (SS(fs) / 4)));
			if (res != FR_OK) break;
			if (!FF_FS_EXFAT || fs->fs_type != FS_EXFAT) {
				val = (val & 0x0FFFFFFF) | (ld_dword(fs->win + clst * 4 % SS(fs)) & 0xF0000000);
			}
			st_dword(fs->win + clst * 4 % SS(fs), val);
			fs->wflag = 1;
			break;
		}
	}
	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl $0x2, -0x24(%rbp)
cmpl $0x2, -0xc(%rbp)
jb 0xf404
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jae 0xf404
movq -0x8(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x28(%rbp)
subl $0x1, %eax
je 0xf1e6
jmp 0xf1c4
movl -0x28(%rbp), %eax
subl $0x2, %eax
je 0xf316
jmp 0xf1d2
movl -0x28(%rbp), %eax
addl $-0x3, %eax
subl $0x2, %eax
jb 0xf36f
jmp 0xf402
movl -0xc(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
shrl %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rsi
movl -0x14(%rbp), %eax
shrl $0x9, %eax
movl %eax, %eax
addq %rax, %rsi
callq 0x6480
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0xf221
jmp 0xf402
movq -0x8(%rbp), %rax
addq $0x60, %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
andl $0x1ff, %ecx            # imm = 0x1FF
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movl -0xc(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xf268
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
andl $0xf, %eax
movl -0x10(%rbp), %ecx
movzbl %cl, %ecx
shll $0x4, %ecx
orl %ecx, %eax
movl %eax, -0x2c(%rbp)
jmp 0xf271
movl -0x10(%rbp), %eax
movzbl %al, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movq -0x8(%rbp), %rax
movb $0x1, 0x3(%rax)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rsi
movl -0x14(%rbp), %eax
shrl $0x9, %eax
movl %eax, %eax
addq %rax, %rsi
callq 0x6480
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0xf2ae
jmp 0xf402
movq -0x8(%rbp), %rax
addq $0x60, %rax
movl -0x14(%rbp), %ecx
andl $0x1ff, %ecx            # imm = 0x1FF
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movl -0xc(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xf2e1
movl -0x10(%rbp), %eax
shrl $0x4, %eax
movzbl %al, %eax
movl %eax, -0x30(%rbp)
jmp 0xf2fe
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
andl $0xf0, %eax
movl -0x10(%rbp), %ecx
shrl $0x8, %ecx
movzbl %cl, %ecx
andl $0xf, %ecx
orl %ecx, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movq -0x8(%rbp), %rax
movb $0x1, 0x3(%rax)
jmp 0xf402
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rsi
movl -0xc(%rbp), %eax
shrl $0x8, %eax
movl %eax, %eax
addq %rax, %rsi
callq 0x6480
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0xf340
jmp 0xf402
movq -0x8(%rbp), %rdi
addq $0x60, %rdi
movl -0xc(%rbp), %eax
shll %eax
andl $0x1ff, %eax            # imm = 0x1FF
movl %eax, %eax
addq %rax, %rdi
movl -0x10(%rbp), %eax
movzwl %ax, %esi
callq 0x7c50
movq -0x8(%rbp), %rax
movb $0x1, 0x3(%rax)
jmp 0xf402
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rsi
movl -0xc(%rbp), %eax
shrl $0x7, %eax
movl %eax, %eax
addq %rax, %rsi
callq 0x6480
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0xf396
jmp 0xf402
movq -0x8(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x4, %eax
je 0xf3da
movl -0x10(%rbp), %eax
andl $0xfffffff, %eax        # imm = 0xFFFFFFF
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
addq $0x60, %rdi
movl -0xc(%rbp), %eax
shll $0x2, %eax
andl $0x1ff, %eax            # imm = 0x1FF
movl %eax, %eax
addq %rax, %rdi
callq 0x6510
movl %eax, %ecx
movl -0x34(%rbp), %eax
andl $0xf0000000, %ecx       # imm = 0xF0000000
orl %ecx, %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
addq $0x60, %rdi
movl -0xc(%rbp), %eax
shll $0x2, %eax
andl $0x1ff, %eax            # imm = 0x1FF
movl %eax, %eax
addq %rax, %rdi
movl -0x10(%rbp), %esi
callq 0x5fc0
movq -0x8(%rbp), %rax
movb $0x1, 0x3(%rax)
jmp 0xf404
movl -0x24(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)