// File: /workspace/github_c_makefile_star2_O1/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:
movl $0x2, %eax
cmpl $0x2, %esi
jb 0xbb17
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %esi, %r14d
movq %rdi, %rbx
cmpl %esi, 0x28(%rdi)
jbe 0xbb0f
movl %edx, %ebp
movzbl (%rbx), %ecx
leal -0x3(%rcx), %edx
cmpl $0x2, %edx
jb 0xba9e
cmpl $0x2, %ecx
je 0xbadd
cmpl $0x1, %ecx
jne 0xbb0f
movl %r14d, %r12d
shrl %r12d
addl %r14d, %r12d
movl %r12d, %esi
shrl $0x9, %esi
addq 0x38(%rbx), %rsi
movq %rbx, %rdi
callq 0x6314
testl %eax, %eax
jne 0xbb0f
leal 0x1(%r12), %r15d
andl $0x1ff, %r12d           # imm = 0x1FF
movl %ebp, %eax
testb $0x1, %r14b
je 0xba5b
movzbl 0x60(%rbx,%r12), %ecx
andl $0xf, %ecx
movzbl %bpl, %eax
shll $0x4, %eax
orl %ecx, %eax
movb %al, 0x60(%rbx,%r12)
movb $0x1, 0x3(%rbx)
movl %r15d, %esi
shrl $0x9, %esi
addq 0x38(%rbx), %rsi
movq %rbx, %rdi
callq 0x6314
testl %eax, %eax
jne 0xbb0f
andl $0x1ff, %r15d           # imm = 0x1FF
testb $0x1, %r14b
jne 0xbafe
movzbl 0x60(%rbx,%r15), %eax
andl $-0x10, %eax
shrl $0x8, %ebp
andl $0xf, %ebp
orl %eax, %ebp
jmp 0xbb01
movl %r14d, %esi
shrl $0x7, %esi
addq 0x38(%rbx), %rsi
movq %rbx, %rdi
callq 0x6314
testl %eax, %eax
jne 0xbb0f
cmpb $0x4, (%rbx)
je 0xbad2
andl $0xfffffff, %ebp        # imm = 0xFFFFFFF
movl %r14d, %eax
andl $0x7f, %eax
movzbl 0x63(%rbx,%rax,4), %eax
andl $-0x10, %eax
shll $0x18, %eax
orl %eax, %ebp
andl $0x7f, %r14d
movl %ebp, 0x60(%rbx,%r14,4)
jmp 0xbb06
movl %r14d, %esi
shrl $0x8, %esi
addq 0x38(%rbx), %rsi
movq %rbx, %rdi
callq 0x6314
testl %eax, %eax
jne 0xbb0f
movzbl %r14b, %eax
movw %bp, 0x60(%rbx,%rax,2)
jmp 0xbb06
shrl $0x4, %ebp
movb %bpl, 0x60(%rbx,%r15)
addq $0x3, %rbx
movb $0x1, (%rbx)
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq