signed int writebmp(char *filename, signed int xs, signed int ys,
                    unsigned char *img) {
  if (!(img == ((unsigned char *)((void *)0)))) {
    struct _IO_FILE$link44 *dfile;
    dfile = fopen(filename, "wb");
    if (!(dfile == ((struct _IO_FILE$link44 *)((void *)0)))) {
      signed int i;
      signed int y;
      signed int imgdataoffset = 14 + 40;
      signed int rowsz = xs * 3 + 3 & -4;
      signed int imgdatasize = rowsz * ys;
      signed int filesize = imgdataoffset + imgdatasize;
      unsigned char *rowbuf = (unsigned char *)((void *)0);
      fputc(66, dfile);
      fputc(77, dfile);
      write_le_int32(dfile, filesize);
      write_le_int16(dfile, 0);
      write_le_int16(dfile, 0);
      write_le_int32(dfile, imgdataoffset);
      write_le_int32(dfile, 40);
      write_le_int32(dfile, xs);
      write_le_int32(dfile, ys);
      write_le_int16(dfile, 1);
      write_le_int16(dfile, 24);
      write_le_int32(dfile, 0);
      write_le_int32(dfile, imgdatasize);
      write_le_int32(dfile, 11811);
      write_le_int32(dfile, 11811);
      write_le_int32(dfile, 0);
      write_le_int32(dfile, 0);
      void *return_value_malloc$1;
      return_value_malloc$1 = malloc((unsigned long int)rowsz);
      rowbuf = (unsigned char *)return_value_malloc$1;
      if (!(rowbuf == ((unsigned char *)((void *)0)))) {
        memset((void *)rowbuf, 0, (unsigned long int)rowsz);
        y = 0;
        while (!(y >= ys)) {
          signed int addr = xs * 3 * y;
          i = 0;
          while (!(i >= rowsz)) {
            rowbuf[(signed long int)i] = img[(signed long int)(addr + i + 2)];
            rowbuf[(signed long int)(i + 1)] =
                img[(signed long int)(addr + i + 1)];
            rowbuf[(signed long int)(i + 2)] = img[(signed long int)(addr + i)];
            i = i + 3;
          }
          fwrite((const void *)rowbuf, (unsigned long int)rowsz,
                 (unsigned long int)1, dfile);
          y = y + 1;
        }
        free((void *)rowbuf);
      }
      fclose(dfile);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<writebmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1420 <writebmp+0x290>
mov    -0x8(%rbp),%rdi
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   10a0 <fopen@plt>
cltq
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     141b <writebmp+0x28b>
movl   $0x36,-0x2c(%rbp)
imul   $0x3,-0xc(%rbp),%eax
add    $0x3,%eax
and    $0xfffffffc,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x20(%rbp),%rsi
mov    $0x42,%edi
mov    $0x0,%al
call   1070 <fputc@plt>
mov    -0x20(%rbp),%rsi
mov    $0x4d,%edi
mov    $0x0,%al
call   1070 <fputc@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%esi
mov    $0x0,%al
call   1050 <write_le_int32@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x0,%al
call   1090 <write_le_int16@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x0,%al
call   1090 <write_le_int16@plt>
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    $0x0,%al
call   1050 <write_le_int32@plt>
mov    -0x20(%rbp),%rdi
mov    $0x28,%esi
mov    $0x0,%al
call   1050 <write_le_int32@plt>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    $0x0,%al
call   1050 <write_le_int32@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    $0x0,%al
call   1050 <write_le_int32@plt>
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1090 <write_le_int16@plt>
mov    -0x20(%rbp),%rdi
mov    $0x18,%esi
mov    $0x0,%al
call   1090 <write_le_int16@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x0,%al
call   1050 <write_le_int32@plt>
mov    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    $0x0,%al
call   1050 <write_le_int32@plt>
mov    -0x20(%rbp),%rdi
mov    $0x2e23,%esi
mov    $0x0,%al
call   1050 <write_le_int32@plt>
mov    -0x20(%rbp),%rdi
mov    $0x2e23,%esi
mov    $0x0,%al
call   1050 <write_le_int32@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x0,%al
call   1050 <write_le_int32@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x0,%al
call   1050 <write_le_int32@plt>
movslq -0x30(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1410 <writebmp+0x280>
mov    -0x40(%rbp),%rdi
movslq -0x30(%rbp),%rdx
xor    %esi,%esi
call   1060 <memset@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x10(%rbp),%eax
setge  %al
xor    $0xff,%al
test   $0x1,%al
jne    1348 <writebmp+0x1b8>
jmp    1407 <writebmp+0x277>
imul   $0x3,-0xc(%rbp),%eax
imul   -0x28(%rbp),%eax
mov    %eax,-0x4c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x30(%rbp),%eax
setge  %al
xor    $0xff,%al
test   $0x1,%al
jne    1372 <writebmp+0x1e2>
jmp    13e1 <writebmp+0x251>
mov    -0x18(%rbp),%rax
mov    -0x4c(%rbp),%ecx
add    -0x24(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x40(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x4c(%rbp),%ecx
add    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x40(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x4c(%rbp),%ecx
add    -0x24(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x40(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x24(%rbp)
jmp    135a <writebmp+0x1ca>
mov    -0x40(%rbp),%rdi
movslq -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
mov    $0x0,%al
call   10b0 <fwrite@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1330 <writebmp+0x1a0>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1040 <fclose@plt>
jmp    1420 <writebmp+0x290>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writebmp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,0x8(%rsp)
test   %rcx,%rcx
je     1369 <writebmp+0x1e9>
mov    %rcx,%rbx
mov    %esi,%r12d
lea    0xe58(%rip),%rsi
xor    %eax,%eax
call   1090 <fopen@plt>
test   %eax,%eax
je     1369 <writebmp+0x1e9>
movslq %eax,%rbp
lea    (%r12,%r12,2),%r15d
add    $0x3,%r15d
and    $0xfffffffc,%r15d
mov    %r15d,%r13d
imul   0x8(%rsp),%r13d
lea    0x36(%r13),%r14d
mov    $0x42,%edi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <fputc@plt>
mov    $0x4d,%edi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <fputc@plt>
mov    %rbp,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <write_le_int32@plt>
mov    %rbp,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1080 <write_le_int16@plt>
mov    %rbp,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1080 <write_le_int16@plt>
mov    %rbp,%rdi
mov    $0x36,%esi
xor    %eax,%eax
call   1050 <write_le_int32@plt>
mov    %rbp,%rdi
mov    $0x28,%esi
xor    %eax,%eax
call   1050 <write_le_int32@plt>
mov    %rbp,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <write_le_int32@plt>
mov    %rbp,%rdi
mov    0x8(%rsp),%esi
xor    %eax,%eax
call   1050 <write_le_int32@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1080 <write_le_int16@plt>
mov    %rbp,%rdi
mov    $0x18,%esi
xor    %eax,%eax
call   1080 <write_le_int16@plt>
mov    %rbp,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <write_le_int32@plt>
mov    %rbp,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <write_le_int32@plt>
mov    %rbp,%rdi
mov    $0x2e23,%esi
xor    %eax,%eax
call   1050 <write_le_int32@plt>
mov    %rbp,%rdi
mov    $0x2e23,%esi
xor    %eax,%eax
call   1050 <write_le_int32@plt>
mov    %rbp,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <write_le_int32@plt>
mov    %rbp,0x10(%rsp)
mov    %rbp,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <write_le_int32@plt>
mov    %r15d,0xc(%rsp)
movslq %r15d,%r13
mov    $0x1,%edi
mov    %r13,%rsi
call   1070 <calloc@plt>
test   %rax,%rax
je     135d <writebmp+0x1dd>
mov    %rax,%rbp
cmpl   $0x0,0x8(%rsp)
jle    1355 <writebmp+0x1d5>
lea    (%r12,%r12,2),%eax
movslq %eax,%r12
mov    0x8(%rsp),%r15d
add    $0x2,%rbx
xor    %r14d,%r14d
jmp    1323 <writebmp+0x1a3>
xchg   %ax,%ax
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %r13,%rsi
mov    0x10(%rsp),%rcx
xor    %eax,%eax
call   10a0 <fwrite@plt>
add    $0x1,%r14
add    %r12,%rbx
cmp    %r15,%r14
je     1355 <writebmp+0x1d5>
cmpl   $0x0,0xc(%rsp)
jle    1300 <writebmp+0x180>
xor    %eax,%eax
nopl   0x0(%rax)
movzbl (%rbx,%rax,1),%ecx
mov    %cl,0x0(%rbp,%rax,1)
movzbl -0x1(%rbx,%rax,1),%ecx
mov    %cl,0x1(%rbp,%rax,1)
movzbl -0x2(%rbx,%rax,1),%ecx
mov    %cl,0x2(%rbp,%rax,1)
add    $0x3,%rax
cmp    %r13,%rax
jl     1330 <writebmp+0x1b0>
jmp    1300 <writebmp+0x180>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
xor    %eax,%eax
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%"struct._IO_FILE$link44" = type opaque
@.str = [3 x i8] c"wb\00"
define i32 @writebmp(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = icmp eq i8* %3, null
br i1 %5, label %71, label %6
6: ; preds = %4
%7 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @fopen to i32 (i8*, i8*, ...)*)(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to %"struct._IO_FILE$link44"*
%10 = icmp eq i32 %7, 0
br i1 %10, label %71, label %11
11: ; preds = %6
%12 = mul nsw i32 %1, 3
%13 = add nsw i32 %12, 3
%14 = and i32 %13, -4
%15 = mul nsw i32 %14, %2
%16 = add nsw i32 %15, 54
%17 = tail call i32 (i32, %"struct._IO_FILE$link44"*, ...) bitcast (i32 (...)* @fputc to i32 (i32, %"struct._IO_FILE$link44"*, ...)*)(i32 66, %"struct._IO_FILE$link44"* %9)
%18 = tail call i32 (i32, %"struct._IO_FILE$link44"*, ...) bitcast (i32 (...)* @fputc to i32 (i32, %"struct._IO_FILE$link44"*, ...)*)(i32 77, %"struct._IO_FILE$link44"* %9)
%19 = tail call i32 (%"struct._IO_FILE$link44"*, i32, ...) bitcast (i32 (...)* @write_le_int32 to i32 (%"struct._IO_FILE$link44"*, i32, ...)*)(%"struct._IO_FILE$link44"* %9, i32 %16)
%20 = tail call i32 (%"struct._IO_FILE$link44"*, i32, ...) bitcast (i32 (...)* @write_le_int16 to i32 (%"struct._IO_FILE$link44"*, i32, ...)*)(%"struct._IO_FILE$link44"* %9, i32 0)
%21 = tail call i32 (%"struct._IO_FILE$link44"*, i32, ...) bitcast (i32 (...)* @write_le_int16 to i32 (%"struct._IO_FILE$link44"*, i32, ...)*)(%"struct._IO_FILE$link44"* %9, i32 0)
%22 = tail call i32 (%"struct._IO_FILE$link44"*, i32, ...) bitcast (i32 (...)* @write_le_int32 to i32 (%"struct._IO_FILE$link44"*, i32, ...)*)(%"struct._IO_FILE$link44"* %9, i32 54)
%23 = tail call i32 (%"struct._IO_FILE$link44"*, i32, ...) bitcast (i32 (...)* @write_le_int32 to i32 (%"struct._IO_FILE$link44"*, i32, ...)*)(%"struct._IO_FILE$link44"* %9, i32 40)
%24 = tail call i32 (%"struct._IO_FILE$link44"*, i32, ...) bitcast (i32 (...)* @write_le_int32 to i32 (%"struct._IO_FILE$link44"*, i32, ...)*)(%"struct._IO_FILE$link44"* %9, i32 %1)
%25 = tail call i32 (%"struct._IO_FILE$link44"*, i32, ...) bitcast (i32 (...)* @write_le_int32 to i32 (%"struct._IO_FILE$link44"*, i32, ...)*)(%"struct._IO_FILE$link44"* %9, i32 %2)
%26 = tail call i32 (%"struct._IO_FILE$link44"*, i32, ...) bitcast (i32 (...)* @write_le_int16 to i32 (%"struct._IO_FILE$link44"*, i32, ...)*)(%"struct._IO_FILE$link44"* %9, i32 1)
%27 = tail call i32 (%"struct._IO_FILE$link44"*, i32, ...) bitcast (i32 (...)* @write_le_int16 to i32 (%"struct._IO_FILE$link44"*, i32, ...)*)(%"struct._IO_FILE$link44"* %9, i32 24)
%28 = tail call i32 (%"struct._IO_FILE$link44"*, i32, ...) bitcast (i32 (...)* @write_le_int32 to i32 (%"struct._IO_FILE$link44"*, i32, ...)*)(%"struct._IO_FILE$link44"* %9, i32 0)
%29 = tail call i32 (%"struct._IO_FILE$link44"*, i32, ...) bitcast (i32 (...)* @write_le_int32 to i32 (%"struct._IO_FILE$link44"*, i32, ...)*)(%"struct._IO_FILE$link44"* %9, i32 %15)
%30 = tail call i32 (%"struct._IO_FILE$link44"*, i32, ...) bitcast (i32 (...)* @write_le_int32 to i32 (%"struct._IO_FILE$link44"*, i32, ...)*)(%"struct._IO_FILE$link44"* %9, i32 11811)
%31 = tail call i32 (%"struct._IO_FILE$link44"*, i32, ...) bitcast (i32 (...)* @write_le_int32 to i32 (%"struct._IO_FILE$link44"*, i32, ...)*)(%"struct._IO_FILE$link44"* %9, i32 11811)
%32 = tail call i32 (%"struct._IO_FILE$link44"*, i32, ...) bitcast (i32 (...)* @write_le_int32 to i32 (%"struct._IO_FILE$link44"*, i32, ...)*)(%"struct._IO_FILE$link44"* %9, i32 0)
%33 = tail call i32 (%"struct._IO_FILE$link44"*, i32, ...) bitcast (i32 (...)* @write_le_int32 to i32 (%"struct._IO_FILE$link44"*, i32, ...)*)(%"struct._IO_FILE$link44"* %9, i32 0)
%34 = sext i32 %14 to i64
%35 = call i8* @calloc(i64 1, i64 %34)
%36 = icmp eq i8* %35, null
br i1 %36, label %69, label %37
37: ; preds = %11
%38 = icmp sgt i32 %2, 0
br i1 %38, label %39, label %68
39: ; preds = %37
%40 = icmp sgt i32 %14, 0
%41 = sext i32 %12 to i64
%42 = zext i32 %2 to i64
br label %43
43: ; preds = %39, %64
%44 = phi i64 [ 0, %39 ], [ %66, %64 ]
%45 = mul nsw i64 %44, %41
br i1 %40, label %46, label %64
46: ; preds = %43, %46
%47 = phi i64 [ %62, %46 ], [ 0, %43 ]
%48 = add nsw i64 %47, %45
%49 = add nsw i64 %48, 2
%50 = getelementptr inbounds i8, i8* %3, i64 %49
%51 = load i8, i8* %50
%52 = getelementptr inbounds i8, i8* %35, i64 %47
store i8 %51, i8* %52
%53 = add nsw i64 %48, 1
%54 = getelementptr inbounds i8, i8* %3, i64 %53
%55 = load i8, i8* %54
%56 = add nuw nsw i64 %47, 1
%57 = getelementptr inbounds i8, i8* %35, i64 %56
store i8 %55, i8* %57
%58 = getelementptr inbounds i8, i8* %3, i64 %48
%59 = load i8, i8* %58
%60 = add nuw nsw i64 %47, 2
%61 = getelementptr inbounds i8, i8* %35, i64 %60
store i8 %59, i8* %61
%62 = add nuw nsw i64 %47, 3
%63 = icmp slt i64 %62, %34
br i1 %63, label %46, label %64
64: ; preds = %46, %43
%65 = tail call i32 (i8*, i64, i64, %"struct._IO_FILE$link44"*, ...) bitcast (i32 (...)* @fwrite to i32 (i8*, i64, i64, %"struct._IO_FILE$link44"*, ...)*)(i8* %35, i64 %34, i64 1, %"struct._IO_FILE$link44"* %9)
%66 = add nuw nsw i64 %44, 1
%67 = icmp eq i64 %66, %42
br i1 %67, label %68, label %43
68: ; preds = %64, %37
tail call void @free(i8* %35)
br label %69
69: ; preds = %68, %11
%70 = tail call i32 (%"struct._IO_FILE$link44"*, ...) bitcast (i32 (...)* @fclose to i32 (%"struct._IO_FILE$link44"*, ...)*)(%"struct._IO_FILE$link44"* %9)
br label %71
71: ; preds = %6, %69, %4
ret i32 0
}