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

/* Variables and functions */
int /*<<< orphan*/ bwrite_endian(int, int, unsigned char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(unsigned char *, int, int);
int WriteBMP32(const char *fname, unsigned char (*data)[3], int w, int h) {
  FILE *fp = fopen(fname, "wb");
  int Endian = 1;
  unsigned char buffer[40];
  ulong fileSize;
  ulong imageSize;
  int x, y;
  if (!fp)
    return -1;
  imageSize = 4 * w * h;
  fileSize = 14 + 40 + imageSize;
  memset(buffer, 0x00, 14);
  buffer[0] = 66;
  buffer[1] = 77;
  bwrite_endian(fileSize, 4, buffer + 2, Endian);
  bwrite_endian(0, 4, buffer + 6, Endian);
  bwrite_endian(54, 4, buffer + 10, Endian);
  fwrite(buffer, 1, 14, fp);
  memset(buffer, 0x00, 40);
  bwrite_endian(40, 4, buffer + 0, Endian);
  bwrite_endian(w, 4, buffer + 4, Endian);
  bwrite_endian(h, 4, buffer + 8, Endian);
  bwrite_endian(1, 2, buffer + 12, Endian);
  bwrite_endian(32, 2, buffer + 14, Endian);
  bwrite_endian(0, 4, buffer + 16, Endian);
  bwrite_endian(imageSize, 4, buffer + 20, Endian);
  bwrite_endian(0x10000, 4, buffer + 24, Endian);
  bwrite_endian(0x10000, 4, buffer + 28, Endian);
  bwrite_endian(0x1000000, 4, buffer + 32, Endian);
  bwrite_endian(0, 4, buffer + 36, Endian);
  fwrite(buffer, 1, 40, fp);
  buffer[0] = 0;
  for (y = h - 1; y >= 0; --y) {
    for (x = 0; x < w; ++x) {
      fwrite(&data[x + y * w][2], 1, 1, fp);
      fwrite(&data[x + y * w][1], 1, 1, fp);
      fwrite(&data[x + y * w][0], 1, 1, fp);
      fwrite(buffer, 1, 1, fp);
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<WriteBMP32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1198 <WriteBMP32+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    144d <WriteBMP32+0x2fd>
mov    -0x1c(%rbp),%eax
shl    $0x2,%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
add    $0x36,%eax
mov    %eax,-0x64(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0xe,%edx
call   1050 <memset@plt>
movb   $0x42,-0x60(%rbp)
movb   $0x4d,-0x5f(%rbp)
mov    -0x64(%rbp),%edi
lea    -0x60(%rbp),%rdx
add    $0x2,%rdx
mov    -0x2c(%rbp),%ecx
mov    $0x4,%esi
call   1030 <bwrite_endian@plt>
lea    -0x60(%rbp),%rdx
add    $0x6,%rdx
mov    -0x2c(%rbp),%ecx
xor    %edi,%edi
mov    $0x4,%esi
call   1030 <bwrite_endian@plt>
lea    -0x60(%rbp),%rdx
add    $0xa,%rdx
mov    -0x2c(%rbp),%ecx
mov    $0x36,%edi
mov    $0x4,%esi
call   1030 <bwrite_endian@plt>
lea    -0x60(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0xe,%edx
call   1070 <fwrite@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
lea    -0x60(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
mov    $0x28,%edi
mov    $0x4,%esi
call   1030 <bwrite_endian@plt>
mov    -0x1c(%rbp),%edi
lea    -0x60(%rbp),%rdx
add    $0x4,%rdx
mov    -0x2c(%rbp),%ecx
mov    $0x4,%esi
call   1030 <bwrite_endian@plt>
mov    -0x20(%rbp),%edi
lea    -0x60(%rbp),%rdx
add    $0x8,%rdx
mov    -0x2c(%rbp),%ecx
mov    $0x4,%esi
call   1030 <bwrite_endian@plt>
lea    -0x60(%rbp),%rdx
add    $0xc,%rdx
mov    -0x2c(%rbp),%ecx
mov    $0x1,%edi
mov    $0x2,%esi
call   1030 <bwrite_endian@plt>
lea    -0x60(%rbp),%rdx
add    $0xe,%rdx
mov    -0x2c(%rbp),%ecx
mov    $0x20,%edi
mov    $0x2,%esi
call   1030 <bwrite_endian@plt>
lea    -0x60(%rbp),%rdx
add    $0x10,%rdx
mov    -0x2c(%rbp),%ecx
xor    %edi,%edi
mov    $0x4,%esi
call   1030 <bwrite_endian@plt>
mov    -0x68(%rbp),%edi
lea    -0x60(%rbp),%rdx
add    $0x14,%rdx
mov    -0x2c(%rbp),%ecx
mov    $0x4,%esi
call   1030 <bwrite_endian@plt>
lea    -0x60(%rbp),%rdx
add    $0x18,%rdx
mov    -0x2c(%rbp),%ecx
mov    $0x10000,%edi
mov    $0x4,%esi
call   1030 <bwrite_endian@plt>
lea    -0x60(%rbp),%rdx
add    $0x1c,%rdx
mov    -0x2c(%rbp),%ecx
mov    $0x10000,%edi
mov    $0x4,%esi
call   1030 <bwrite_endian@plt>
lea    -0x60(%rbp),%rdx
add    $0x20,%rdx
mov    -0x2c(%rbp),%ecx
mov    $0x1000000,%edi
mov    $0x4,%esi
call   1030 <bwrite_endian@plt>
lea    -0x60(%rbp),%rdx
add    $0x24,%rdx
mov    -0x2c(%rbp),%ecx
xor    %edi,%edi
mov    $0x4,%esi
call   1030 <bwrite_endian@plt>
lea    -0x60(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x28,%edx
call   1070 <fwrite@plt>
movb   $0x0,-0x60(%rbp)
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x70(%rbp)
cmpl   $0x0,-0x70(%rbp)
jl     143d <WriteBMP32+0x2ed>
movl   $0x0,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    142a <WriteBMP32+0x2da>
mov    -0x18(%rbp),%rdi
mov    -0x6c(%rbp),%eax
mov    -0x70(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
add    %ecx,%eax
cltq
imul   $0x3,%rax,%rax
add    %rax,%rdi
add    $0x2,%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%rdi
mov    -0x6c(%rbp),%eax
mov    -0x70(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
add    %ecx,%eax
cltq
imul   $0x3,%rax,%rax
add    %rax,%rdi
add    $0x1,%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%rdi
mov    -0x6c(%rbp),%eax
mov    -0x70(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
add    %ecx,%eax
cltq
imul   $0x3,%rax,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
lea    -0x60(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    1379 <WriteBMP32+0x229>
jmp    142f <WriteBMP32+0x2df>
mov    -0x70(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x70(%rbp)
jmp    1368 <WriteBMP32+0x218>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WriteBMP32>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %ecx,%r12d
mov    %edx,%r13d
mov    %rsi,%rbp
lea    0xe82(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     13fe <WriteBMP32+0x29e>
mov    %rax,%rbx
mov    %rbp,0x8(%rsp)
mov    %r13d,%eax
imul   %r12d,%eax
lea    0x36(,%rax,4),%r14d
mov    %eax,%r15d
shl    $0x2,%r15d
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xe,%edx
call   1050 <memset@plt>
movw   $0x4d42,0x10(%rsp)
lea    0x12(%rsp),%rdx
mov    %r14d,%edi
mov    $0x4,%esi
mov    $0x1,%ecx
call   1030 <bwrite_endian@plt>
lea    0x16(%rsp),%rdx
xor    %edi,%edi
mov    $0x4,%esi
mov    $0x1,%ecx
call   1030 <bwrite_endian@plt>
lea    0x1a(%rsp),%rdx
mov    $0x36,%edi
mov    $0x4,%esi
mov    $0x1,%ecx
call   1030 <bwrite_endian@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0xe,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
mov    $0x28,%edi
mov    $0x4,%esi
mov    %rbp,%rdx
mov    $0x1,%ecx
call   1030 <bwrite_endian@plt>
lea    0x14(%rsp),%rdx
mov    %r13d,%edi
mov    $0x4,%esi
mov    $0x1,%ecx
call   1030 <bwrite_endian@plt>
lea    0x18(%rsp),%rdx
mov    %r12d,%edi
mov    $0x4,%esi
mov    $0x1,%ecx
call   1030 <bwrite_endian@plt>
lea    0x1c(%rsp),%rdx
mov    $0x1,%edi
mov    $0x2,%esi
mov    $0x1,%ecx
call   1030 <bwrite_endian@plt>
lea    0x1e(%rsp),%rdx
mov    $0x20,%edi
mov    $0x2,%esi
mov    $0x1,%ecx
call   1030 <bwrite_endian@plt>
lea    0x20(%rsp),%rdx
xor    %edi,%edi
mov    $0x4,%esi
mov    $0x1,%ecx
call   1030 <bwrite_endian@plt>
lea    0x24(%rsp),%rdx
mov    %r15d,%edi
mov    $0x4,%esi
mov    $0x1,%ecx
call   1030 <bwrite_endian@plt>
lea    0x28(%rsp),%rdx
mov    $0x10000,%edi
mov    $0x4,%esi
mov    $0x1,%ecx
call   1030 <bwrite_endian@plt>
lea    0x2c(%rsp),%rdx
mov    $0x10000,%edi
mov    $0x4,%esi
mov    $0x1,%ecx
call   1030 <bwrite_endian@plt>
lea    0x30(%rsp),%rdx
mov    $0x1000000,%edi
mov    $0x4,%esi
mov    $0x1,%ecx
call   1030 <bwrite_endian@plt>
lea    0x34(%rsp),%rdx
xor    %edi,%edi
mov    $0x4,%esi
mov    $0x1,%ecx
call   1030 <bwrite_endian@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x28,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
movb   $0x0,0x10(%rsp)
test   %r12d,%r12d
jle    13f2 <WriteBMP32+0x292>
mov    %r12d,%r14d
movslq %r13d,%rax
mov    %r13d,%ecx
lea    -0x1(%r14),%rdx
imul   %rax,%rdx
lea    (%rdx,%rdx,2),%rdx
mov    0x8(%rsp),%rsi
lea    (%rsi,%rdx,1),%rbp
add    $0x2,%rbp
lea    (%rax,%rax,2),%rax
neg    %rax
mov    %rax,0x8(%rsp)
lea    (%rcx,%rcx,2),%r12
jmp    13a5 <WriteBMP32+0x245>
nopl   0x0(%rax,%rax,1)
lea    -0x1(%r14),%rax
add    0x8(%rsp),%rbp
cmp    $0x2,%r14
mov    %rax,%r14
mov    %r15d,%r13d
jl     13f2 <WriteBMP32+0x292>
mov    %r13d,%r15d
test   %r13d,%r13d
jle    1390 <WriteBMP32+0x230>
xor    %r13d,%r13d
movsbl 0x0(%rbp,%r13,1),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl -0x1(%rbp,%r13,1),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl -0x2(%rbp,%r13,1),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0x10(%rsp),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
add    $0x3,%r13
cmp    %r13,%r12
jne    13b0 <WriteBMP32+0x250>
jmp    1390 <WriteBMP32+0x230>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1403 <WriteBMP32+0x2a3>
mov    $0xffffffff,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
define i32 @WriteBMP32(i8* %0, [3 x i8]* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [3 x i8]*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca [40 x i8]
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i8* %0, i8** %6
store [3 x i8]* %1, [3 x i8]** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%17 = load i8*, i8** %6
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %10
store i32 1, i32* %11
%19 = load i32*, i32** %10
%20 = icmp ne i32* %19, null
br i1 %20, label %22, label %21
21: ; preds = %4
store i32 -1, i32* %5
br label %159
22: ; preds = %4
%23 = load i32, i32* %8
%24 = mul nsw i32 4, %23
%25 = load i32, i32* %9
%26 = mul nsw i32 %24, %25
store i32 %26, i32* %14
%27 = load i32, i32* %14
%28 = add nsw i32 54, %27
store i32 %28, i32* %13
%29 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
%30 = call i32 @memset(i8* %29, i32 0, i32 14)
%31 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
store i8 66, i8* %31
%32 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 1
store i8 77, i8* %32
%33 = load i32, i32* %13
%34 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
%35 = getelementptr inbounds i8, i8* %34, i64 2
%36 = load i32, i32* %11
%37 = call i32 @bwrite_endian(i32 %33, i32 4, i8* %35, i32 %36)
%38 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
%39 = getelementptr inbounds i8, i8* %38, i64 6
%40 = load i32, i32* %11
%41 = call i32 @bwrite_endian(i32 0, i32 4, i8* %39, i32 %40)
%42 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
%43 = getelementptr inbounds i8, i8* %42, i64 10
%44 = load i32, i32* %11
%45 = call i32 @bwrite_endian(i32 54, i32 4, i8* %43, i32 %44)
%46 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
%47 = load i32*, i32** %10
%48 = call i32 @fwrite(i8* %46, i32 1, i32 14, i32* %47)
%49 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
%50 = call i32 @memset(i8* %49, i32 0, i32 40)
%51 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
%52 = getelementptr inbounds i8, i8* %51, i64 0
%53 = load i32, i32* %11
%54 = call i32 @bwrite_endian(i32 40, i32 4, i8* %52, i32 %53)
%55 = load i32, i32* %8
%56 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
%57 = getelementptr inbounds i8, i8* %56, i64 4
%58 = load i32, i32* %11
%59 = call i32 @bwrite_endian(i32 %55, i32 4, i8* %57, i32 %58)
%60 = load i32, i32* %9
%61 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
%62 = getelementptr inbounds i8, i8* %61, i64 8
%63 = load i32, i32* %11
%64 = call i32 @bwrite_endian(i32 %60, i32 4, i8* %62, i32 %63)
%65 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
%66 = getelementptr inbounds i8, i8* %65, i64 12
%67 = load i32, i32* %11
%68 = call i32 @bwrite_endian(i32 1, i32 2, i8* %66, i32 %67)
%69 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
%70 = getelementptr inbounds i8, i8* %69, i64 14
%71 = load i32, i32* %11
%72 = call i32 @bwrite_endian(i32 32, i32 2, i8* %70, i32 %71)
%73 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
%74 = getelementptr inbounds i8, i8* %73, i64 16
%75 = load i32, i32* %11
%76 = call i32 @bwrite_endian(i32 0, i32 4, i8* %74, i32 %75)
%77 = load i32, i32* %14
%78 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
%79 = getelementptr inbounds i8, i8* %78, i64 20
%80 = load i32, i32* %11
%81 = call i32 @bwrite_endian(i32 %77, i32 4, i8* %79, i32 %80)
%82 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
%83 = getelementptr inbounds i8, i8* %82, i64 24
%84 = load i32, i32* %11
%85 = call i32 @bwrite_endian(i32 65536, i32 4, i8* %83, i32 %84)
%86 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
%87 = getelementptr inbounds i8, i8* %86, i64 28
%88 = load i32, i32* %11
%89 = call i32 @bwrite_endian(i32 65536, i32 4, i8* %87, i32 %88)
%90 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
%91 = getelementptr inbounds i8, i8* %90, i64 32
%92 = load i32, i32* %11
%93 = call i32 @bwrite_endian(i32 16777216, i32 4, i8* %91, i32 %92)
%94 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
%95 = getelementptr inbounds i8, i8* %94, i64 36
%96 = load i32, i32* %11
%97 = call i32 @bwrite_endian(i32 0, i32 4, i8* %95, i32 %96)
%98 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
%99 = load i32*, i32** %10
%100 = call i32 @fwrite(i8* %98, i32 1, i32 40, i32* %99)
%101 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
store i8 0, i8* %101
%102 = load i32, i32* %9
%103 = sub nsw i32 %102, 1
store i32 %103, i32* %16
br label %104
104: ; preds = %153, %22
%105 = load i32, i32* %16
%106 = icmp sge i32 %105, 0
br i1 %106, label %107, label %156
107: ; preds = %104
store i32 0, i32* %15
br label %108
108: ; preds = %149, %107
%109 = load i32, i32* %15
%110 = load i32, i32* %8
%111 = icmp slt i32 %109, %110
br i1 %111, label %112, label %152
112: ; preds = %108
%113 = load [3 x i8]*, [3 x i8]** %7
%114 = load i32, i32* %15
%115 = load i32, i32* %16
%116 = load i32, i32* %8
%117 = mul nsw i32 %115, %116
%118 = add nsw i32 %114, %117
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds [3 x i8], [3 x i8]* %113, i64 %119
%121 = getelementptr inbounds [3 x i8], [3 x i8]* %120, i64 0, i64 2
%122 = load i32*, i32** %10
%123 = call i32 @fwrite(i8* %121, i32 1, i32 1, i32* %122)
%124 = load [3 x i8]*, [3 x i8]** %7
%125 = load i32, i32* %15
%126 = load i32, i32* %16
%127 = load i32, i32* %8
%128 = mul nsw i32 %126, %127
%129 = add nsw i32 %125, %128
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds [3 x i8], [3 x i8]* %124, i64 %130
%132 = getelementptr inbounds [3 x i8], [3 x i8]* %131, i64 0, i64 1
%133 = load i32*, i32** %10
%134 = call i32 @fwrite(i8* %132, i32 1, i32 1, i32* %133)
%135 = load [3 x i8]*, [3 x i8]** %7
%136 = load i32, i32* %15
%137 = load i32, i32* %16
%138 = load i32, i32* %8
%139 = mul nsw i32 %137, %138
%140 = add nsw i32 %136, %139
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds [3 x i8], [3 x i8]* %135, i64 %141
%143 = getelementptr inbounds [3 x i8], [3 x i8]* %142, i64 0, i64 0
%144 = load i32*, i32** %10
%145 = call i32 @fwrite(i8* %143, i32 1, i32 1, i32* %144)
%146 = getelementptr inbounds [40 x i8], [40 x i8]* %12, i64 0, i64 0
%147 = load i32*, i32** %10
%148 = call i32 @fwrite(i8* %146, i32 1, i32 1, i32* %147)
br label %149
149: ; preds = %112
%150 = load i32, i32* %15
%151 = add nsw i32 %150, 1
store i32 %151, i32* %15
br label %108
152: ; preds = %108
br label %153
153: ; preds = %152
%154 = load i32, i32* %16
%155 = add nsw i32 %154, -1
store i32 %155, i32* %16
br label %104
156: ; preds = %104
%157 = load i32*, i32** %10
%158 = call i32 @fclose(i32* %157)
store i32 0, i32* %5
br label %159
159: ; preds = %156, %21
%160 = load i32, i32* %5
ret i32 %160
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
define i32 @WriteBMP32(i8* nocapture %0, [3 x i8]* nocapture %1, i32 %2, i32 %3) {
%5 = alloca [40 x i8]
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 0
%8 = icmp eq i32* %6, null
br i1 %8, label %80, label %9
9: ; preds = %4
%10 = shl nsw i32 %2, 2
%11 = mul nsw i32 %10, %3
%12 = add nsw i32 %11, 54
%13 = call i32 @memset(i8* %7, i32 0, i32 14)
store i8 66, i8* %7
%14 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 1
store i8 77, i8* %14
%15 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 2
%16 = call i32 @bwrite_endian(i32 %12, i32 4, i8* %15, i32 1)
%17 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 6
%18 = call i32 @bwrite_endian(i32 0, i32 4, i8* %17, i32 1)
%19 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 10
%20 = call i32 @bwrite_endian(i32 54, i32 4, i8* %19, i32 1)
%21 = call i32 @fwrite(i8* %7, i32 1, i32 14, i32* %6)
%22 = call i32 @memset(i8* %7, i32 0, i32 40)
%23 = call i32 @bwrite_endian(i32 40, i32 4, i8* %7, i32 1)
%24 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 4
%25 = call i32 @bwrite_endian(i32 %2, i32 4, i8* %24, i32 1)
%26 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 8
%27 = call i32 @bwrite_endian(i32 %3, i32 4, i8* %26, i32 1)
%28 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 12
%29 = call i32 @bwrite_endian(i32 1, i32 2, i8* %28, i32 1)
%30 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 14
%31 = call i32 @bwrite_endian(i32 32, i32 2, i8* %30, i32 1)
%32 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 16
%33 = call i32 @bwrite_endian(i32 0, i32 4, i8* %32, i32 1)
%34 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 20
%35 = call i32 @bwrite_endian(i32 %11, i32 4, i8* %34, i32 1)
%36 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 24
%37 = call i32 @bwrite_endian(i32 65536, i32 4, i8* %36, i32 1)
%38 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 28
%39 = call i32 @bwrite_endian(i32 65536, i32 4, i8* %38, i32 1)
%40 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 32
%41 = call i32 @bwrite_endian(i32 16777216, i32 4, i8* %40, i32 1)
%42 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 36
%43 = call i32 @bwrite_endian(i32 0, i32 4, i8* %42, i32 1)
%44 = call i32 @fwrite(i8* %7, i32 1, i32 40, i32* %6)
store i8 0, i8* %7
%45 = icmp sgt i32 %3, 0
br i1 %45, label %46, label %78
46: ; preds = %9
%47 = icmp sgt i32 %2, 0
%48 = zext i32 %3 to i64
%49 = sext i32 %2 to i64
%50 = zext i32 %2 to i64
br label %53
51: ; preds = %58, %53
%52 = icmp sgt i64 %54, 1
br i1 %52, label %53, label %78
53: ; preds = %46, %51
%54 = phi i64 [ %48, %46 ], [ %55, %51 ]
%55 = add nsw i64 %54, -1
br i1 %47, label %56, label %51
56: ; preds = %53
%57 = mul nsw i64 %55, %49
br label %58
58: ; preds = %56, %58
%59 = phi i64 [ 0, %56 ], [ %76, %58 ]
%60 = add nsw i64 %59, %57
%61 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 %60, i64 2
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = call i32 @fputc(i32 %63, i32* %6)
%65 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 %60, i64 1
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = call i32 @fputc(i32 %67, i32* %6)
%69 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 %60, i64 0
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = call i32 @fputc(i32 %71, i32* %6)
%73 = load i8, i8* %7
%74 = sext i8 %73 to i32
%75 = call i32 @fputc(i32 %74, i32* %6)
%76 = add nuw nsw i64 %59, 1
%77 = icmp eq i64 %76, %50
br i1 %77, label %51, label %58
78: ; preds = %51, %9
%79 = call i32 @fclose(i32* %6)
br label %80
80: ; preds = %4, %78
%81 = phi i32 [ 0, %78 ], [ -1, %4 ]
ret i32 %81
}