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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
unsigned int fread(unsigned char *, int, unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
unsigned int loadbmp_decode_file(const char *filename,
                                 unsigned char **imageData, unsigned int *width,
                                 unsigned int *height) {
  FILE *f = fopen(filename, "rb");
  if (!f)
    return 2;
  unsigned char bmp_file_header[14];
  unsigned char bmp_info_header[40];
  unsigned char bmp_pad[3];
  unsigned int w, h;
  unsigned char *data = NULL;
  unsigned int x, y, i, padding;
  memset(bmp_file_header, 0, sizeof(bmp_file_header));
  memset(bmp_info_header, 0, sizeof(bmp_info_header));
  if (fread(bmp_file_header, sizeof(bmp_file_header), 1, f) == 0) {
    fclose(f);
    return 4;
  }
  if (fread(bmp_info_header, sizeof(bmp_info_header), 1, f) == 0) {
    fclose(f);
    return 4;
  }
  if ((bmp_file_header[0] != 'B') || (bmp_file_header[1] != 'M')) {
    fclose(f);
    return 5;
  }
  if ((bmp_info_header[14] != 24) && (bmp_info_header[14] != 32)) {
    fclose(f);
    return 6;
  }
  w = (bmp_info_header[4] + (bmp_info_header[5] << 8) +
       (bmp_info_header[6] << 16) + (bmp_info_header[7] << 24));
  h = (bmp_info_header[8] + (bmp_info_header[9] << 8) +
       (bmp_info_header[10] << 16) + (bmp_info_header[11] << 24));
  if ((w > 0) && (h > 0)) {
    data = (unsigned char *)malloc(w * h * 4);
    if (!data) {
      fclose(f);
      return 1;
    }
    for (y = (h - 1); y != -1; y--) {
      for (x = 0; x < w; x++) {
        i = (x + y * w) * 4;
        if (fread(data + i, 3, 1, f) == 0) {
          free(data);
          fclose(f);
          return 4;
        }
        data[i + 3] = data[i + 2];
        data[i + 2] = data[i + 1];
        data[i + 1] = data[i];
        data[i] = 255;
      }
      padding = ((4 - (w * 3) % 4) % 4);
      if (fread(bmp_pad, 1, padding, f) != padding) {
        free(data);
        fclose(f);
        return 4;
      }
    }
  }
  (*width) = w;
  (*height) = h;
  (*imageData) = data;
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<loadbmp_decode_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11a6 <loadbmp_decode_file+0x46>
movl   $0x2,-0x4(%rbp)
jmp    150c <loadbmp_decode_file+0x3ac>
movq   $0x0,-0x88(%rbp)
lea    -0x3e(%rbp),%rdi
xor    %esi,%esi
mov    $0xe,%edx
call   1060 <memset@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
lea    -0x3e(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0xe,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x0,%eax
jne    1206 <loadbmp_decode_file+0xa6>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x4,-0x4(%rbp)
jmp    150c <loadbmp_decode_file+0x3ac>
lea    -0x70(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x28,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x0,%eax
jne    123b <loadbmp_decode_file+0xdb>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x4,-0x4(%rbp)
jmp    150c <loadbmp_decode_file+0x3ac>
movzbl -0x3e(%rbp),%eax
cmp    $0x42,%eax
jne    1255 <loadbmp_decode_file+0xf5>
movzbl -0x3d(%rbp),%eax
cmp    $0x4d,%eax
je     126a <loadbmp_decode_file+0x10a>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x5,-0x4(%rbp)
jmp    150c <loadbmp_decode_file+0x3ac>
movzbl -0x62(%rbp),%eax
cmp    $0x18,%eax
je     1299 <loadbmp_decode_file+0x139>
movzbl -0x62(%rbp),%eax
cmp    $0x20,%eax
je     1299 <loadbmp_decode_file+0x139>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x6,-0x4(%rbp)
jmp    150c <loadbmp_decode_file+0x3ac>
movzbl -0x6c(%rbp),%eax
movzbl -0x6b(%rbp),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
movzbl -0x6a(%rbp),%ecx
shl    $0x10,%ecx
add    %ecx,%eax
movzbl -0x69(%rbp),%ecx
shl    $0x18,%ecx
add    %ecx,%eax
mov    %eax,-0x78(%rbp)
movzbl -0x68(%rbp),%eax
movzbl -0x67(%rbp),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
movzbl -0x66(%rbp),%ecx
shl    $0x10,%ecx
add    %ecx,%eax
movzbl -0x65(%rbp),%ecx
shl    $0x18,%ecx
add    %ecx,%eax
mov    %eax,-0x7c(%rbp)
cmpl   $0x0,-0x78(%rbp)
jbe    14dc <loadbmp_decode_file+0x37c>
cmpl   $0x0,-0x7c(%rbp)
jbe    14dc <loadbmp_decode_file+0x37c>
mov    -0x78(%rbp),%edi
imul   -0x7c(%rbp),%edi
shl    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    132a <loadbmp_decode_file+0x1ca>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    150c <loadbmp_decode_file+0x3ac>
mov    -0x7c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x90(%rbp)
cmpl   $0xffffffff,-0x90(%rbp)
je     14d7 <loadbmp_decode_file+0x377>
movl   $0x0,-0x8c(%rbp)
mov    -0x8c(%rbp),%eax
cmp    -0x78(%rbp),%eax
jae    1462 <loadbmp_decode_file+0x302>
mov    -0x8c(%rbp),%eax
mov    -0x90(%rbp),%ecx
imul   -0x78(%rbp),%ecx
add    %ecx,%eax
shl    $0x2,%eax
mov    %eax,-0x94(%rbp)
mov    -0x88(%rbp),%rdi
mov    -0x94(%rbp),%eax
add    %rax,%rdi
mov    -0x30(%rbp),%rcx
mov    $0x3,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x0,%eax
jne    13c4 <loadbmp_decode_file+0x264>
mov    -0x88(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x4,-0x4(%rbp)
jmp    150c <loadbmp_decode_file+0x3ac>
mov    -0x88(%rbp),%rax
mov    -0x94(%rbp),%ecx
add    $0x2,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x88(%rbp),%rax
mov    -0x94(%rbp),%ecx
add    $0x3,%ecx
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x88(%rbp),%rax
mov    -0x94(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x88(%rbp),%rax
mov    -0x94(%rbp),%ecx
add    $0x2,%ecx
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x88(%rbp),%rax
mov    -0x94(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x88(%rbp),%rax
mov    -0x94(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x88(%rbp),%rax
mov    -0x94(%rbp),%ecx
movb   $0xff,(%rax,%rcx,1)
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
jmp    134d <loadbmp_decode_file+0x1ed>
imul   $0x3,-0x78(%rbp),%ecx
and    $0x3,%ecx
mov    $0x4,%eax
sub    %ecx,%eax
and    $0x3,%eax
mov    %eax,-0x98(%rbp)
lea    -0x73(%rbp),%rdi
mov    -0x98(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
cmp    -0x98(%rbp),%eax
je     14be <loadbmp_decode_file+0x35e>
mov    -0x88(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x4,-0x4(%rbp)
jmp    150c <loadbmp_decode_file+0x3ac>
jmp    14c3 <loadbmp_decode_file+0x363>
mov    -0x90(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x90(%rbp)
jmp    1336 <loadbmp_decode_file+0x1d6>
jmp    14dc <loadbmp_decode_file+0x37c>
mov    -0x78(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x7c(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x88(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadbmp_decode_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r15
lea    0xe82(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     137d <loadbmp_decode_file+0x21d>
mov    %rax,%rbx
lea    0x42(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xe,%edx
call   1060 <memset@plt>
lea    0x50(%rsp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
mov    %rbp,%rdi
mov    $0xe,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    $0x4,%r13d
test   %eax,%eax
je     1399 <loadbmp_decode_file+0x239>
lea    0x50(%rsp),%rdi
mov    $0x28,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
test   %eax,%eax
je     1399 <loadbmp_decode_file+0x239>
cmpb   $0x42,0x42(%rsp)
mov    $0x5,%r13d
jne    1399 <loadbmp_decode_file+0x239>
cmpb   $0x4d,0x43(%rsp)
jne    1399 <loadbmp_decode_file+0x239>
mov    0x5e(%rsp),%al
cmp    $0x20,%al
je     1228 <loadbmp_decode_file+0xc8>
mov    $0x6,%r13d
cmp    $0x18,%al
jne    1399 <loadbmp_decode_file+0x239>
mov    0x54(%rsp),%ecx
mov    0x58(%rsp),%eax
xor    %r13d,%r13d
test   %rcx,%rcx
je     1385 <loadbmp_decode_file+0x225>
mov    $0x0,%ebp
test   %eax,%eax
je     1387 <loadbmp_decode_file+0x227>
mov    %ecx,%edi
imul   %eax,%edi
shl    $0x2,%edi
mov    %rax,0x18(%rsp)
mov    %rcx,0x10(%rsp)
call   1070 <malloc@plt>
test   %rax,%rax
je     1393 <loadbmp_decode_file+0x233>
mov    %rax,%rbp
mov    0x10(%rsp),%rdi
lea    (%rdi,%rdi,2),%eax
neg    %eax
and    $0x3,%eax
mov    %eax,0x4(%rsp)
mov    0x18(%rsp),%rcx
lea    -0x1(%rcx),%edx
imul   %edi,%edx
shl    $0x2,%edx
lea    0x0(,%rdi,4),%eax
mov    %eax,(%rsp)
mov    %ecx,%esi
mov    %rcx,%rax
mov    %rdi,%rcx
mov    %r14,0x38(%rsp)
mov    %r15,0x30(%rsp)
mov    %r12,0x28(%rsp)
sub    $0x1,%esi
jb     1387 <loadbmp_decode_file+0x227>
mov    %esi,0x8(%rsp)
mov    %rcx,%r15
mov    %edx,0xc(%rsp)
mov    %edx,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12d,%r14d
add    %rbp,%r14
mov    %r14,%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
test   %eax,%eax
je     136d <loadbmp_decode_file+0x20d>
lea    0x2(%r12),%eax
movzbl 0x0(%rbp,%rax,1),%ecx
lea    0x3(%r12),%edx
mov    %cl,0x0(%rbp,%rdx,1)
lea    0x1(%r12),%ecx
movzbl 0x0(%rbp,%rcx,1),%edx
mov    %dl,0x0(%rbp,%rax,1)
movzbl (%r14),%eax
mov    %al,0x0(%rbp,%rcx,1)
movb   $0xff,(%r14)
add    $0x4,%r12d
add    $0xffffffffffffffff,%r15
jne    12d0 <loadbmp_decode_file+0x170>
lea    0x25(%rsp),%rdi
mov    $0x1,%esi
mov    0x4(%rsp),%r14d
mov    %r14d,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    0xc(%rsp),%edx
sub    (%rsp),%edx
cmp    %r14d,%eax
mov    0x38(%rsp),%r14
mov    0x30(%rsp),%r15
mov    0x28(%rsp),%r12
mov    0x18(%rsp),%rax
mov    0x10(%rsp),%rcx
mov    0x8(%rsp),%esi
je     12ac <loadbmp_decode_file+0x14c>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    $0x4,%r13d
jmp    1399 <loadbmp_decode_file+0x239>
mov    $0x2,%r13d
jmp    13a1 <loadbmp_decode_file+0x241>
xor    %ebp,%ebp
mov    %ecx,(%r12)
mov    %eax,(%r14)
mov    %rbp,(%r15)
jmp    1399 <loadbmp_decode_file+0x239>
mov    $0x1,%r13d
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r13d,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i32 @loadbmp_decode_file(i8* %0, i8** %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca [14 x i8]
%12 = alloca [40 x i8]
%13 = alloca [3 x i8]
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i8* %0, i8** %6
store i8** %1, i8*** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%21 = load i8*, i8** %6
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %10
%23 = load i32*, i32** %10
%24 = icmp ne i32* %23, null
br i1 %24, label %26, label %25
25: ; preds = %4
store i32 2, i32* %5
br label %227
26: ; preds = %4
store i8* null, i8** %16
%27 = getelementptr inbounds [14 x i8], [14 x i8]* %11, i64 0, i64 0
%28 = call i32 @memset(i8* %27, i32 0, i32 14)
%29 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
%30 = call i32 @memset(i8* %29, i32 0, i32 40)
%31 = getelementptr inbounds [14 x i8], [14 x i8]* %11, i64 0, i64 0
%32 = load i32*, i32** %10
%33 = call i32 @fread(i8* %31, i32 14, i32 1, i32* %32)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %26
%36 = load i32*, i32** %10
%37 = call i32 @fclose(i32* %36)
store i32 4, i32* %5
br label %227
38: ; preds = %26
%39 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
%40 = load i32*, i32** %10
%41 = call i32 @fread(i8* %39, i32 40, i32 1, i32* %40)
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %38
%44 = load i32*, i32** %10
%45 = call i32 @fclose(i32* %44)
store i32 4, i32* %5
br label %227
46: ; preds = %38
%47 = getelementptr inbounds [14 x i8], [14 x i8]* %11, i64 0, i64 0
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = icmp ne i32 %49, 66
br i1 %50, label %56, label %51
51: ; preds = %46
%52 = getelementptr inbounds [14 x i8], [14 x i8]* %11, i64 0, i64 1
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = icmp ne i32 %54, 77
br i1 %55, label %56, label %59
56: ; preds = %51, %46
%57 = load i32*, i32** %10
%58 = call i32 @fclose(i32* %57)
store i32 5, i32* %5
br label %227
59: ; preds = %51
%60 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 14
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = icmp ne i32 %62, 24
br i1 %63, label %64, label %72
64: ; preds = %59
%65 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 14
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = icmp ne i32 %67, 32
br i1 %68, label %69, label %72
69: ; preds = %64
%70 = load i32*, i32** %10
%71 = call i32 @fclose(i32* %70)
store i32 6, i32* %5
br label %227
72: ; preds = %64, %59
%73 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 4
%74 = load i8, i8* %73
%75 = zext i8 %74 to i32
%76 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 5
%77 = load i8, i8* %76
%78 = zext i8 %77 to i32
%79 = shl i32 %78, 8
%80 = add nsw i32 %75, %79
%81 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 6
%82 = load i8, i8* %81
%83 = zext i8 %82 to i32
%84 = shl i32 %83, 16
%85 = add nsw i32 %80, %84
%86 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 7
%87 = load i8, i8* %86
%88 = zext i8 %87 to i32
%89 = shl i32 %88, 24
%90 = add nsw i32 %85, %89
store i32 %90, i32* %14
%91 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 8
%92 = load i8, i8* %91
%93 = zext i8 %92 to i32
%94 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 9
%95 = load i8, i8* %94
%96 = zext i8 %95 to i32
%97 = shl i32 %96, 8
%98 = add nsw i32 %93, %97
%99 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 10
%100 = load i8, i8* %99
%101 = zext i8 %100 to i32
%102 = shl i32 %101, 16
%103 = add nsw i32 %98, %102
%104 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 11
%105 = load i8, i8* %104
%106 = zext i8 %105 to i32
%107 = shl i32 %106, 24
%108 = add nsw i32 %103, %107
store i32 %108, i32* %15
%109 = load i32, i32* %14
%110 = icmp ugt i32 %109, 0
br i1 %110, label %111, label %218
111: ; preds = %72
%112 = load i32, i32* %15
%113 = icmp ugt i32 %112, 0
br i1 %113, label %114, label %218
114: ; preds = %111
%115 = load i32, i32* %14
%116 = load i32, i32* %15
%117 = mul i32 %115, %116
%118 = mul i32 %117, 4
%119 = call i64 @malloc(i32 %118)
%120 = inttoptr i64 %119 to i8*
store i8* %120, i8** %16
%121 = load i8*, i8** %16
%122 = icmp ne i8* %121, null
br i1 %122, label %126, label %123
123: ; preds = %114
%124 = load i32*, i32** %10
%125 = call i32 @fclose(i32* %124)
store i32 1, i32* %5
br label %227
126: ; preds = %114
%127 = load i32, i32* %15
%128 = sub i32 %127, 1
store i32 %128, i32* %18
br label %129
129: ; preds = %214, %126
%130 = load i32, i32* %18
%131 = icmp ne i32 %130, -1
br i1 %131, label %132, label %217
132: ; preds = %129
store i32 0, i32* %17
br label %133
133: ; preds = %193, %132
%134 = load i32, i32* %17
%135 = load i32, i32* %14
%136 = icmp ult i32 %134, %135
br i1 %136, label %137, label %196
137: ; preds = %133
%138 = load i32, i32* %17
%139 = load i32, i32* %18
%140 = load i32, i32* %14
%141 = mul i32 %139, %140
%142 = add i32 %138, %141
%143 = mul i32 %142, 4
store i32 %143, i32* %19
%144 = load i8*, i8** %16
%145 = load i32, i32* %19
%146 = zext i32 %145 to i64
%147 = getelementptr inbounds i8, i8* %144, i64 %146
%148 = load i32*, i32** %10
%149 = call i32 @fread(i8* %147, i32 3, i32 1, i32* %148)
%150 = icmp eq i32 %149, 0
br i1 %150, label %151, label %156
151: ; preds = %137
%152 = load i8*, i8** %16
%153 = call i32 @free(i8* %152)
%154 = load i32*, i32** %10
%155 = call i32 @fclose(i32* %154)
store i32 4, i32* %5
br label %227
156: ; preds = %137
%157 = load i8*, i8** %16
%158 = load i32, i32* %19
%159 = add i32 %158, 2
%160 = zext i32 %159 to i64
%161 = getelementptr inbounds i8, i8* %157, i64 %160
%162 = load i8, i8* %161
%163 = load i8*, i8** %16
%164 = load i32, i32* %19
%165 = add i32 %164, 3
%166 = zext i32 %165 to i64
%167 = getelementptr inbounds i8, i8* %163, i64 %166
store i8 %162, i8* %167
%168 = load i8*, i8** %16
%169 = load i32, i32* %19
%170 = add i32 %169, 1
%171 = zext i32 %170 to i64
%172 = getelementptr inbounds i8, i8* %168, i64 %171
%173 = load i8, i8* %172
%174 = load i8*, i8** %16
%175 = load i32, i32* %19
%176 = add i32 %175, 2
%177 = zext i32 %176 to i64
%178 = getelementptr inbounds i8, i8* %174, i64 %177
store i8 %173, i8* %178
%179 = load i8*, i8** %16
%180 = load i32, i32* %19
%181 = zext i32 %180 to i64
%182 = getelementptr inbounds i8, i8* %179, i64 %181
%183 = load i8, i8* %182
%184 = load i8*, i8** %16
%185 = load i32, i32* %19
%186 = add i32 %185, 1
%187 = zext i32 %186 to i64
%188 = getelementptr inbounds i8, i8* %184, i64 %187
store i8 %183, i8* %188
%189 = load i8*, i8** %16
%190 = load i32, i32* %19
%191 = zext i32 %190 to i64
%192 = getelementptr inbounds i8, i8* %189, i64 %191
store i8 -1, i8* %192
br label %193
193: ; preds = %156
%194 = load i32, i32* %17
%195 = add i32 %194, 1
store i32 %195, i32* %17
br label %133
196: ; preds = %133
%197 = load i32, i32* %14
%198 = mul i32 %197, 3
%199 = urem i32 %198, 4
%200 = sub i32 4, %199
%201 = urem i32 %200, 4
store i32 %201, i32* %20
%202 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 0
%203 = load i32, i32* %20
%204 = load i32*, i32** %10
%205 = call i32 @fread(i8* %202, i32 1, i32 %203, i32* %204)
%206 = load i32, i32* %20
%207 = icmp ne i32 %205, %206
br i1 %207, label %208, label %213
208: ; preds = %196
%209 = load i8*, i8** %16
%210 = call i32 @free(i8* %209)
%211 = load i32*, i32** %10
%212 = call i32 @fclose(i32* %211)
store i32 4, i32* %5
br label %227
213: ; preds = %196
br label %214
214: ; preds = %213
%215 = load i32, i32* %18
%216 = add i32 %215, -1
store i32 %216, i32* %18
br label %129
217: ; preds = %129
br label %218
218: ; preds = %217, %111, %72
%219 = load i32, i32* %14
%220 = load i32*, i32** %8
store i32 %219, i32* %220
%221 = load i32, i32* %15
%222 = load i32*, i32** %9
store i32 %221, i32* %222
%223 = load i8*, i8** %16
%224 = load i8**, i8*** %7
store i8* %223, i8** %224
%225 = load i32*, i32** %10
%226 = call i32 @fclose(i32* %225)
store i32 0, i32* %5
br label %227
227: ; preds = %218, %208, %151, %123, %69, %56, %43, %35, %25
%228 = load i32, i32* %5
ret i32 %228
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i32 @loadbmp_decode_file(i8* nocapture %0, i8** nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = alloca [14 x i8]
%6 = alloca [40 x i8]
%7 = alloca [3 x 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 %123, label %10
10: ; preds = %4
%11 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%14 = call i32 @memset(i8* %11, i32 0, i32 14)
%15 = call i32 @memset(i8* %12, i32 0, i32 40)
%16 = call i32 @fread(i8* %11, i32 14, i32 1, i32* %8)
%17 = icmp eq i32 %16, 0
br i1 %17, label %120, label %18
18: ; preds = %10
%19 = call i32 @fread(i8* %12, i32 40, i32 1, i32* %8)
%20 = icmp eq i32 %19, 0
br i1 %20, label %120, label %21
21: ; preds = %18
%22 = load i8, i8* %11
%23 = icmp ne i8 %22, 66
%24 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 1
%25 = load i8, i8* %24
%26 = icmp ne i8 %25, 77
%27 = select i1 %23, i1 true, i1 %26
br i1 %27, label %120, label %28
28: ; preds = %21
%29 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 14
%30 = load i8, i8* %29
switch i8 %30, label %120 [
i8 32, label %31
i8 24, label %31
]
31: ; preds = %28, %28
%32 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 4
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 5
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = shl nuw nsw i32 %37, 8
%39 = or i32 %38, %34
%40 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 6
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = shl nuw nsw i32 %42, 16
%44 = or i32 %39, %43
%45 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 7
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = shl nuw i32 %47, 24
%49 = or i32 %44, %48
%50 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 8
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 9
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = shl nuw nsw i32 %55, 8
%57 = or i32 %56, %52
%58 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 10
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
%61 = shl nuw nsw i32 %60, 16
%62 = or i32 %57, %61
%63 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 11
%64 = load i8, i8* %63
%65 = zext i8 %64 to i32
%66 = shl nuw i32 %65, 24
%67 = or i32 %62, %66
%68 = icmp ne i32 %49, 0
%69 = icmp ne i32 %67, 0
%70 = select i1 %68, i1 %69, i1 false
br i1 %70, label %71, label %118
71: ; preds = %31
%72 = shl i32 %49, 2
%73 = mul i32 %72, %67
%74 = call i64 @malloc(i32 %73)
%75 = inttoptr i64 %74 to i8*
%76 = icmp eq i64 %74, 0
br i1 %76, label %120, label %77
77: ; preds = %71
%78 = mul i32 %49, -3
%79 = and i32 %78, 3
%80 = zext i32 %49 to i64
br label %81
81: ; preds = %77, %113
%82 = phi i32 [ %83, %113 ], [ %67, %77 ]
%83 = add i32 %82, -1
%84 = icmp eq i32 %82, 0
br i1 %84, label %118, label %85
85: ; preds = %81
%86 = mul i32 %83, %49
br label %87
87: ; preds = %85, %98
%88 = phi i64 [ 0, %85 ], [ %111, %98 ]
%89 = trunc i64 %88 to i32
%90 = add i32 %86, %89
%91 = shl i32 %90, 2
%92 = zext i32 %91 to i64
%93 = getelementptr inbounds i8, i8* %75, i64 %92
%94 = call i32 @fread(i8* %93, i32 3, i32 1, i32* %8)
%95 = icmp eq i32 %94, 0
br i1 %95, label %96, label %98
96: ; preds = %87
%97 = call i32 @free(i8* %75)
br label %120
98: ; preds = %87
%99 = or i32 %91, 2
%100 = zext i32 %99 to i64
%101 = getelementptr inbounds i8, i8* %75, i64 %100
%102 = load i8, i8* %101
%103 = or i32 %91, 3
%104 = zext i32 %103 to i64
%105 = getelementptr inbounds i8, i8* %75, i64 %104
store i8 %102, i8* %105
%106 = or i32 %91, 1
%107 = zext i32 %106 to i64
%108 = getelementptr inbounds i8, i8* %75, i64 %107
%109 = load i8, i8* %108
store i8 %109, i8* %101
%110 = load i8, i8* %93
store i8 %110, i8* %108
store i8 -1, i8* %93
%111 = add nuw nsw i64 %88, 1
%112 = icmp eq i64 %111, %80
br i1 %112, label %113, label %87
113: ; preds = %98
%114 = call i32 @fread(i8* %13, i32 1, i32 %79, i32* %8)
%115 = icmp eq i32 %114, %79
br i1 %115, label %81, label %116
116: ; preds = %113
%117 = call i32 @free(i8* %75)
br label %120
118: ; preds = %81, %31
%119 = phi i8* [ null, %31 ], [ %75, %81 ]
store i32 %49, i32* %2
store i32 %67, i32* %3
store i8* %119, i8** %1
br label %120
120: ; preds = %71, %28, %21, %18, %10, %118, %116, %96
%121 = phi i32 [ 4, %96 ], [ 4, %116 ], [ 0, %118 ], [ 4, %10 ], [ 4, %18 ], [ 5, %21 ], [ 6, %28 ], [ 1, %71 ]
%122 = call i32 @fclose(i32* %8)
br label %123
123: ; preds = %4, %120
%124 = phi i32 [ %121, %120 ], [ 2, %4 ]
ret i32 %124
}