#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*/ uint8_t;
typedef int uint32_t;
typedef size_t off_t;
typedef int int32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ error(char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
uint8_t *load_file(const char *filename, uint32_t *w, uint32_t *h) {
  uint8_t header_buf[0x36];
  uint8_t *buf;
  uint8_t px[4] = {0};
  uint32_t k;
  FILE *fh = fopen(filename, "rb");
  int32_t x, y;
  off_t offset;
  if (fh == NULL) {
    error("impossible d'ouvrir le fichier en lecture", 1);
  }
  fread(header_buf, 1, 0x36, fh);
  k = *((uint32_t *)(header_buf + 0x1c));
  if (k != 24) {
    error("fichier Bitmap invalide", 3);
  }
  k = *((uint32_t *)(header_buf + 0xe));
  if (k != 40) {
    error("fichier Bitmap invalide : mauvais entête", 3);
  }
  *w = *((uint32_t *)(header_buf + 0x12));
  *h = *((uint32_t *)(header_buf + 0x16));
  if ((*w & 3) != 0) {
    error("la largeur de l'image Bitmap n'est pas un multiple de 4", 3);
  }
  buf = (uint8_t *)malloc(3 * *w * *h);
  for (y = *h - 1; y >= 0; --y) {
    for (x = 0; x < *w; ++x) {
      offset = 3 * (y * *w + x);
      if (fread(px, 1, 3, fh) != 3) {
        free(buf);
        error("impossible de lire le fichier Bitmap au complet", 3);
      }
      buf[offset] = px[2];
      buf[offset + 1] = px[1];
      buf[offset + 2] = px[0];
    }
  }
  fclose(fh);
  return buf;
}


x86 assembly (clang, -O0):
<load_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x120(%rbp)
cmpq   $0x0,-0x120(%rbp)
jne    11d0 <load_file+0x60>
lea    0xe3d(%rip),%rdi
mov    $0x1,%esi
call   1080 <error@plt>
lea    -0xf0(%rbp),%rdi
mov    -0x120(%rbp),%rcx
mov    $0x1,%esi
mov    $0x36,%edx
call   1040 <fread@plt>
mov    -0x80(%rbp),%eax
mov    %eax,-0x114(%rbp)
cmpl   $0x18,-0x114(%rbp)
je     1214 <load_file+0xa4>
lea    0xe23(%rip),%rdi
mov    $0x3,%esi
call   1080 <error@plt>
mov    -0xb8(%rbp),%eax
mov    %eax,-0x114(%rbp)
cmpl   $0x28,-0x114(%rbp)
je     123e <load_file+0xce>
lea    0xe11(%rip),%rdi
mov    $0x3,%esi
call   1080 <error@plt>
mov    -0xa8(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x98(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
and    $0x3,%eax
cmp    $0x0,%eax
je     1279 <load_file+0x109>
lea    0xe00(%rip),%rdi
mov    $0x3,%esi
call   1080 <error@plt>
mov    -0x10(%rbp),%rax
imul   $0x3,(%rax),%edi
mov    -0x18(%rbp),%rax
imul   (%rax),%edi
call   1070 <malloc@plt>
mov    %rax,-0xf8(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
sub    $0x1,%eax
mov    %eax,-0x128(%rbp)
cmpl   $0x0,-0x128(%rbp)
jl     13a1 <load_file+0x231>
movl   $0x0,-0x124(%rbp)
mov    -0x124(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    1388 <load_file+0x218>
mov    -0x128(%rbp),%eax
mov    -0x10(%rbp),%rcx
imul   (%rcx),%eax
add    -0x124(%rbp),%eax
imul   $0x3,%eax,%eax
cltq
mov    %rax,-0x130(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x120(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3,%edx
call   1040 <fread@plt>
cmp    $0x3,%eax
je     132d <load_file+0x1bd>
mov    -0xf8(%rbp),%rdi
call   1030 <free@plt>
lea    0xd84(%rip),%rdi
mov    $0x3,%esi
call   1080 <error@plt>
mov    -0x108(%rbp),%edx
mov    -0xf8(%rbp),%rax
mov    -0x130(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10c(%rbp),%edx
mov    -0xf8(%rbp),%rax
mov    -0x130(%rbp),%rcx
mov    %edx,0x4(%rax,%rcx,4)
mov    -0x110(%rbp),%edx
mov    -0xf8(%rbp),%rax
mov    -0x130(%rbp),%rcx
mov    %edx,0x8(%rax,%rcx,4)
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    12b9 <load_file+0x149>
jmp    138d <load_file+0x21d>
mov    -0x128(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x128(%rbp)
jmp    12a2 <load_file+0x132>
mov    -0x120(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0xf8(%rbp),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf8,%rsp
mov    %rdx,%r12
mov    %rsi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
lea    0xe7b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11a3 <load_file+0x43>
lea    0xe6a(%rip),%rdi
mov    $0x1,%esi
call   1070 <error@plt>
lea    0x20(%rsp),%rdi
mov    $0x1,%esi
mov    $0x36,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
cmpl   $0x18,0x90(%rsp)
18
je     11d5 <load_file+0x75>
lea    0xe62(%rip),%rdi
mov    $0x3,%esi
call   1070 <error@plt>
cmpl   $0x28,0x58(%rsp)
je     11ed <load_file+0x8d>
lea    0xe62(%rip),%rdi
mov    $0x3,%esi
call   1070 <error@plt>
mov    0x68(%rsp),%eax
mov    %eax,(%r14)
mov    0x78(%rsp),%eax
mov    %eax,(%r12)
mov    (%r14),%ecx
test   $0x3,%cl
je     121c <load_file+0xbc>
lea    0xe64(%rip),%rdi
mov    $0x3,%esi
call   1070 <error@plt>
mov    (%r14),%ecx
mov    (%r12),%eax
imul   %ecx,%eax
lea    (%rax,%rax,2),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    (%r12),%eax
test   %eax,%eax
jle    12c5 <load_file+0x165>
mov    (%r14),%r13d
lea    -0x1(%rax),%ebp
jmp    1250 <load_file+0xf0>
xchg   %ax,%ax
mov    0x18(%rsp),%rcx
lea    -0x1(%rcx),%eax
add    $0xffffffff,%ebp
cmp    $0x2,%ecx
jl     12c5 <load_file+0x165>
test   %r13d,%r13d
mov    %rax,0x18(%rsp)
jle    1240 <load_file+0xe0>
xor    %r12d,%r12d
jmp    1289 <load_file+0x129>
nop
lea    0x0(%r13,%r13,2),%eax
cltq
mov    0x8(%rsp),%ecx
mov    %ecx,(%rbx,%rax,4)
mov    0x4(%rsp),%ecx
mov    %ecx,0x4(%rbx,%rax,4)
mov    (%rsp),%ecx
mov    %ecx,0x8(%rbx,%rax,4)
add    $0x1,%r12d
mov    (%r14),%r13d
cmp    %r13d,%r12d
jge    1240 <load_file+0xe0>
imul   %ebp,%r13d
add    %r12d,%r13d
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x3,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
cmp    $0x3,%eax
je     1260 <load_file+0x100>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xdee(%rip),%rdi
mov    $0x3,%esi
call   1070 <error@plt>
jmp    1260 <load_file+0x100>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rax
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [42 x i8] c"impossible d'ouvrir le fichier en lecture\00"
@.str.2 = [24 x i8] c"fichier Bitmap invalide\00"
@.str.3 = [42 x i8] c"fichier Bitmap invalide : mauvais ent\C3\AAte\00"
@.str.4 = [56 x i8] c"la largeur de l'image Bitmap n'est pas un multiple de 4\00"
@.str.5 = [48 x i8] c"impossible de lire le fichier Bitmap au complet\00"
define i32* @load_file(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [54 x i32]
%8 = alloca i32*
%9 = alloca [4 x i32]
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i64
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%15 = bitcast [4 x i32]* %9 to i8*
%16 = load i8*, i8** %4
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %11
%18 = load i32*, i32** %11
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = call i32 @error(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %22
22: ; preds = %20, %3
%23 = getelementptr inbounds [54 x i32], [54 x i32]* %7, i64 0, i64 0
%24 = load i32*, i32** %11
%25 = call i32 @fread(i32* %23, i32 1, i32 54, i32* %24)
%26 = getelementptr inbounds [54 x i32], [54 x i32]* %7, i64 0, i64 0
%27 = getelementptr inbounds i32, i32* %26, i64 28
%28 = load i32, i32* %27
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = icmp ne i32 %29, 24
br i1 %30, label %31, label %33
31: ; preds = %22
%32 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 3)
br label %33
33: ; preds = %31, %22
%34 = getelementptr inbounds [54 x i32], [54 x i32]* %7, i64 0, i64 0
%35 = getelementptr inbounds i32, i32* %34, i64 14
%36 = load i32, i32* %35
store i32 %36, i32* %10
%37 = load i32, i32* %10
%38 = icmp ne i32 %37, 40
br i1 %38, label %39, label %41
39: ; preds = %33
%40 = call i32 @error(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 3)
br label %41
41: ; preds = %39, %33
%42 = getelementptr inbounds [54 x i32], [54 x i32]* %7, i64 0, i64 0
%43 = getelementptr inbounds i32, i32* %42, i64 18
%44 = load i32, i32* %43
%45 = load i32*, i32** %5
store i32 %44, i32* %45
%46 = getelementptr inbounds [54 x i32], [54 x i32]* %7, i64 0, i64 0
%47 = getelementptr inbounds i32, i32* %46, i64 22
%48 = load i32, i32* %47
%49 = load i32*, i32** %6
store i32 %48, i32* %49
%50 = load i32*, i32** %5
%51 = load i32, i32* %50
%52 = and i32 %51, 3
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %41
%55 = call i32 @error(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 3)
br label %56
56: ; preds = %54, %41
%57 = load i32*, i32** %5
%58 = load i32, i32* %57
%59 = mul nsw i32 3, %58
%60 = load i32*, i32** %6
%61 = load i32, i32* %60
%62 = mul nsw i32 %59, %61
%63 = call i64 @malloc(i32 %62)
%64 = inttoptr i64 %63 to i32*
store i32* %64, i32** %8
%65 = load i32*, i32** %6
%66 = load i32, i32* %65
%67 = sub nsw i32 %66, 1
store i32 %67, i32* %13
br label %68
68: ; preds = %116, %56
%69 = load i32, i32* %13
%70 = icmp sge i32 %69, 0
br i1 %70, label %71, label %119
71: ; preds = %68
store i32 0, i32* %12
br label %72
72: ; preds = %112, %71
%73 = load i32, i32* %12
%74 = load i32*, i32** %5
%75 = load i32, i32* %74
%76 = icmp slt i32 %73, %75
br i1 %76, label %77, label %115
77: ; preds = %72
%78 = load i32, i32* %13
%79 = load i32*, i32** %5
%80 = load i32, i32* %79
%81 = mul nsw i32 %78, %80
%82 = load i32, i32* %12
%83 = add nsw i32 %81, %82
%84 = mul nsw i32 3, %83
%85 = sext i32 %84 to i64
store i64 %85, i64* %14
%86 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
%87 = load i32*, i32** %11
%88 = call i32 @fread(i32* %86, i32 1, i32 3, i32* %87)
%89 = icmp ne i32 %88, 3
br i1 %89, label %90, label %94
90: ; preds = %77
%91 = load i32*, i32** %8
%92 = call i32 @free(i32* %91)
%93 = call i32 @error(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), i32 3)
br label %94
94: ; preds = %90, %77
%95 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 2
%96 = load i32, i32* %95
%97 = load i32*, i32** %8
%98 = load i64, i64* %14
%99 = getelementptr inbounds i32, i32* %97, i64 %98
store i32 %96, i32* %99
%100 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 1
%101 = load i32, i32* %100
%102 = load i32*, i32** %8
%103 = load i64, i64* %14
%104 = add i64 %103, 1
%105 = getelementptr inbounds i32, i32* %102, i64 %104
store i32 %101, i32* %105
%106 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
%107 = load i32, i32* %106
%108 = load i32*, i32** %8
%109 = load i64, i64* %14
%110 = add i64 %109, 2
%111 = getelementptr inbounds i32, i32* %108, i64 %110
store i32 %107, i32* %111
br label %112
112: ; preds = %94
%113 = load i32, i32* %12
%114 = add nsw i32 %113, 1
store i32 %114, i32* %12
br label %72
115: ; preds = %72
br label %116
116: ; preds = %115
%117 = load i32, i32* %13
%118 = add nsw i32 %117, -1
store i32 %118, i32* %13
br label %68
119: ; preds = %68
%120 = load i32*, i32** %11
%121 = call i32 @fclose(i32* %120)
%122 = load i32*, i32** %8
ret i32* %122
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [42 x i8] c"impossible d'ouvrir le fichier en lecture\00"
@.str.2 = [24 x i8] c"fichier Bitmap invalide\00"
@.str.3 = [42 x i8] c"fichier Bitmap invalide : mauvais ent\C3\AAte\00"
@.str.4 = [56 x i8] c"la largeur de l'image Bitmap n'est pas un multiple de 4\00"
@.str.5 = [48 x i8] c"impossible de lire le fichier Bitmap au complet\00"
define i32* @load_file(i8* nocapture %0, i32* nocapture %1, i32* nocapture %2) {
%4 = alloca [54 x i32]
%5 = alloca [4 x i32]
%6 = bitcast [54 x i32]* %4 to i8*
%7 = bitcast [4 x i32]* %5 to i8*
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = tail call i32 @error(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %12
12: ; preds = %10, %3
%13 = getelementptr inbounds [54 x i32], [54 x i32]* %4, i64 0, i64 0
%14 = call i32 @fread(i32* %13, i32 1, i32 54, i32* %8)
%15 = getelementptr inbounds [54 x i32], [54 x i32]* %4, i64 0, i64 28
%16 = load i32, i32* %15
%17 = icmp eq i32 %16, 24
br i1 %17, label %20, label %18
18: ; preds = %12
%19 = tail call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 3)
br label %20
20: ; preds = %18, %12
%21 = getelementptr inbounds [54 x i32], [54 x i32]* %4, i64 0, i64 14
%22 = load i32, i32* %21
%23 = icmp eq i32 %22, 40
br i1 %23, label %26, label %24
24: ; preds = %20
%25 = tail call i32 @error(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 3)
br label %26
26: ; preds = %24, %20
%27 = getelementptr inbounds [54 x i32], [54 x i32]* %4, i64 0, i64 18
%28 = load i32, i32* %27
store i32 %28, i32* %1
%29 = getelementptr inbounds [54 x i32], [54 x i32]* %4, i64 0, i64 22
%30 = load i32, i32* %29
store i32 %30, i32* %2
%31 = load i32, i32* %1
%32 = and i32 %31, 3
%33 = icmp eq i32 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %26
%35 = tail call i32 @error(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 3)
%36 = load i32, i32* %1
%37 = load i32, i32* %2
br label %38
38: ; preds = %34, %26
%39 = phi i32 [ %37, %34 ], [ %30, %26 ]
%40 = phi i32 [ %36, %34 ], [ %31, %26 ]
%41 = mul nsw i32 %40, 3
%42 = mul nsw i32 %41, %39
%43 = tail call i64 @malloc(i32 %42)
%44 = inttoptr i64 %43 to i32*
%45 = load i32, i32* %2
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %84
47: ; preds = %38
%48 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
%49 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 2
%50 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 1
%51 = load i32, i32* %1
br label %55
52: ; preds = %72, %55
%53 = phi i32 [ %56, %55 ], [ %82, %72 ]
%54 = icmp sgt i32 %57, 1
br i1 %54, label %55, label %84
55: ; preds = %47, %52
%56 = phi i32 [ %51, %47 ], [ %53, %52 ]
%57 = phi i32 [ %45, %47 ], [ %58, %52 ]
%58 = add nsw i32 %57, -1
%59 = icmp sgt i32 %56, 0
br i1 %59, label %60, label %52
60: ; preds = %55, %72
%61 = phi i32 [ %82, %72 ], [ %56, %55 ]
%62 = phi i32 [ %81, %72 ], [ 0, %55 ]
%63 = mul nsw i32 %61, %58
%64 = add nsw i32 %63, %62
%65 = mul nsw i32 %64, 3
%66 = sext i32 %65 to i64
%67 = call i32 @fread(i32* %48, i32 1, i32 3, i32* %8)
%68 = icmp eq i32 %67, 3
br i1 %68, label %72, label %69
69: ; preds = %60
%70 = tail call i32 @free(i32* %44)
%71 = tail call i32 @error(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), i32 3)
br label %72
72: ; preds = %69, %60
%73 = load i32, i32* %49
%74 = getelementptr inbounds i32, i32* %44, i64 %66
store i32 %73, i32* %74
%75 = load i32, i32* %50
%76 = add nsw i64 %66, 1
%77 = getelementptr inbounds i32, i32* %44, i64 %76
store i32 %75, i32* %77
%78 = load i32, i32* %48
%79 = add nsw i64 %66, 2
%80 = getelementptr inbounds i32, i32* %44, i64 %79
store i32 %78, i32* %80
%81 = add nuw nsw i32 %62, 1
%82 = load i32, i32* %1
%83 = icmp slt i32 %81, %82
br i1 %83, label %60, label %52
84: ; preds = %52, %38
%85 = tail call i32 @fclose(i32* %8)
ret i32* %44
}