#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 */

/* Variables and functions */
int OS_file_read(unsigned long, unsigned char *, int);
int read_file_header(unsigned long file_handle, unsigned long *p_width,
                     unsigned long *p_height, unsigned long *p_header_size) {
  int err;
  unsigned char buf[(14 + 40)];
  unsigned long size_image;
  err = OS_file_read(file_handle, buf, (14 + 40));
  if (err)
    return err;
  *p_width = *(unsigned long *)(buf + 18);
  *p_height = *(unsigned long *)(buf + 22);
  *p_header_size = *(unsigned long *)(buf + 10);
  size_image = ((((*p_width) * 3) + 3) & ~3) * (*p_height);
  if (size_image != *(unsigned long *)(buf + 34))
    return 1;
  if ((0x4D42 != *(unsigned short *)(buf)) ||
      (40 != *(unsigned long *)(buf + 14)))
    return 1;
  if ((24 != *(unsigned short *)(buf + 28)) ||
      (0 != *(unsigned long *)(buf + 30)))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<read_file_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x36,%edx
call   1030 <OS_file_read@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1155 <read_file_header+0x45>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1208 <read_file_header+0xf8>
mov    -0x5e(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x5a(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x66(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
imul   $0x3,(%rax),%rax
add    $0x3,%rax
and    $0xfffffffffffffffc,%rax
mov    -0x20(%rbp),%rcx
imul   (%rcx),%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
cmp    -0x4e(%rbp),%rax
je     11ac <read_file_header+0x9c>
movl   $0x1,-0x4(%rbp)
jmp    1208 <read_file_header+0xf8>
movzwl -0x70(%rbp),%ecx
mov    $0x4d42,%eax
cmp    %ecx,%eax
jne    11cc <read_file_header+0xbc>
mov    $0x28,%eax
cmp    -0x62(%rbp),%rax
je     11d8 <read_file_header+0xc8>
movl   $0x1,-0x4(%rbp)
jmp    1208 <read_file_header+0xf8>
movzwl -0x54(%rbp),%ecx
mov    $0x18,%eax
cmp    %ecx,%eax
jne    11f5 <read_file_header+0xe5>
xor    %eax,%eax
cmp    -0x52(%rbp),%rax
je     1201 <read_file_header+0xf1>
movl   $0x1,-0x4(%rbp)
jmp    1208 <read_file_header+0xf8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file_header>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rsp,%rsi
mov    $0x36,%edx
call   1030 <OS_file_read@plt>
test   %eax,%eax
je     113d <read_file_header+0x2d>
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x12(%rsp),%rax
mov    %rax,(%rbx)
mov    0x16(%rsp),%rcx
mov    %rcx,(%r15)
mov    0xa(%rsp),%rax
mov    %rax,(%r14)
mov    (%rbx),%rax
lea    (%rax,%rax,2),%rdx
add    $0x3,%rdx
and    $0xfffffffffffffffc,%rdx
imul   (%r15),%rdx
mov    $0x1,%eax
cmp    0x22(%rsp),%rdx
jne    1133 <read_file_header+0x23>
movzwl (%rsp),%edx
cmp    $0x4d42,%edx
jne    1133 <read_file_header+0x23>
cmpq   $0x28,0xe(%rsp)
jne    1133 <read_file_header+0x23>
movabs $0xffff000000000000,%rdx
and    %rdx,%rcx
movabs $0x18000000000000,%rdx
cmp    %rdx,%rcx
jne    1133 <read_file_header+0x23>
xor    %eax,%eax
cmpq   $0x0,0x1e(%rsp)
setne  %al
jmp    1133 <read_file_header+0x23>

LLVM IR (-O0):
define i32 @read_file_header(i64 %0, i64* %1, i64* %2, i64* %3) {
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64*
%8 = alloca i64*
%9 = alloca i64*
%10 = alloca i32
%11 = alloca [54 x i8]
%12 = alloca i64
store i64 %0, i64* %6
store i64* %1, i64** %7
store i64* %2, i64** %8
store i64* %3, i64** %9
%13 = load i64, i64* %6
%14 = getelementptr inbounds [54 x i8], [54 x i8]* %11, i64 0, i64 0
%15 = call i32 @OS_file_read(i64 %13, i8* %14, i32 54)
store i32 %15, i32* %10
%16 = load i32, i32* %10
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %4
%19 = load i32, i32* %10
store i32 %19, i32* %5
br label %79
20: ; preds = %4
%21 = getelementptr inbounds [54 x i8], [54 x i8]* %11, i64 0, i64 0
%22 = getelementptr inbounds i8, i8* %21, i64 18
%23 = bitcast i8* %22 to i64*
%24 = load i64, i64* %23
%25 = load i64*, i64** %7
store i64 %24, i64* %25
%26 = getelementptr inbounds [54 x i8], [54 x i8]* %11, i64 0, i64 0
%27 = getelementptr inbounds i8, i8* %26, i64 22
%28 = bitcast i8* %27 to i64*
%29 = load i64, i64* %28
%30 = load i64*, i64** %8
store i64 %29, i64* %30
%31 = getelementptr inbounds [54 x i8], [54 x i8]* %11, i64 0, i64 0
%32 = getelementptr inbounds i8, i8* %31, i64 10
%33 = bitcast i8* %32 to i64*
%34 = load i64, i64* %33
%35 = load i64*, i64** %9
store i64 %34, i64* %35
%36 = load i64*, i64** %7
%37 = load i64, i64* %36
%38 = mul i64 %37, 3
%39 = add i64 %38, 3
%40 = and i64 %39, -4
%41 = load i64*, i64** %8
%42 = load i64, i64* %41
%43 = mul i64 %40, %42
store i64 %43, i64* %12
%44 = load i64, i64* %12
%45 = getelementptr inbounds [54 x i8], [54 x i8]* %11, i64 0, i64 0
%46 = getelementptr inbounds i8, i8* %45, i64 34
%47 = bitcast i8* %46 to i64*
%48 = load i64, i64* %47
%49 = icmp ne i64 %44, %48
br i1 %49, label %50, label %51
50: ; preds = %20
store i32 1, i32* %5
br label %79
51: ; preds = %20
%52 = getelementptr inbounds [54 x i8], [54 x i8]* %11, i64 0, i64 0
%53 = bitcast i8* %52 to i16*
%54 = load i16, i16* %53
%55 = zext i16 %54 to i32
%56 = icmp ne i32 19778, %55
br i1 %56, label %63, label %57
57: ; preds = %51
%58 = getelementptr inbounds [54 x i8], [54 x i8]* %11, i64 0, i64 0
%59 = getelementptr inbounds i8, i8* %58, i64 14
%60 = bitcast i8* %59 to i64*
%61 = load i64, i64* %60
%62 = icmp ne i64 40, %61
br i1 %62, label %63, label %64
63: ; preds = %57, %51
store i32 1, i32* %5
br label %79
64: ; preds = %57
%65 = getelementptr inbounds [54 x i8], [54 x i8]* %11, i64 0, i64 0
%66 = getelementptr inbounds i8, i8* %65, i64 28
%67 = bitcast i8* %66 to i16*
%68 = load i16, i16* %67
%69 = zext i16 %68 to i32
%70 = icmp ne i32 24, %69
br i1 %70, label %77, label %71
71: ; preds = %64
%72 = getelementptr inbounds [54 x i8], [54 x i8]* %11, i64 0, i64 0
%73 = getelementptr inbounds i8, i8* %72, i64 30
%74 = bitcast i8* %73 to i64*
%75 = load i64, i64* %74
%76 = icmp ne i64 0, %75
br i1 %76, label %77, label %78
77: ; preds = %71, %64
store i32 1, i32* %5
br label %79
78: ; preds = %71
store i32 0, i32* %5
br label %79
79: ; preds = %78, %77, %63, %50, %18
%80 = load i32, i32* %5
ret i32 %80
}

LLVM IR (-O2):
define i32 @read_file_header(i64 %0, i64* nocapture %1, i64* nocapture %2, i64* nocapture writeonly %3) {
%5 = alloca [54 x i8]
%6 = getelementptr inbounds [54 x i8], [54 x i8]* %5, i64 0, i64 0
%7 = call i32 @OS_file_read(i64 %0, i8* %6, i32 54)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %47
9: ; preds = %4
%10 = getelementptr inbounds [54 x i8], [54 x i8]* %5, i64 0, i64 18
%11 = bitcast i8* %10 to i64*
%12 = load i64, i64* %11
store i64 %12, i64* %1
%13 = getelementptr inbounds [54 x i8], [54 x i8]* %5, i64 0, i64 22
%14 = bitcast i8* %13 to i64*
%15 = load i64, i64* %14
store i64 %15, i64* %2
%16 = getelementptr inbounds [54 x i8], [54 x i8]* %5, i64 0, i64 10
%17 = bitcast i8* %16 to i64*
%18 = load i64, i64* %17
store i64 %18, i64* %3
%19 = load i64, i64* %1
%20 = mul i64 %19, 3
%21 = add i64 %20, 3
%22 = and i64 %21, -4
%23 = load i64, i64* %2
%24 = mul i64 %22, %23
%25 = getelementptr inbounds [54 x i8], [54 x i8]* %5, i64 0, i64 34
%26 = bitcast i8* %25 to i64*
%27 = load i64, i64* %26
%28 = icmp eq i64 %24, %27
%29 = bitcast [54 x i8]* %5 to i16*
%30 = load i16, i16* %29
%31 = icmp eq i16 %30, 19778
%32 = select i1 %28, i1 %31, i1 false
br i1 %32, label %33, label %47
33: ; preds = %9
%34 = getelementptr inbounds [54 x i8], [54 x i8]* %5, i64 0, i64 14
%35 = bitcast i8* %34 to i64*
%36 = load i64, i64* %35
%37 = icmp eq i64 %36, 40
%38 = and i64 %15, -281474976710656
%39 = icmp eq i64 %38, 6755399441055744
%40 = select i1 %37, i1 %39, i1 false
br i1 %40, label %41, label %47
41: ; preds = %33
%42 = getelementptr inbounds [54 x i8], [54 x i8]* %5, i64 0, i64 30
%43 = bitcast i8* %42 to i64*
%44 = load i64, i64* %43
%45 = icmp ne i64 %44, 0
%46 = zext i1 %45 to i32
br label %47
47: ; preds = %41, %33, %9, %4
%48 = phi i32 [ %7, %4 ], [ 1, %9 ], [ 1, %33 ], [ %46, %41 ]
ret i32 %48
}