#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int uint8_t;
typedef int uint32_t;
typedef int uint16_t;

/* Variables and functions */
int check_root_block(int);
int *read_block(int /*<<< orphan*/);
int /*<<< orphan*/ reset_cache();
bool fatfs_mount() {
  reset_cache();
  if (check_root_block(0))
    return true;
  uint8_t *data_block = read_block(0);
  if (!data_block || data_block[0x1fe] != 0x55 || data_block[0x1ff] != 0xaa)
    return false;
  if ((data_block[0x1be] & 0x7f) != 0)
    return false;
  uint32_t part_start = *(uint16_t *)(data_block + 0x1c6);
  part_start += (*(uint16_t *)(data_block + 0x1c8)) << 16;
  if (!part_start)
    return false;
  return check_root_block(part_start);
}


x86 assembly (clang, -O0):
<fatfs_mount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <reset_cache@plt>
xor    %edi,%edi
call   1030 <check_root_block@plt>
cmp    $0x0,%eax
je     115b <fatfs_mount+0x2b>
movl   $0x1,-0x4(%rbp)
jmp    1205 <fatfs_mount+0xd5>
xor    %edi,%edi
call   1050 <read_block@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1196 <fatfs_mount+0x66>
mov    -0x10(%rbp),%rax
cmpl   $0x55,0x7f8(%rax)
jne    1196 <fatfs_mount+0x66>
mov    -0x10(%rbp),%rax
cmpl   $0xaa,0x7fc(%rax)
je     11a2 <fatfs_mount+0x72>
movl   $0x0,-0x4(%rbp)
jmp    1205 <fatfs_mount+0xd5>
mov    -0x10(%rbp),%rax
mov    0x6f8(%rax),%eax
and    $0x7f,%eax
cmp    $0x0,%eax
je     11c4 <fatfs_mount+0x94>
movl   $0x0,-0x4(%rbp)
jmp    1205 <fatfs_mount+0xd5>
mov    -0x10(%rbp),%rax
mov    0x718(%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x720(%rax),%eax
shl    $0x10,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11fa <fatfs_mount+0xca>
movl   $0x0,-0x4(%rbp)
jmp    1205 <fatfs_mount+0xd5>
mov    -0x14(%rbp),%edi
call   1030 <check_root_block@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fatfs_mount>:
push   %rax
xor    %eax,%eax
call   1040 <reset_cache@plt>
xor    %edi,%edi
call   1030 <check_root_block@plt>
mov    $0x1,%ecx
test   %eax,%eax
jne    1174 <fatfs_mount+0x44>
xor    %edi,%edi
call   1050 <read_block@plt>
test   %rax,%rax
je     1172 <fatfs_mount+0x42>
cmpl   $0x55,0x7f8(%rax)
jne    1172 <fatfs_mount+0x42>
cmpl   $0xaa,0x7fc(%rax)
jne    1172 <fatfs_mount+0x42>
testb  $0x7f,0x6f8(%rax)
je     1178 <fatfs_mount+0x48>
xor    %ecx,%ecx
mov    %ecx,%eax
pop    %rcx
ret
mov    0x720(%rax),%edi
shl    $0x10,%edi
mov    $0x0,%ecx
add    0x718(%rax),%edi
je     1174 <fatfs_mount+0x44>
pop    %rax
jmp    1030 <check_root_block@plt>

LLVM IR (-O0):
define i32 @fatfs_mount() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = call i32 (...) @reset_cache()
%5 = call i32 @check_root_block(i32 0)
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %0
store i32 1, i32* %1
br label %46
8: ; preds = %0
%9 = call i32* @read_block(i32 0)
store i32* %9, i32** %2
%10 = load i32*, i32** %2
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = load i32*, i32** %2
%14 = getelementptr inbounds i32, i32* %13, i64 510
%15 = load i32, i32* %14
%16 = icmp ne i32 %15, 85
br i1 %16, label %22, label %17
17: ; preds = %12
%18 = load i32*, i32** %2
%19 = getelementptr inbounds i32, i32* %18, i64 511
%20 = load i32, i32* %19
%21 = icmp ne i32 %20, 170
br i1 %21, label %22, label %23
22: ; preds = %17, %12, %8
store i32 0, i32* %1
br label %46
23: ; preds = %17
%24 = load i32*, i32** %2
%25 = getelementptr inbounds i32, i32* %24, i64 446
%26 = load i32, i32* %25
%27 = and i32 %26, 127
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 0, i32* %1
br label %46
30: ; preds = %23
%31 = load i32*, i32** %2
%32 = getelementptr inbounds i32, i32* %31, i64 454
%33 = load i32, i32* %32
store i32 %33, i32* %3
%34 = load i32*, i32** %2
%35 = getelementptr inbounds i32, i32* %34, i64 456
%36 = load i32, i32* %35
%37 = shl i32 %36, 16
%38 = load i32, i32* %3
%39 = add nsw i32 %38, %37
store i32 %39, i32* %3
%40 = load i32, i32* %3
%41 = icmp ne i32 %40, 0
br i1 %41, label %43, label %42
42: ; preds = %30
store i32 0, i32* %1
br label %46
43: ; preds = %30
%44 = load i32, i32* %3
%45 = call i32 @check_root_block(i32 %44)
store i32 %45, i32* %1
br label %46
46: ; preds = %43, %42, %29, %22, %7
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
define i32 @fatfs_mount() {
%1 = tail call i32 (...) @reset_cache()
%2 = tail call i32 @check_root_block(i32 0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %30
4: ; preds = %0
%5 = tail call i32* @read_block(i32 0)
%6 = icmp eq i32* %5, null
br i1 %6, label %30, label %7
7: ; preds = %4
%8 = getelementptr inbounds i32, i32* %5, i64 510
%9 = load i32, i32* %8
%10 = icmp eq i32 %9, 85
br i1 %10, label %11, label %30
11: ; preds = %7
%12 = getelementptr inbounds i32, i32* %5, i64 511
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, 170
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = getelementptr inbounds i32, i32* %5, i64 446
%17 = load i32, i32* %16
%18 = and i32 %17, 127
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %30
20: ; preds = %15
%21 = getelementptr inbounds i32, i32* %5, i64 454
%22 = load i32, i32* %21
%23 = getelementptr inbounds i32, i32* %5, i64 456
%24 = load i32, i32* %23
%25 = shl i32 %24, 16
%26 = add nsw i32 %25, %22
%27 = icmp eq i32 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %20
%29 = tail call i32 @check_root_block(i32 %26)
br label %30
30: ; preds = %11, %7, %4, %15, %20, %28, %0
%31 = phi i32 [ 1, %0 ], [ 0, %11 ], [ 0, %7 ], [ 0, %4 ], [ 0, %15 ], [ %29, %28 ], [ 0, %20 ]
ret i32 %31
}