#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 /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int header_check(FILE *in) {
  char buf[4];
  size_t r = fread(buf, 1, sizeof(buf), in);
  if (r != sizeof(buf)) {
    do {
      fprintf(stderr, "could not read header");
      putc('\n', stderr);
    } while (0);
    return -1;
  }
  uint8_t major, minor, crypto, hash;
  major = buf[0];
  minor = buf[1];
  crypto = buf[2];
  hash = buf[3];
  if (major != 0 || minor != 0 || crypto != 0 || hash != 0) {
    do {
      fprintf(stderr, "Header had non-zero value? What?");
      putc('\n', stderr);
    } while (0);
    do {
      fprintf(stderr, "major: %d, minor: %d, crypto: %d, hash: %d\n", major,
              minor, crypto, hash);
      putc('\n', stderr);
    } while (0);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<header_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x4,-0x20(%rbp)
je     119d <header_check+0x6d>
jmp    1167 <header_check+0x37>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1040 <putc@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1260 <header_check+0x130>
movsbl -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
movsbl -0x13(%rbp),%eax
mov    %eax,-0x28(%rbp)
movsbl -0x12(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movsbl -0x11(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11e1 <header_check+0xb1>
cmpl   $0x0,-0x28(%rbp)
jne    11e1 <header_check+0xb1>
cmpl   $0x0,-0x2c(%rbp)
jne    11e1 <header_check+0xb1>
cmpl   $0x0,-0x30(%rbp)
je     1259 <header_check+0x129>
jmp    11e6 <header_check+0xb6>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1040 <putc@plt>
jmp    1215 <header_check+0xe5>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x30(%rbp),%r9d
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1040 <putc@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1260 <header_check+0x130>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<header_check>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rcx
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
cmp    $0x4,%rax
jne    11c8 <header_check+0x98>
movsbl 0xc(%rsp),%ebp
mov    0xd(%rsp),%cl
mov    0xe(%rsp),%dl
mov    0xf(%rsp),%bl
test   %ebp,%ebp
jne    117c <header_check+0x4c>
test   %cl,%cl
jne    117c <header_check+0x4c>
test   %dl,%dl
jne    117c <header_check+0x4c>
xor    %eax,%eax
test   %bl,%bl
je     11f7 <header_check+0xc7>
movsbl %cl,%r12d
movsbl %dl,%r14d
movsbl %bl,%r15d
mov    0x2e51(%rip),%rbx
mov    (%rbx),%edi
lea    0xe7e(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%esi
mov    $0xa,%edi
call   1040 <putc@plt>
mov    (%rbx),%edi
lea    0xe83(%rip),%rsi
mov    %ebp,%edx
mov    %r12d,%ecx
mov    %r14d,%r8d
mov    %r15d,%r9d
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11df <header_check+0xaf>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1040 <putc@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"could not read header\00"
@.str.1 = [33 x i8] c"Header had non-zero value? What?\00"
@.str.2 = [44 x i8] c"major: %d, minor: %d, crypto: %d, hash: %d\0A\00"
define i32 @header_check(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [4 x i8]
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %3
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%11 = load i32*, i32** %3
%12 = call i64 @fread(i8* %10, i32 1, i32 4, i32* %11)
store i64 %12, i64* %5
%13 = load i64, i64* %5
%14 = icmp ne i64 %13, 4
br i1 %14, label %15, label %22
15: ; preds = %1
br label %16
16: ; preds = %15
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @stderr
%20 = call i32 @putc(i8 signext 10, i32 %19)
br label %21
21: ; preds = %16
store i32 -1, i32* %2
br label %64
22: ; preds = %1
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
store i32 %25, i32* %6
%26 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
store i32 %28, i32* %7
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
store i32 %31, i32* %8
%32 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 3
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
store i32 %34, i32* %9
%35 = load i32, i32* %6
%36 = icmp ne i32 %35, 0
br i1 %36, label %46, label %37
37: ; preds = %22
%38 = load i32, i32* %7
%39 = icmp ne i32 %38, 0
br i1 %39, label %46, label %40
40: ; preds = %37
%41 = load i32, i32* %8
%42 = icmp ne i32 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %40
%44 = load i32, i32* %9
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %63
46: ; preds = %43, %40, %37, %22
br label %47
47: ; preds = %46
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%50 = load i32, i32* @stderr
%51 = call i32 @putc(i8 signext 10, i32 %50)
br label %52
52: ; preds = %47
br label %53
53: ; preds = %52
%54 = load i32, i32* @stderr
%55 = load i32, i32* %6
%56 = load i32, i32* %7
%57 = load i32, i32* %8
%58 = load i32, i32* %9
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %55, i32 %56, i32 %57, i32 %58)
%60 = load i32, i32* @stderr
%61 = call i32 @putc(i8 signext 10, i32 %60)
br label %62
62: ; preds = %53
store i32 -1, i32* %2
br label %64
63: ; preds = %43
store i32 0, i32* %2
br label %64
64: ; preds = %63, %62, %21
%65 = load i32, i32* %2
ret i32 %65
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"could not read header\00"
@.str.1 = [33 x i8] c"Header had non-zero value? What?\00"
@.str.2 = [44 x i8] c"major: %d, minor: %d, crypto: %d, hash: %d\0A\00"
define i32 @header_check(i32* nocapture %0) {
%2 = alloca [4 x i8]
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%4 = call i64 @fread(i8* %3, i32 1, i32 4, i32* %0)
%5 = icmp eq i64 %4, 4
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %35
9: ; preds = %1
%10 = load i8, i8* %3
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 1
%12 = load i8, i8* %11
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 2
%14 = load i8, i8* %13
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 3
%16 = load i8, i8* %15
%17 = icmp ne i8 %10, 0
%18 = icmp ne i8 %12, 0
%19 = select i1 %17, i1 true, i1 %18
%20 = icmp ne i8 %14, 0
%21 = select i1 %19, i1 true, i1 %20
%22 = icmp ne i8 %16, 0
%23 = select i1 %21, i1 true, i1 %22
br i1 %23, label %24, label %38
24: ; preds = %9
%25 = sext i8 %16 to i32
%26 = sext i8 %14 to i32
%27 = sext i8 %12 to i32
%28 = sext i8 %10 to i32
%29 = load i32, i32* @stderr
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%31 = load i32, i32* @stderr
%32 = tail call i32 @putc(i8 signext 10, i32 %31)
%33 = load i32, i32* @stderr
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 %27, i32 %26, i32 %25)
br label %35
35: ; preds = %6, %24
%36 = load i32, i32* @stderr
%37 = tail call i32 @putc(i8 signext 10, i32 %36)
br label %38
38: ; preds = %35, %9
%39 = phi i32 [ 0, %9 ], [ -1, %35 ]
ret i32 %39
}