#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;

/* Variables and functions */
int /*<<< orphan*/ SectorError(char *, ...);
int mdv_csum(int *, int);
scalar_t__ memcmp(int *, char *, int);
void mdv_check_header(uint8_t *buf, uint8_t sec) {
  if (buf[0] != 1)
    SectorError("Bad header type: %d", buf[0]);
  if (buf[1] != sec)
    SectorError("Bad header block number: %d", buf[1]);
  if (memcmp(buf + 4, "FUZIX     ", 10))
    SectorError("Bad header magic");
  if (buf[14] != mdv_csum(buf, 14))
    SectorError("Bad header checksum %02x %02x\n", buf[14], mdv_csum(buf, 14));
}


x86 assembly (clang, -O0):
<mdv_check_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0x1,(%rax)
je     1160 <mdv_check_header+0x30>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1050 <SectorError@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
cmp    -0xc(%rbp),%eax
je     1185 <mdv_check_header+0x55>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1050 <SectorError@plt>
mov    -0x8(%rbp),%rdi
add    $0x10,%rdi
lea    0xe9c(%rip),%rsi
mov    $0xa,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
je     11b6 <mdv_check_header+0x86>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1050 <SectorError@plt>
mov    -0x8(%rbp),%rax
mov    0x38(%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0xe,%esi
call   1040 <mdv_csum@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
je     1206 <mdv_check_header+0xd6>
mov    -0x8(%rbp),%rax
mov    0x38(%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0xe,%esi
call   1040 <mdv_csum@plt>
mov    -0x14(%rbp),%esi
mov    %eax,%edx
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1050 <SectorError@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mdv_check_header>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    (%rdi),%esi
cmp    $0x1,%esi
je     114d <mdv_check_header+0x1d>
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1050 <SectorError@plt>
mov    0x4(%rbx),%esi
cmp    %ebp,%esi
je     1162 <mdv_check_header+0x32>
lea    0xeb9(%rip),%rdi
xor    %eax,%eax
call   1050 <SectorError@plt>
lea    0x10(%rbx),%rdi
lea    0xec3(%rip),%rsi
mov    $0xa,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     118a <mdv_check_header+0x5a>
lea    0xeb8(%rip),%rdi
xor    %eax,%eax
call   1050 <SectorError@plt>
mov    0x38(%rbx),%ebp
mov    %rbx,%rdi
mov    $0xe,%esi
call   1040 <mdv_csum@plt>
cmp    %eax,%ebp
jne    11a5 <mdv_check_header+0x75>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x38(%rbx),%ebp
mov    %rbx,%rdi
mov    $0xe,%esi
call   1040 <mdv_csum@plt>
lea    0xe90(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <SectorError@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"Bad header type: %d\00"
@.str.1 = [28 x i8] c"Bad header block number: %d\00"
@.str.2 = [11 x i8] c"FUZIX \00"
@.str.3 = [17 x i8] c"Bad header magic\00"
@.str.4 = [31 x i8] c"Bad header checksum %02x %02x\0A\00"
define void @mdv_check_header(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%5 = load i32*, i32** %3
%6 = getelementptr inbounds i32, i32* %5, i64 0
%7 = load i32, i32* %6
%8 = icmp ne i32 %7, 1
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i32*, i32** %3
%11 = getelementptr inbounds i32, i32* %10, i64 0
%12 = load i32, i32* %11
%13 = call i32 (i8*, ...) @SectorError(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %9, %2
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 1
%17 = load i32, i32* %16
%18 = load i32, i32* %4
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %25
20: ; preds = %14
%21 = load i32*, i32** %3
%22 = getelementptr inbounds i32, i32* %21, i64 1
%23 = load i32, i32* %22
%24 = call i32 (i8*, ...) @SectorError(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %20, %14
%26 = load i32*, i32** %3
%27 = getelementptr inbounds i32, i32* %26, i64 4
%28 = call i64 @memcmp(i32* %27, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 10)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 (i8*, ...) @SectorError(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %25
%33 = load i32*, i32** %3
%34 = getelementptr inbounds i32, i32* %33, i64 14
%35 = load i32, i32* %34
%36 = load i32*, i32** %3
%37 = call i32 @mdv_csum(i32* %36, i32 14)
%38 = icmp ne i32 %35, %37
br i1 %38, label %39, label %46
39: ; preds = %32
%40 = load i32*, i32** %3
%41 = getelementptr inbounds i32, i32* %40, i64 14
%42 = load i32, i32* %41
%43 = load i32*, i32** %3
%44 = call i32 @mdv_csum(i32* %43, i32 14)
%45 = call i32 (i8*, ...) @SectorError(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %42, i32 %44)
br label %46
46: ; preds = %39, %32
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"Bad header type: %d\00"
@.str.1 = [28 x i8] c"Bad header block number: %d\00"
@.str.2 = [11 x i8] c"FUZIX \00"
@.str.3 = [17 x i8] c"Bad header magic\00"
@.str.4 = [31 x i8] c"Bad header checksum %02x %02x\0A\00"
define void @mdv_check_header(i32* %0, i32 %1) {
%3 = load i32, i32* %0
%4 = icmp eq i32 %3, 1
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 (i8*, ...) @SectorError(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %7
7: ; preds = %5, %2
%8 = getelementptr inbounds i32, i32* %0, i64 1
%9 = load i32, i32* %8
%10 = icmp eq i32 %9, %1
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = tail call i32 (i8*, ...) @SectorError(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %13
13: ; preds = %11, %7
%14 = getelementptr inbounds i32, i32* %0, i64 4
%15 = tail call i64 @memcmp(i32* %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 10)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = tail call i32 (i8*, ...) @SectorError(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %19
19: ; preds = %17, %13
%20 = getelementptr inbounds i32, i32* %0, i64 14
%21 = load i32, i32* %20
%22 = tail call i32 @mdv_csum(i32* %0, i32 14)
%23 = icmp eq i32 %21, %22
br i1 %23, label %28, label %24
24: ; preds = %19
%25 = load i32, i32* %20
%26 = tail call i32 @mdv_csum(i32* %0, i32 14)
%27 = tail call i32 (i8*, ...) @SectorError(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %25, i32 %26)
br label %28
28: ; preds = %24, %19
ret void
}