// File: /workspace/github_c_makefile_star2_O0/lb3361[P]dosfs/ff.c
// Function: check_fs
static UINT check_fs (	/* 0:FAT VBR, 1:exFAT VBR, 2:Not FAT and valid BS, 3:Not FAT and invalid BS, 4:Disk error */
	FATFS* fs,			/* Filesystem object */
	LBA_t sect			/* Sector to load and check if it is an FAT-VBR or not */
)
{
	WORD w, sign;
	BYTE b;


	fs->wflag = 0; fs->winsect = (LBA_t)0 - 1;		/* Invaidate window */
	if (move_window(fs, sect) != FR_OK) return 4;	/* Load the boot sector */
	sign = ld_word(fs->win + BS_55AA);
#if FF_FS_EXFAT
	if (sign == 0xAA55 && !mem_cmp(fs->win + BS_JmpBoot, "\xEB\x76\x90" "EXFAT   ", 11)) return 1;	/* It is an exFAT VBR */
#endif
	b = fs->win[BS_JmpBoot];
	if (b == 0xEB || b == 0xE9 || b == 0xE8) {	/* Valid JumpBoot code? (short jump, near jump or near call) */
		if (sign == 0xAA55 && !mem_cmp(fs->win + BS_FilSysType32, "FAT32   ", 8)) return 0;	/* It is an FAT32 VBR */
		/* FAT volumes formatted with early MS-DOS lack boot signature and FAT string, so that we need to identify the FAT VBR without them. */
		w = ld_word(fs->win + BPB_BytsPerSec);
		if ((w & (w - 1)) == 0 && w >= FF_MIN_SS && w <= FF_MAX_SS) {	/* Properness of sector size */
			b = fs->win[BPB_SecPerClus];
			if (b != 0 && (b & (b - 1)) == 0						/* Properness of cluster size */
			&& (fs->win[BPB_NumFATs] == 1 || fs->win[BPB_NumFATs] == 2)	/* Properness of number of FATs */
			&& ld_word(fs->win + BPB_RootEntCnt) != 0				/* Properness of root entry count */
			&& ld_word(fs->win + BPB_FATSz16) != 0) {				/* Properness of FAT size */
				return 0;	/* Sector can be presumed an FAT VBR */
			}
		}
	}
	return sign == 0xAA55 ? 2 : 3;	/* Not an FAT VBR (valid or invalid BS) */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movb $0x0, 0x3(%rax)
movq -0x10(%rbp), %rax
movq $-0x1, 0x58(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6480
cmpl $0x0, %eax
je 0xe122
movl $0x4, -0x4(%rbp)
jmp 0xe2b4
movq -0x10(%rbp), %rdi
addq $0x60, %rdi
addq $0x1fe, %rdi            # imm = 0x1FE
callq 0x9390
movw %ax, -0x1c(%rbp)
movzwl -0x1c(%rbp), %eax
cmpl $0xaa55, %eax           # imm = 0xAA55
jne 0xe16f
movq -0x10(%rbp), %rdi
addq $0x60, %rdi
leaq 0x43ac(%rip), %rsi      # 0x12500
movl $0xb, %edx
callq 0xd440
cmpl $0x0, %eax
jne 0xe16f
movl $0x1, -0x4(%rbp)
jmp 0xe2b4
movq -0x10(%rbp), %rax
movb 0x60(%rax), %al
movb %al, -0x1d(%rbp)
movzbl -0x1d(%rbp), %eax
cmpl $0xeb, %eax
je 0xe19e
movzbl -0x1d(%rbp), %eax
cmpl $0xe9, %eax
je 0xe19e
movzbl -0x1d(%rbp), %eax
cmpl $0xe8, %eax
jne 0xe29a
movzwl -0x1c(%rbp), %eax
cmpl $0xaa55, %eax           # imm = 0xAA55
jne 0xe1d7
movq -0x10(%rbp), %rdi
addq $0x60, %rdi
addq $0x52, %rdi
leaq 0x4367(%rip), %rsi      # 0x12523
movl $0x8, %edx
callq 0xd440
cmpl $0x0, %eax
jne 0xe1d7
movl $0x0, -0x4(%rbp)
jmp 0xe2b4
movq -0x10(%rbp), %rdi
addq $0x60, %rdi
addq $0xb, %rdi
callq 0x9390
movw %ax, -0x1a(%rbp)
movzwl -0x1a(%rbp), %eax
movzwl -0x1a(%rbp), %ecx
subl $0x1, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
jne 0xe298
movzwl -0x1a(%rbp), %eax
cmpl $0x200, %eax            # imm = 0x200
jl 0xe298
movzwl -0x1a(%rbp), %eax
cmpl $0x200, %eax            # imm = 0x200
jg 0xe298
movq -0x10(%rbp), %rax
movb 0x6d(%rax), %al
movb %al, -0x1d(%rbp)
movzbl -0x1d(%rbp), %eax
cmpl $0x0, %eax
je 0xe296
movzbl -0x1d(%rbp), %eax
movzbl -0x1d(%rbp), %ecx
subl $0x1, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
jne 0xe296
movq -0x10(%rbp), %rax
movzbl 0x70(%rax), %eax
cmpl $0x1, %eax
je 0xe25b
movq -0x10(%rbp), %rax
movzbl 0x70(%rax), %eax
cmpl $0x2, %eax
jne 0xe296
movq -0x10(%rbp), %rdi
addq $0x60, %rdi
addq $0x11, %rdi
callq 0x9390
movzwl %ax, %eax
cmpl $0x0, %eax
je 0xe296
movq -0x10(%rbp), %rdi
addq $0x60, %rdi
addq $0x16, %rdi
callq 0x9390
movzwl %ax, %eax
cmpl $0x0, %eax
je 0xe296
movl $0x0, -0x4(%rbp)
jmp 0xe2b4
jmp 0xe298
jmp 0xe29a
movzwl -0x1c(%rbp), %edx
movl $0x3, %eax
movl $0x2, %ecx
cmpl $0xaa55, %edx           # imm = 0xAA55
cmovel %ecx, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)