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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
int uInt32Number(unsigned char *);
int ReadFileHeader(FILE *f, int *bitmap_pos) {
  unsigned char header[14];
  int numb = 0;
  int offset = 0;
  if (fseek(f, 0, SEEK_SET))
    return 0;
  numb = fread(header, 14, 1, f);
  if (numb != 1)
    return 0;
  if (header[0] != 'B' || header[1] != 'M')
    return 0;
  offset = uInt32Number(header + 10);
  numb = fread(header, 4, 1, f);
  if (numb != 1)
    return 0;
  if (uInt32Number(header) != 40)
    return 0;
  *bitmap_pos = offset;
  return 1;
}


x86 assembly (clang, -O0):
<ReadFileHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e87(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <fseek@plt>
cmp    $0x0,%rax
je     1178 <ReadFileHeader+0x48>
movl   $0x0,-0x4(%rbp)
jmp    123c <ReadFileHeader+0x10c>
lea    -0x26(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0xe,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
je     11a8 <ReadFileHeader+0x78>
movl   $0x0,-0x4(%rbp)
jmp    123c <ReadFileHeader+0x10c>
movzbl -0x26(%rbp),%eax
cmp    $0x42,%eax
jne    11c2 <ReadFileHeader+0x92>
movzbl -0x25(%rbp),%eax
cmp    $0x4d,%eax
je     11ce <ReadFileHeader+0x9e>
movl   $0x0,-0x4(%rbp)
jmp    123c <ReadFileHeader+0x10c>
lea    -0x26(%rbp),%rdi
add    $0xa,%rdi
call   1040 <uInt32Number@plt>
mov    %eax,-0x30(%rbp)
lea    -0x26(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
je     120e <ReadFileHeader+0xde>
movl   $0x0,-0x4(%rbp)
jmp    123c <ReadFileHeader+0x10c>
lea    -0x26(%rbp),%rdi
call   1040 <uInt32Number@plt>
cmp    $0x28,%eax
je     122c <ReadFileHeader+0xfc>
movl   $0x0,-0x4(%rbp)
jmp    123c <ReadFileHeader+0x10c>
mov    -0x30(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadFileHeader>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e99(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
xor    %esi,%esi
call   1050 <fseek@plt>
test   %rax,%rax
jne    11c1 <ReadFileHeader+0x91>
lea    0xa(%rsp),%rdi
mov    $0xe,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    11c1 <ReadFileHeader+0x91>
cmpb   $0x42,0xa(%rsp)
jne    11c1 <ReadFileHeader+0x91>
cmpb   $0x4d,0xb(%rsp)
jne    11c1 <ReadFileHeader+0x91>
lea    0x14(%rsp),%rdi
call   1040 <uInt32Number@plt>
mov    %eax,%r15d
lea    0xa(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    11c1 <ReadFileHeader+0x91>
lea    0xa(%rsp),%rdi
call   1040 <uInt32Number@plt>
cmp    $0x28,%eax
jne    11c1 <ReadFileHeader+0x91>
mov    %r15d,(%r14)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @ReadFileHeader(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [14 x i8]
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 0, i32* %7
store i32 0, i32* %8
%9 = load i32*, i32** %4
%10 = load i32, i32* @SEEK_SET
%11 = call i64 @fseek(i32* %9, i32 0, i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 0, i32* %3
br label %50
14: ; preds = %2
%15 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 0
%16 = load i32*, i32** %4
%17 = call i32 @fread(i8* %15, i32 14, i32 1, i32* %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp ne i32 %18, 1
br i1 %19, label %20, label %21
20: ; preds = %14
store i32 0, i32* %3
br label %50
21: ; preds = %14
%22 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 0
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = icmp ne i32 %24, 66
br i1 %25, label %31, label %26
26: ; preds = %21
%27 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 1
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = icmp ne i32 %29, 77
br i1 %30, label %31, label %32
31: ; preds = %26, %21
store i32 0, i32* %3
br label %50
32: ; preds = %26
%33 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 0
%34 = getelementptr inbounds i8, i8* %33, i64 10
%35 = call i32 @uInt32Number(i8* %34)
store i32 %35, i32* %8
%36 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 0
%37 = load i32*, i32** %4
%38 = call i32 @fread(i8* %36, i32 4, i32 1, i32* %37)
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = icmp ne i32 %39, 1
br i1 %40, label %41, label %42
41: ; preds = %32
store i32 0, i32* %3
br label %50
42: ; preds = %32
%43 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 0
%44 = call i32 @uInt32Number(i8* %43)
%45 = icmp ne i32 %44, 40
br i1 %45, label %46, label %47
46: ; preds = %42
store i32 0, i32* %3
br label %50
47: ; preds = %42
%48 = load i32, i32* %8
%49 = load i32*, i32** %5
store i32 %48, i32* %49
store i32 1, i32* %3
br label %50
50: ; preds = %47, %46, %41, %31, %20, %13
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @ReadFileHeader(i32* nocapture %0, i32* nocapture writeonly %1) {
%3 = alloca [14 x i8]
%4 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @SEEK_SET
%6 = tail call i64 @fseek(i32* %0, i32 0, i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %27
8: ; preds = %2
%9 = call i32 @fread(i8* %4, i32 14, i32 1, i32* %0)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %27
11: ; preds = %8
%12 = load i8, i8* %4
%13 = icmp ne i8 %12, 66
%14 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 1
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 77
%17 = select i1 %13, i1 true, i1 %16
br i1 %17, label %27, label %18
18: ; preds = %11
%19 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 10
%20 = call i32 @uInt32Number(i8* %19)
%21 = call i32 @fread(i8* %4, i32 4, i32 1, i32* %0)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = call i32 @uInt32Number(i8* %4)
%25 = icmp eq i32 %24, 40
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 %20, i32* %1
br label %27
27: ; preds = %23, %18, %11, %8, %2, %26
%28 = phi i32 [ 1, %26 ], [ 0, %2 ], [ 0, %8 ], [ 0, %11 ], [ 0, %18 ], [ 0, %23 ]
ret i32 %28
}