#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 GL_RGB;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
unsigned char *malloc(int);
int /*<<< orphan*/ stderr;
int bmp_load(char *name, int *dx, int *dy, int *bpp, unsigned char **o) {
  unsigned char *c, tmp[4];
  int i, os;
  FILE *f;
  if (name == NULL || dx == NULL || dy == NULL || bpp == NULL || o == NULL)
    return 0;
  *o = NULL;
  *bpp = GL_RGB;
  f = fopen(name, "rb");
  if (f == NULL) {
    fprintf(stderr, "BMP_LOAD: Could not open file \"%s\" for reading.\n",
            name);
    return 0;
  }
  fscanf(f, "%c%c", &tmp[0], &tmp[1]);
  if (tmp[0] != 'B' || tmp[1] != 'M') {
    fprintf(stderr, "BMP_LOAD: File \"%s\" is not a BMP image.\n", name);
    fclose(f);
    return 0;
  }
  fscanf(f, "%*c%*c%*c%*c%*c%*c%*c%*c");
  {
    c = (unsigned char *)&i;
    fscanf(f, "%c%c%c%c", &c[0], &c[1], &c[2], &c[3]);
  };
  os = i - (2 + 8 + 4) - (3 * 4 + 2 * 2);
  fscanf(f, "%*c%*c%*c%*c");
  {
    c = (unsigned char *)&i;
    fscanf(f, "%c%c%c%c", &c[0], &c[1], &c[2], &c[3]);
  };
  *dx = i;
  {
    c = (unsigned char *)&i;
    fscanf(f, "%c%c%c%c", &c[0], &c[1], &c[2], &c[3]);
  };
  *dy = i;
  fscanf(f, "%*c%*c");
  {
    c = (unsigned char *)&i;
    fscanf(f, "%c%c", &c[0], &c[1]);
    c[2] = c[3] = 0;
  };
  if (i != 24) {
    fprintf(stderr,
            "BMP_LOAD: Only 24bit images are supported. File \"%s\" has %d "
            "bits per pixel.\n",
            name, i);
    fclose(f);
    return 0;
  }
  while (os > 0) {
    fscanf(f, "%*c");
    os--;
  }
  *o = malloc((*dx) * (*dy) * 3);
  if (*o == NULL) {
    fprintf(stderr, "BMP_LOAD: Out of memory error.\n");
    fclose(f);
    return 0;
  }
  for (i = 0; i < (*dx) * (*dy) * 3; i += 3) {
    fscanf(f, "%c%c%c", &tmp[0], &tmp[1], &tmp[2]);
    (*o)[i + 0] = tmp[2];
    (*o)[i + 1] = tmp[1];
    (*o)[i + 2] = tmp[0];
  }
  fclose(f);
  return 1;
}


