#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputlong(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputshort(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char const *, int, int,
                          int /*<<< orphan*/ *);
int BitmapWrite(const char *filename, const void *buffer, int bitsPerPixel,
                int width, int inputStride, int height) {
  FILE *fp;
  int p;
  int stride;
  int paletteEntries;
  int y;
  if (bitsPerPixel <= 8) {
    paletteEntries = (1 << bitsPerPixel);
  } else {
    paletteEntries = 0;
  }
  bitsPerPixel = ((bitsPerPixel + 7) / 8) * 8;
  stride = ((((width * bitsPerPixel) + 31) & ~31) >> 3);
  if (filename == NULL || filename[0] == '\0') {
    return -1;
  }
  fp = fopen(filename, "wb");
  if (fp == NULL) {
    return -1;
  }
  fputc('B', fp);
  fputc('M', fp);
  fputlong((height * stride) + 54 + (paletteEntries * 4), fp);
  fputshort(0, fp);
  fputshort(0, fp);
  fputlong(54 + (paletteEntries * 4), fp);
  fputlong(40, fp);
  fputlong(width, fp);
  fputlong(height, fp);
  fputshort(1, fp);
  fputshort(bitsPerPixel, fp);
  fputlong(0, fp);
  fputlong(height * stride, fp);
  fputlong(5000, fp);
  fputlong(5000, fp);
  fputlong(0, fp);
  fputlong(0, fp);
  for (p = 0; p < paletteEntries; p++) {
    unsigned char v = p * 256 / paletteEntries;
    fputc(v, fp);
    fputc(v, fp);
    fputc(v, fp);
    fputc(0x00, fp);
  }
  for (y = height - 1; y >= 0; y--) {
    int len = stride;
    if (len > inputStride) {
      len = inputStride;
    }
    fwrite((const unsigned char *)buffer + y * inputStride, 1, len, fp);
    {
      int padding = stride - len;
      while (padding--) {
        fputc(0x00, fp);
      }
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<BitmapWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jg     119a <BitmapWrite+0x3a>
mov    -0x1c(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x3c(%rbp)
jmp    11a1 <BitmapWrite+0x41>
movl   $0x0,-0x3c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x7,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
shl    $0x3,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
imul   -0x1c(%rbp),%eax
add    $0x1f,%eax
and    $0xffffffe0,%eax
sar    $0x3,%eax
mov    %eax,-0x38(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11e3 <BitmapWrite+0x83>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11ef <BitmapWrite+0x8f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1402 <BitmapWrite+0x2a2>
mov    -0x10(%rbp),%rdi
lea    0xe06(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    121a <BitmapWrite+0xba>
movl   $0xffffffff,-0x4(%rbp)
jmp    1402 <BitmapWrite+0x2a2>
mov    -0x30(%rbp),%rsi
mov    $0x42,%edi
call   1050 <fputc@plt>
mov    -0x30(%rbp),%rsi
mov    $0x4d,%edi
call   1050 <fputc@plt>
mov    -0x28(%rbp),%edi
imul   -0x38(%rbp),%edi
add    $0x36,%edi
mov    -0x3c(%rbp),%eax
shl    $0x2,%eax
add    %eax,%edi
mov    -0x30(%rbp),%rsi
call   1060 <fputlong@plt>
mov    -0x30(%rbp),%rsi
xor    %edi,%edi
call   1040 <fputshort@plt>
mov    -0x30(%rbp),%rsi
xor    %edi,%edi
call   1040 <fputshort@plt>
mov    -0x3c(%rbp),%edi
shl    $0x2,%edi
add    $0x36,%edi
mov    -0x30(%rbp),%rsi
call   1060 <fputlong@plt>
mov    -0x30(%rbp),%rsi
mov    $0x28,%edi
call   1060 <fputlong@plt>
mov    -0x20(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1060 <fputlong@plt>
mov    -0x28(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1060 <fputlong@plt>
mov    -0x30(%rbp),%rsi
mov    $0x1,%edi
call   1040 <fputshort@plt>
mov    -0x1c(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1040 <fputshort@plt>
mov    -0x30(%rbp),%rsi
xor    %edi,%edi
call   1060 <fputlong@plt>
mov    -0x28(%rbp),%edi
imul   -0x38(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1060 <fputlong@plt>
mov    -0x30(%rbp),%rsi
mov    $0x1388,%edi
call   1060 <fputlong@plt>
mov    -0x30(%rbp),%rsi
mov    $0x1388,%edi
call   1060 <fputlong@plt>
mov    -0x30(%rbp),%rsi
xor    %edi,%edi
call   1060 <fputlong@plt>
mov    -0x30(%rbp),%rsi
xor    %edi,%edi
call   1060 <fputlong@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    1366 <BitmapWrite+0x206>
mov    -0x34(%rbp),%eax
shl    $0x8,%eax
cltd
idivl  -0x3c(%rbp)
mov    %al,-0x41(%rbp)
movzbl -0x41(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1050 <fputc@plt>
movzbl -0x41(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1050 <fputc@plt>
movzbl -0x41(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1050 <fputc@plt>
mov    -0x30(%rbp),%rsi
xor    %edi,%edi
call   1050 <fputc@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    130d <BitmapWrite+0x1ad>
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jl     13f2 <BitmapWrite+0x292>
mov    -0x38(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x24(%rbp),%eax
jle    1391 <BitmapWrite+0x231>
mov    -0x24(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%eax
imul   -0x24(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x48(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1080 <fwrite@plt>
mov    -0x38(%rbp),%eax
sub    -0x48(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4c(%rbp)
cmp    $0x0,%eax
je     13df <BitmapWrite+0x27f>
mov    -0x30(%rbp),%rsi
xor    %edi,%edi
call   1050 <fputc@plt>
jmp    13bb <BitmapWrite+0x25b>
jmp    13e4 <BitmapWrite+0x284>
mov    -0x40(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x40(%rbp)
jmp    136f <BitmapWrite+0x20f>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BitmapWrite>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,%ebx
mov    %edx,%r15d
mov    $0x1,%eax
mov    %r15d,%ecx
shl    %cl,%eax
xor    %r14d,%r14d
cmp    $0x9,%edx
cmovl  %eax,%r14d
mov    %rsi,0x20(%rsp)
lea    0x7(%r15),%eax
lea    0xe(%r15),%ecx
test   %eax,%eax
cmovns %eax,%ecx
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     13bb <BitmapWrite+0x25b>
cmpb   $0x0,(%rdi)
je     13bb <BitmapWrite+0x25b>
mov    %r9d,%r13d
mov    %r8d,%r12d
mov    %ecx,0x8(%rsp)
mov    %ebx,0x4(%rsp)
lea    0xe3b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     13bb <BitmapWrite+0x25b>
mov    %rax,%rbx
mov    %r12d,0x18(%rsp)
mov    0x8(%rsp),%ebp
and    $0xfffffff8,%ebp
mov    %ebp,0x8(%rsp)
imul   0x4(%rsp),%ebp
add    $0x1f,%ebp
sar    $0x3,%ebp
and    $0xfffffffc,%ebp
mov    $0x42,%edi
mov    %rax,%rsi
call   1050 <fputc@plt>
mov    $0x4d,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    %ebp,0x14(%rsp)
imul   %r13d,%ebp
lea    0x36(,%r14,4),%eax
mov    %eax,0x1c(%rsp)
lea    0x36(%rbp,%r14,4),%edi
mov    %rbx,%rsi
call   1060 <fputlong@plt>
mov    %r13d,%r12d
xor    %r13d,%r13d
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <fputshort@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <fputshort@plt>
mov    0x1c(%rsp),%edi
mov    %rbx,%rsi
call   1060 <fputlong@plt>
mov    $0x28,%edi
mov    %rbx,%rsi
call   1060 <fputlong@plt>
mov    0x4(%rsp),%edi
mov    %rbx,%rsi
call   1060 <fputlong@plt>
mov    %r12d,0x4(%rsp)
mov    %r12d,%edi
mov    %rbx,%rsi
call   1060 <fputlong@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
call   1040 <fputshort@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
call   1040 <fputshort@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <fputlong@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <fputlong@plt>
mov    $0x1388,%edi
mov    %rbx,%rsi
call   1060 <fputlong@plt>
mov    $0x1388,%edi
mov    %rbx,%rsi
call   1060 <fputlong@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <fputlong@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <fputlong@plt>
test   %r14d,%r14d
jle    1320 <BitmapWrite+0x1c0>
xchg   %ax,%ax
mov    %r13d,%eax
mov    %r15d,%ecx
shr    %cl,%eax
movzbl %al,%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
add    $0x100,%r13d
add    $0xffffffff,%r14d
jne    12e0 <BitmapWrite+0x180>
mov    0x4(%rsp),%edx
test   %edx,%edx
jle    13b1 <BitmapWrite+0x251>
mov    0x14(%rsp),%r15d
mov    0x18(%rsp),%ecx
cmp    %ecx,%r15d
mov    %r15d,%r14d
cmovg  %ecx,%r14d
mov    %edx,%r12d
movslq %ecx,%rcx
mov    %rcx,0x8(%rsp)
mov    %r14d,%ecx
sub    %r15d,%ecx
mov    %ecx,0x4(%rsp)
sub    %r14d,%r15d
jmp    1366 <BitmapWrite+0x206>
nopl   0x0(%rax)
cmp    $0x2,%rbp
jl     13b1 <BitmapWrite+0x251>
mov    %r12,%rbp
add    $0xffffffffffffffff,%r12
mov    %r12,%rdi
imul   0x8(%rsp),%rdi
add    0x20(%rsp),%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
test   %r15d,%r15d
je     1360 <BitmapWrite+0x200>
mov    0x4(%rsp),%r13d
cs nopw 0x0(%rax,%rax,1)
nop
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
inc    %r13d
jne    13a0 <BitmapWrite+0x240>
jmp    1360 <BitmapWrite+0x200>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x28,%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 @BitmapWrite(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i8
%20 = alloca i32
%21 = alloca i32
store i8* %0, i8** %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
%22 = load i32, i32* %10
%23 = icmp sle i32 %22, 8
br i1 %23, label %24, label %27
24: ; preds = %6
%25 = load i32, i32* %10
%26 = shl i32 1, %25
store i32 %26, i32* %17
br label %28
27: ; preds = %6
store i32 0, i32* %17
br label %28
28: ; preds = %27, %24
%29 = load i32, i32* %10
%30 = add nsw i32 %29, 7
%31 = sdiv i32 %30, 8
%32 = mul nsw i32 %31, 8
store i32 %32, i32* %10
%33 = load i32, i32* %11
%34 = load i32, i32* %10
%35 = mul nsw i32 %33, %34
%36 = add nsw i32 %35, 31
%37 = and i32 %36, -32
%38 = ashr i32 %37, 3
store i32 %38, i32* %16
%39 = load i8*, i8** %8
%40 = icmp eq i8* %39, null
br i1 %40, label %47, label %41
41: ; preds = %28
%42 = load i8*, i8** %8
%43 = getelementptr inbounds i8, i8* %42, i64 0
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %41, %28
store i32 -1, i32* %7
br label %172
48: ; preds = %41
%49 = load i8*, i8** %8
%50 = call i32* @fopen(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %50, i32** %14
%51 = load i32*, i32** %14
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %54
53: ; preds = %48
store i32 -1, i32* %7
br label %172
54: ; preds = %48
%55 = load i32*, i32** %14
%56 = call i32 @fputc(i32 66, i32* %55)
%57 = load i32*, i32** %14
%58 = call i32 @fputc(i32 77, i32* %57)
%59 = load i32, i32* %13
%60 = load i32, i32* %16
%61 = mul nsw i32 %59, %60
%62 = add nsw i32 %61, 54
%63 = load i32, i32* %17
%64 = mul nsw i32 %63, 4
%65 = add nsw i32 %62, %64
%66 = load i32*, i32** %14
%67 = call i32 @fputlong(i32 %65, i32* %66)
%68 = load i32*, i32** %14
%69 = call i32 @fputshort(i32 0, i32* %68)
%70 = load i32*, i32** %14
%71 = call i32 @fputshort(i32 0, i32* %70)
%72 = load i32, i32* %17
%73 = mul nsw i32 %72, 4
%74 = add nsw i32 54, %73
%75 = load i32*, i32** %14
%76 = call i32 @fputlong(i32 %74, i32* %75)
%77 = load i32*, i32** %14
%78 = call i32 @fputlong(i32 40, i32* %77)
%79 = load i32, i32* %11
%80 = load i32*, i32** %14
%81 = call i32 @fputlong(i32 %79, i32* %80)
%82 = load i32, i32* %13
%83 = load i32*, i32** %14
%84 = call i32 @fputlong(i32 %82, i32* %83)
%85 = load i32*, i32** %14
%86 = call i32 @fputshort(i32 1, i32* %85)
%87 = load i32, i32* %10
%88 = load i32*, i32** %14
%89 = call i32 @fputshort(i32 %87, i32* %88)
%90 = load i32*, i32** %14
%91 = call i32 @fputlong(i32 0, i32* %90)
%92 = load i32, i32* %13
%93 = load i32, i32* %16
%94 = mul nsw i32 %92, %93
%95 = load i32*, i32** %14
%96 = call i32 @fputlong(i32 %94, i32* %95)
%97 = load i32*, i32** %14
%98 = call i32 @fputlong(i32 5000, i32* %97)
%99 = load i32*, i32** %14
%100 = call i32 @fputlong(i32 5000, i32* %99)
%101 = load i32*, i32** %14
%102 = call i32 @fputlong(i32 0, i32* %101)
%103 = load i32*, i32** %14
%104 = call i32 @fputlong(i32 0, i32* %103)
store i32 0, i32* %15
br label %105
105: ; preds = %129, %54
%106 = load i32, i32* %15
%107 = load i32, i32* %17
%108 = icmp slt i32 %106, %107
br i1 %108, label %109, label %132
109: ; preds = %105
%110 = load i32, i32* %15
%111 = mul nsw i32 %110, 256
%112 = load i32, i32* %17
%113 = sdiv i32 %111, %112
%114 = trunc i32 %113 to i8
store i8 %114, i8* %19
%115 = load i8, i8* %19
%116 = zext i8 %115 to i32
%117 = load i32*, i32** %14
%118 = call i32 @fputc(i32 %116, i32* %117)
%119 = load i8, i8* %19
%120 = zext i8 %119 to i32
%121 = load i32*, i32** %14
%122 = call i32 @fputc(i32 %120, i32* %121)
%123 = load i8, i8* %19
%124 = zext i8 %123 to i32
%125 = load i32*, i32** %14
%126 = call i32 @fputc(i32 %124, i32* %125)
%127 = load i32*, i32** %14
%128 = call i32 @fputc(i32 0, i32* %127)
br label %129
129: ; preds = %109
%130 = load i32, i32* %15
%131 = add nsw i32 %130, 1
store i32 %131, i32* %15
br label %105
132: ; preds = %105
%133 = load i32, i32* %13
%134 = sub nsw i32 %133, 1
store i32 %134, i32* %18
br label %135
135: ; preds = %166, %132
%136 = load i32, i32* %18
%137 = icmp sge i32 %136, 0
br i1 %137, label %138, label %169
138: ; preds = %135
%139 = load i32, i32* %16
store i32 %139, i32* %20
%140 = load i32, i32* %20
%141 = load i32, i32* %12
%142 = icmp sgt i32 %140, %141
br i1 %142, label %143, label %145
143: ; preds = %138
%144 = load i32, i32* %12
store i32 %144, i32* %20
br label %145
145: ; preds = %143, %138
%146 = load i8*, i8** %9
%147 = load i32, i32* %18
%148 = load i32, i32* %12
%149 = mul nsw i32 %147, %148
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds i8, i8* %146, i64 %150
%152 = load i32, i32* %20
%153 = load i32*, i32** %14
%154 = call i32 @fwrite(i8* %151, i32 1, i32 %152, i32* %153)
%155 = load i32, i32* %16
%156 = load i32, i32* %20
%157 = sub nsw i32 %155, %156
store i32 %157, i32* %21
br label %158
158: ; preds = %162, %145
%159 = load i32, i32* %21
%160 = add nsw i32 %159, -1
store i32 %160, i32* %21
%161 = icmp ne i32 %159, 0
br i1 %161, label %162, label %165
162: ; preds = %158
%163 = load i32*, i32** %14
%164 = call i32 @fputc(i32 0, i32* %163)
br label %158
165: ; preds = %158
br label %166
166: ; preds = %165
%167 = load i32, i32* %18
%168 = add nsw i32 %167, -1
store i32 %168, i32* %18
br label %135
169: ; preds = %135
%170 = load i32*, i32** %14
%171 = call i32 @fclose(i32* %170)
store i32 0, i32* %7
br label %172
172: ; preds = %169, %53, %47
%173 = load i32, i32* %7
ret i32 %173
}

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