x86 assembly (clang, -O0):
<bmp_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a3 <bmp_load+0x53>
cmpq   $0x0,-0x18(%rbp)
je     11a3 <bmp_load+0x53>
cmpq   $0x0,-0x20(%rbp)
je     11a3 <bmp_load+0x53>
cmpq   $0x0,-0x28(%rbp)
je     11a3 <bmp_load+0x53>
cmpq   $0x0,-0x30(%rbp)
jne    11af <bmp_load+0x5f>
movl   $0x0,-0x4(%rbp)
jmp    1510 <bmp_load+0x3c0>
mov    -0x30(%rbp),%rax
movq   $0x0,(%rax)
mov    0x2e2f(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    120f <bmp_load+0xbf>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1510 <bmp_load+0x3c0>
mov    -0x50(%rbp),%rdi
lea    -0x3c(%rbp),%rdx
lea    -0x3c(%rbp),%rcx
add    $0x1,%rcx
lea    0xe54(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
movzbl -0x3c(%rbp),%eax
cmp    $0x42,%eax
jne    1247 <bmp_load+0xf7>
movzbl -0x3b(%rbp),%eax
cmp    $0x4d,%eax
je     1277 <bmp_load+0x127>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x50(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1510 <bmp_load+0x3c0>
mov    -0x50(%rbp),%rdi
lea    0xddb(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
lea    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x38(%rbp),%rcx
add    $0x1,%rcx
mov    -0x38(%rbp),%r8
add    $0x2,%r8
mov    -0x38(%rbp),%r9
add    $0x3,%r9
lea    0xdbe(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x40(%rbp),%eax
sub    $0xe,%eax
sub    $0x10,%eax
mov    %eax,-0x44(%rbp)
mov    -0x50(%rbp),%rdi
lea    0xd93(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
lea    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x38(%rbp),%rcx
add    $0x1,%rcx
mov    -0x38(%rbp),%r8
add    $0x2,%r8
mov    -0x38(%rbp),%r9
add    $0x3,%r9
lea    0xd6a(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x40(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x38(%rbp),%rcx
add    $0x1,%rcx
mov    -0x38(%rbp),%r8
add    $0x2,%r8
mov    -0x38(%rbp),%r9
add    $0x3,%r9
lea    0xd2b(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x40(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x50(%rbp),%rdi
lea    0xd09(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
lea    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x38(%rbp),%rcx
add    $0x1,%rcx
lea    0xcee(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x38(%rbp),%rax
movb   $0x0,0x3(%rax)
mov    -0x38(%rbp),%rax
movb   $0x0,0x2(%rax)
cmpl   $0x18,-0x40(%rbp)
je     13e0 <bmp_load+0x290>
mov    0x2c24(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x40(%rbp),%ecx
lea    0xcbb(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x50(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1510 <bmp_load+0x3c0>
jmp    13e5 <bmp_load+0x295>
cmpl   $0x0,-0x44(%rbp)
jle    140f <bmp_load+0x2bf>
mov    -0x50(%rbp),%rdi
lea    0xc78(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x44(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x44(%rbp)
jmp    13e5 <bmp_load+0x295>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x20(%rbp),%rcx
imul   (%rcx),%eax
imul   $0x3,%eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1468 <bmp_load+0x318>
mov    0x2b95(%rip),%rax
mov    (%rax),%edi
lea    0xc80(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x50(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1510 <bmp_load+0x3c0>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%ecx
mov    -0x20(%rbp),%rdx
imul   (%rdx),%ecx
imul   $0x3,%ecx,%ecx
cmp    %ecx,%eax
jge    1500 <bmp_load+0x3b0>
mov    -0x50(%rbp),%rdi
lea    -0x3c(%rbp),%rdx
lea    -0x3c(%rbp),%rcx
add    $0x1,%rcx
lea    -0x3c(%rbp),%r8
add    $0x2,%r8
lea    0xbcf(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x3a(%rbp),%dl
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    -0x40(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x3b(%rbp),%dl
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    -0x40(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x3c(%rbp),%dl
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    -0x40(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x40(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x40(%rbp)
jmp    146f <bmp_load+0x31f>
mov    -0x50(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bmp_load>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %r12d,%r12d
test   %rdi,%rdi
je     144c <bmp_load+0x2fc>
mov    %rsi,%rbp
test   %rsi,%rsi
je     144c <bmp_load+0x2fc>
mov    %rdx,%r15
test   %rdx,%rdx
je     144c <bmp_load+0x2fc>
test   %rcx,%rcx
je     144c <bmp_load+0x2fc>
mov    %r8,%rbx
test   %r8,%r8
je     144c <bmp_load+0x2fc>
mov    %rdi,%r13
movq   $0x0,(%rbx)
mov    0x2e48(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rcx)
lea    0xe4d(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     13d3 <bmp_load+0x283>
mov    %rax,%r14
lea    0x5(%rsp),%rcx
lea    0xeaa(%rip),%rsi
xor    %r12d,%r12d
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1040 <fscanf@plt>
cmpb   $0x42,0x4(%rsp)
jne    13f2 <bmp_load+0x2a2>
cmpb   $0x4d,0x5(%rsp)
jne    13f2 <bmp_load+0x2a2>
lea    0xe5e(%rip),%rsi
xor    %r12d,%r12d
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <fscanf@plt>
lea    0x1(%rsp),%rcx
lea    0x2(%rsp),%r8
lea    0x3(%rsp),%r9
lea    0xe54(%rip),%rsi
mov    %rsp,%rdx
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <fscanf@plt>
mov    %r15,0x10(%rsp)
mov    (%rsp),%r15d
lea    0xe2a(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <fscanf@plt>
mov    %r14,%rdi
lea    0xe23(%rip),%rsi
mov    %rsp,%rdx
lea    0x1(%rsp),%rcx
lea    0x2(%rsp),%r8
lea    0x3(%rsp),%r9
xor    %eax,%eax
call   1040 <fscanf@plt>
mov    (%rsp),%eax
mov    %rbp,0x8(%rsp)
mov    %eax,0x0(%rbp)
mov    %r14,%rdi
lea    0xdf5(%rip),%rsi
mov    %rsp,%rdx
lea    0x1(%rsp),%rbp
mov    %rbp,%rcx
lea    0x2(%rsp),%r8
lea    0x3(%rsp),%r9
xor    %eax,%eax
call   1040 <fscanf@plt>
mov    (%rsp),%eax
mov    0x10(%rsp),%rcx
mov    %eax,(%rcx)
lea    0xdc1(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <fscanf@plt>
lea    0xdbb(%rip),%rsi
mov    %r14,%rdi
mov    %rsp,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1040 <fscanf@plt>
movw   $0x0,0x2(%rsp)
mov    (%rsp),%ecx
cmp    $0x18,%ecx
jne    140e <bmp_load+0x2be>
cmp    $0x1f,%r15d
jl     1317 <bmp_load+0x1c7>
add    $0xffffffe3,%r15d
lea    0xd7f(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <fscanf@plt>
add    $0xffffffff,%r15d
cmp    $0x1,%r15d
ja     1300 <bmp_load+0x1b0>
mov    0x8(%rsp),%rax
mov    (%rax),%eax
mov    0x10(%rsp),%r12
imul   (%r12),%eax
lea    (%rax,%rax,2),%r15d
mov    %r15d,%edi
call   1060 <malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     142a <bmp_load+0x2da>
movl   $0x0,(%rsp)
test   %r15d,%r15d
mov    0x8(%rsp),%rbp
lea    0x5(%rsp),%r15
jle    13c3 <bmp_load+0x273>
lea    0x4(%rsp),%r13
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
lea    0xd0e(%rip),%rsi
mov    %r13,%rdx
mov    %r15,%rcx
lea    0x6(%rsp),%r8
xor    %eax,%eax
call   1040 <fscanf@plt>
movzbl 0x6(%rsp),%eax
mov    (%rbx),%rcx
movslq (%rsp),%rdx
mov    %al,(%rcx,%rdx,1)
movzbl 0x5(%rsp),%eax
mov    (%rbx),%rcx
movslq (%rsp),%rdx
mov    %al,0x1(%rdx,%rcx,1)
movzbl 0x4(%rsp),%eax
mov    (%rbx),%rcx
movslq (%rsp),%rdx
mov    %al,0x2(%rdx,%rcx,1)
mov    (%rsp),%eax
add    $0x3,%eax
mov    %eax,(%rsp)
mov    0x0(%rbp),%ecx
imul   (%r12),%ecx
lea    (%rcx,%rcx,2),%ecx
cmp    %ecx,%eax
jl     1360 <bmp_load+0x210>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    $0x1,%r12d
jmp    144c <bmp_load+0x2fc>
mov    0x2bfe(%rip),%rax
mov    (%rax),%edi
lea    0xc20(%rip),%rsi
xor    %r12d,%r12d
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    144c <bmp_load+0x2fc>
mov    0x2bdf(%rip),%rax
mov    (%rax),%edi
lea    0xc32(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1444 <bmp_load+0x2f4>
mov    0x2bc3(%rip),%rax
mov    (%rax),%edi
lea    0xc61(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1444 <bmp_load+0x2f4>
mov    0x2ba7(%rip),%rax
mov    (%rax),%edi
lea    0xc92(%rip),%rsi
xor    %r12d,%r12d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@GL_RGB = global i32 0
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [49 x i8] c"BMP_LOAD: Could not open file \22%s\22 for reading.\0A\00"
@.str.2 = [5 x i8] c"%c%c\00"
@.str.3 = [41 x i8] c"BMP_LOAD: File \22%s\22 is not a BMP image.\0A\00"
@.str.4 = [25 x i8] c"%*c%*c%*c%*c%*c%*c%*c%*c\00"
@.str.5 = [9 x i8] c"%c%c%c%c\00"
@.str.6 = [13 x i8] c"%*c%*c%*c%*c\00"
@.str.7 = [7 x i8] c"%*c%*c\00"
@.str.8 = [77 x i8] c"BMP_LOAD: Only 24bit images are supported. File \22%s\22 has %d bits per pixel.\0A\00"
@.str.9 = [4 x i8] c"%*c\00"
@.str.10 = [32 x i8] c"BMP_LOAD: Out of memory error.\0A\00"
@.str.11 = [7 x i8] c"%c%c%c\00"
define i32 @bmp_load(i8* %0, i32* %1, i32* %2, i32* %3, i8** %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i8**
%12 = alloca i8*
%13 = alloca [4 x i8]
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32*
store i8* %0, i8** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i8** %4, i8*** %11
%17 = load i8*, i8** %7
%18 = icmp eq i8* %17, null
br i1 %18, label %31, label %19
19: ; preds = %5
%20 = load i32*, i32** %8
%21 = icmp eq i32* %20, null
br i1 %21, label %31, label %22
22: ; preds = %19
%23 = load i32*, i32** %9
%24 = icmp eq i32* %23, null
br i1 %24, label %31, label %25
25: ; preds = %22
%26 = load i32*, i32** %10
%27 = icmp eq i32* %26, null
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = load i8**, i8*** %11
%30 = icmp eq i8** %29, null
br i1 %30, label %31, label %32
31: ; preds = %28, %25, %22, %19, %5
store i32 0, i32* %6
br label %203
32: ; preds = %28
%33 = load i8**, i8*** %11
store i8* null, i8** %33
%34 = load i32, i32* @GL_RGB
%35 = load i32*, i32** %10
store i32 %34, i32* %35
%36 = load i8*, i8** %7
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %37, i32** %16
%38 = load i32*, i32** %16
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %44
40: ; preds = %32
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %7
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i8* %42)
store i32 0, i32* %6
br label %203
44: ; preds = %32
%45 = load i32*, i32** %16
%46 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 0
%47 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 1
%48 = call i32 (i32*, i8*, ...) @fscanf(i32* %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %46, i8* %47)
%49 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 0
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = icmp ne i32 %51, 66
br i1 %52, label %58, label %53
53: ; preds = %44
%54 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 1
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = icmp ne i32 %56, 77
br i1 %57, label %58, label %64
58: ; preds = %53, %44
%59 = load i32, i32* @stderr
%60 = load i8*, i8** %7
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %60)
%62 = load i32*, i32** %16
%63 = call i32 @fclose(i32* %62)
store i32 0, i32* %6
br label %203
64: ; preds = %53
%65 = load i32*, i32** %16
%66 = call i32 (i32*, i8*, ...) @fscanf(i32* %65, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%67 = bitcast i32* %14 to i8*
store i8* %67, i8** %12
%68 = load i32*, i32** %16
%69 = load i8*, i8** %12
%70 = getelementptr inbounds i8, i8* %69, i64 0
%71 = load i8*, i8** %12
%72 = getelementptr inbounds i8, i8* %71, i64 1
%73 = load i8*, i8** %12
%74 = getelementptr inbounds i8, i8* %73, i64 2
%75 = load i8*, i8** %12
%76 = getelementptr inbounds i8, i8* %75, i64 3
%77 = call i32 (i32*, i8*, ...) @fscanf(i32* %68, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %70, i8* %72, i8* %74, i8* %76)
%78 = load i32, i32* %14
%79 = sub nsw i32 %78, 14
%80 = sub nsw i32 %79, 16
store i32 %80, i32* %15
%81 = load i32*, i32** %16
%82 = call i32 (i32*, i8*, ...) @fscanf(i32* %81, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%83 = bitcast i32* %14 to i8*
store i8* %83, i8** %12
%84 = load i32*, i32** %16
%85 = load i8*, i8** %12
%86 = getelementptr inbounds i8, i8* %85, i64 0
%87 = load i8*, i8** %12
%88 = getelementptr inbounds i8, i8* %87, i64 1
%89 = load i8*, i8** %12
%90 = getelementptr inbounds i8, i8* %89, i64 2
%91 = load i8*, i8** %12
%92 = getelementptr inbounds i8, i8* %91, i64 3
%93 = call i32 (i32*, i8*, ...) @fscanf(i32* %84, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %86, i8* %88, i8* %90, i8* %92)
%94 = load i32, i32* %14
%95 = load i32*, i32** %8
store i32 %94, i32* %95
%96 = bitcast i32* %14 to i8*
store i8* %96, i8** %12
%97 = load i32*, i32** %16
%98 = load i8*, i8** %12
%99 = getelementptr inbounds i8, i8* %98, i64 0
%100 = load i8*, i8** %12
%101 = getelementptr inbounds i8, i8* %100, i64 1
%102 = load i8*, i8** %12
%103 = getelementptr inbounds i8, i8* %102, i64 2
%104 = load i8*, i8** %12
%105 = getelementptr inbounds i8, i8* %104, i64 3
%106 = call i32 (i32*, i8*, ...) @fscanf(i32* %97, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %99, i8* %101, i8* %103, i8* %105)
%107 = load i32, i32* %14
%108 = load i32*, i32** %9
store i32 %107, i32* %108
%109 = load i32*, i32** %16
%110 = call i32 (i32*, i8*, ...) @fscanf(i32* %109, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%111 = bitcast i32* %14 to i8*
store i8* %111, i8** %12
%112 = load i32*, i32** %16
%113 = load i8*, i8** %12
%114 = getelementptr inbounds i8, i8* %113, i64 0
%115 = load i8*, i8** %12
%116 = getelementptr inbounds i8, i8* %115, i64 1
%117 = call i32 (i32*, i8*, ...) @fscanf(i32* %112, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %114, i8* %116)
%118 = load i8*, i8** %12
%119 = getelementptr inbounds i8, i8* %118, i64 3
store i8 0, i8* %119
%120 = load i8*, i8** %12
%121 = getelementptr inbounds i8, i8* %120, i64 2
store i8 0, i8* %121
%122 = load i32, i32* %14
%123 = icmp ne i32 %122, 24
br i1 %123, label %124, label %131
124: ; preds = %64
%125 = load i32, i32* @stderr
%126 = load i8*, i8** %7
%127 = load i32, i32* %14
%128 = call i32 (i32, i8*, ...) @fprintf(i32 %125, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.8, i64 0, i64 0), i8* %126, i32 %127)
%129 = load i32*, i32** %16
%130 = call i32 @fclose(i32* %129)
store i32 0, i32* %6
br label %203
131: ; preds = %64
br label %132
132: ; preds = %135, %131
%133 = load i32, i32* %15
%134 = icmp sgt i32 %133, 0
br i1 %134, label %135, label %140
135: ; preds = %132
%136 = load i32*, i32** %16
%137 = call i32 (i32*, i8*, ...) @fscanf(i32* %136, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%138 = load i32, i32* %15
%139 = add nsw i32 %138, -1
store i32 %139, i32* %15
br label %132
140: ; preds = %132
%141 = load i32*, i32** %8
%142 = load i32, i32* %141
%143 = load i32*, i32** %9
%144 = load i32, i32* %143
%145 = mul nsw i32 %142, %144
%146 = mul nsw i32 %145, 3
%147 = call i8* @malloc(i32 %146)
%148 = load i8**, i8*** %11
store i8* %147, i8** %148
%149 = load i8**, i8*** %11
%150 = load i8*, i8** %149
%151 = icmp eq i8* %150, null
br i1 %151, label %152, label %157
152: ; preds = %140
%153 = load i32, i32* @stderr
%154 = call i32 (i32, i8*, ...) @fprintf(i32 %153, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0))
%155 = load i32*, i32** %16
%156 = call i32 @fclose(i32* %155)
store i32 0, i32* %6
br label %203
157: ; preds = %140
store i32 0, i32* %14
br label %158
158: ; preds = %197, %157
%159 = load i32, i32* %14
%160 = load i32*, i32** %8
%161 = load i32, i32* %160
%162 = load i32*, i32** %9
%163 = load i32, i32* %162
%164 = mul nsw i32 %161, %163
%165 = mul nsw i32 %164, 3
%166 = icmp slt i32 %159, %165
br i1 %166, label %167, label %200
167: ; preds = %158
%168 = load i32*, i32** %16
%169 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 0
%170 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 1
%171 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 2
%172 = call i32 (i32*, i8*, ...) @fscanf(i32* %168, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* %169, i8* %170, i8* %171)
%173 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 2
%174 = load i8, i8* %173
%175 = load i8**, i8*** %11
%176 = load i8*, i8** %175
%177 = load i32, i32* %14
%178 = add nsw i32 %177, 0
%179 = sext i32 %178 to i64
%180 = getelementptr inbounds i8, i8* %176, i64 %179
store i8 %174, i8* %180
%181 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 1
%182 = load i8, i8* %181
%183 = load i8**, i8*** %11
%184 = load i8*, i8** %183
%185 = load i32, i32* %14
%186 = add nsw i32 %185, 1
%187 = sext i32 %186 to i64
%188 = getelementptr inbounds i8, i8* %184, i64 %187
store i8 %182, i8* %188
%189 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 0
%190 = load i8, i8* %189
%191 = load i8**, i8*** %11
%192 = load i8*, i8** %191
%193 = load i32, i32* %14
%194 = add nsw i32 %193, 2
%195 = sext i32 %194 to i64
%196 = getelementptr inbounds i8, i8* %192, i64 %195
store i8 %190, i8* %196
br label %197
197: ; preds = %167
%198 = load i32, i32* %14
%199 = add nsw i32 %198, 3
store i32 %199, i32* %14
br label %158
200: ; preds = %158
%201 = load i32*, i32** %16
%202 = call i32 @fclose(i32* %201)
store i32 1, i32* %6
br label %203
203: ; preds = %200, %152, %124, %58, %40, %31
%204 = load i32, i32* %6
ret i32 %204
}

LLVM IR (-O2):
@GL_RGB = global i32 0
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [49 x i8] c"BMP_LOAD: Could not open file \22%s\22 for reading.\0A\00"
@.str.2 = [5 x i8] c"%c%c\00"
@.str.3 = [41 x i8] c"BMP_LOAD: File \22%s\22 is not a BMP image.\0A\00"
@.str.4 = [25 x i8] c"%*c%*c%*c%*c%*c%*c%*c%*c\00"
@.str.5 = [9 x i8] c"%c%c%c%c\00"
@.str.6 = [13 x i8] c"%*c%*c%*c%*c\00"
@.str.7 = [7 x i8] c"%*c%*c\00"
@.str.8 = [77 x i8] c"BMP_LOAD: Only 24bit images are supported. File \22%s\22 has %d bits per pixel.\0A\00"
@.str.9 = [4 x i8] c"%*c\00"
@.str.10 = [32 x i8] c"BMP_LOAD: Out of memory error.\0A\00"
@.str.11 = [7 x i8] c"%c%c%c\00"
define i32 @bmp_load(i8* %0, i32* %1, i32* %2, i32* writeonly %3, i8** %4) {
%6 = alloca [4 x i8]
%7 = alloca i32
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%9 = bitcast i32* %7 to i8*
%10 = icmp eq i8* %0, null
%11 = icmp eq i32* %1, null
%12 = or i1 %10, %11
%13 = icmp eq i32* %2, null
%14 = or i1 %12, %13
%15 = icmp eq i32* %3, null
%16 = or i1 %14, %15
%17 = icmp eq i8** %4, null
%18 = or i1 %16, %17
br i1 %18, label %110, label %19
19: ; preds = %5
store i8* null, i8** %4
%20 = load i32, i32* @GL_RGB
store i32 %20, i32* %3
%21 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %110
26: ; preds = %19
%27 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 1
%28 = call i32 (i32*, i8*, ...) @fscanf(i32* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %8, i8* %27)
%29 = load i8, i8* %8
%30 = icmp ne i8 %29, 66
%31 = load i8, i8* %27
%32 = icmp ne i8 %31, 77
%33 = select i1 %30, i1 true, i1 %32
br i1 %33, label %34, label %38
34: ; preds = %26
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%37 = call i32 @fclose(i32* %21)
br label %110
38: ; preds = %26
%39 = call i32 (i32*, i8*, ...) @fscanf(i32* %21, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%40 = getelementptr inbounds i8, i8* %9, i64 1
%41 = getelementptr inbounds i8, i8* %9, i64 2
%42 = getelementptr inbounds i8, i8* %9, i64 3
%43 = call i32 (i32*, i8*, ...) @fscanf(i32* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32* %7, i8* %40, i8* %41, i8* %42)
%44 = load i32, i32* %7
%45 = call i32 (i32*, i8*, ...) @fscanf(i32* %21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%46 = call i32 (i32*, i8*, ...) @fscanf(i32* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32* %7, i8* %40, i8* %41, i8* %42)
%47 = load i32, i32* %7
store i32 %47, i32* %1
%48 = call i32 (i32*, i8*, ...) @fscanf(i32* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32* %7, i8* %40, i8* %41, i8* %42)
%49 = load i32, i32* %7
store i32 %49, i32* %2
%50 = call i32 (i32*, i8*, ...) @fscanf(i32* %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%51 = call i32 (i32*, i8*, ...) @fscanf(i32* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %7, i8* %40)
store i8 0, i8* %42
store i8 0, i8* %41
%52 = load i32, i32* %7
%53 = icmp eq i32 %52, 24
br i1 %53, label %54, label %58
54: ; preds = %38
%55 = icmp sgt i32 %44, 30
br i1 %55, label %56, label %67
56: ; preds = %54
%57 = add nsw i32 %44, -30
br label %62
58: ; preds = %38
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.8, i64 0, i64 0), i8* %0, i32 %52)
%61 = call i32 @fclose(i32* %21)
br label %110
62: ; preds = %56, %62
%63 = phi i32 [ %65, %62 ], [ %57, %56 ]
%64 = call i32 (i32*, i8*, ...) @fscanf(i32* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%65 = add nsw i32 %63, -1
%66 = icmp ugt i32 %63, 1
br i1 %66, label %62, label %67
67: ; preds = %62, %54
%68 = load i32, i32* %1
%69 = load i32, i32* %2
%70 = mul i32 %68, 3
%71 = mul i32 %70, %69
%72 = call i8* @malloc(i32 %71)
store i8* %72, i8** %4
%73 = icmp eq i8* %72, null
br i1 %73, label %78, label %74
74: ; preds = %67
store i32 0, i32* %7
%75 = icmp sgt i32 %71, 0
br i1 %75, label %76, label %108
76: ; preds = %74
%77 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 2
br label %82
78: ; preds = %67
%79 = load i32, i32* @stderr
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0))
%81 = call i32 @fclose(i32* %21)
br label %110
82: ; preds = %76, %82
%83 = call i32 (i32*, i8*, ...) @fscanf(i32* %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* %8, i8* %27, i8* %77)
%84 = load i8, i8* %77
%85 = load i8*, i8** %4
%86 = load i32, i32* %7
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8, i8* %85, i64 %87
store i8 %84, i8* %88
%89 = load i8, i8* %27
%90 = load i8*, i8** %4
%91 = load i32, i32* %7
%92 = add nsw i32 %91, 1
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8, i8* %90, i64 %93
store i8 %89, i8* %94
%95 = load i8, i8* %8
%96 = load i8*, i8** %4
%97 = load i32, i32* %7
%98 = add nsw i32 %97, 2
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds i8, i8* %96, i64 %99
store i8 %95, i8* %100
%101 = load i32, i32* %7
%102 = add nsw i32 %101, 3
store i32 %102, i32* %7
%103 = load i32, i32* %1
%104 = load i32, i32* %2
%105 = mul i32 %103, 3
%106 = mul i32 %105, %104
%107 = icmp slt i32 %102, %106
br i1 %107, label %82, label %108
108: ; preds = %82, %74
%109 = call i32 @fclose(i32* %21)
br label %110
110: ; preds = %5, %108, %78, %58, %34, %23
%111 = phi i32 [ 0, %23 ], [ 0, %34 ], [ 0, %58 ], [ 0, %78 ], [ 1, %108 ], [ 0, %5 ]
ret i32 %111
}