#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*/ exit(int);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *fd, *ofd;
  char *buf, *outbuf;
  char head[18];
  int s, e, w, h;
  int i, j, k, l;
  int x, y, rx, ry;
  int cw, ch;
  fd = fopen(argv[1], "rb");
  ofd = fopen(argv[2], "wb");
  s = fgetc(fd);
  s += fgetc(fd) << 8;
  e = fgetc(fd);
  e += fgetc(fd) << 8;
  if (s == 0xBF00) {
    buf = malloc(16);
    fread(buf, 1, e, fd);
    cw = buf[1];
    ch = buf[2];
  } else {
    printf("no header\n");
    exit(-1);
  }
  outbuf = malloc(65536 * cw * ch * 3);
  memset(outbuf, 0, 65536 * cw * ch * 3);
  w = 256 * cw;
  h = 256 * ch;
  memset(head, 0, 18);
  head[2] = 2;
  head[12] = w & 0xff;
  head[13] = w >> 8;
  head[14] = h & 0xff;
  head[15] = h >> 8;
  head[16] = 24;
  fwrite(head, 1, 18, ofd);
  while (1) {
    s = fgetc(fd);
    s += fgetc(fd) << 8;
    e = fgetc(fd);
    e += fgetc(fd) << 8;
    if (!s && !e)
      break;
    printf("chunk %d-%d\n", s, e);
    buf = malloc(((e - s) + 1) * ((cw * ch) / 8));
    fread(buf, (e - s) + 1, ((cw * ch) / 8), fd);
    for (i = 0; i < ((e - s) + 1); i++) {
      j = i + s;
      x = (j & 0xff) * cw;
      y = (j >> 8) * ch;
      for (k = 0; k < ((cw * ch) / 8); k++)
        for (l = 0; l < 8; l++) {
          if (buf[(i * ((cw * ch) / 8)) + k] & (128 >> l)) {
            rx = ((k * 8) + l) % cw;
            ry = ((k * 8) + l) / cw;
            outbuf[(((h - (y + ry) - 1) * w) + (x + rx)) * 3] = 0xff;
            outbuf[(((h - (y + ry) - 1) * w) + (x + rx)) * 3 + 1] = 0xff;
            outbuf[(((h - (y + ry) - 1) * w) + (x + rx)) * 3 + 2] = 0xff;
          }
        }
    }
  }
  fwrite(outbuf, 256 * ch, 256 * cw * 3, ofd);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe58(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe43(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
shl    $0x8,%eax
add    -0x54(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
shl    $0x8,%eax
add    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
cmpl   $0xbf00,-0x54(%rbp)
jne    1256 <main+0xd6>
mov    $0x10,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x58(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0x84(%rbp)
mov    -0x28(%rbp),%rax
movsbl 0x2(%rax),%eax
mov    %eax,-0x88(%rbp)
jmp    126e <main+0xee>
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x84(%rbp),%eax
shl    $0x10,%eax
imul   -0x88(%rbp),%eax
imul   $0x3,%eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x84(%rbp),%eax
shl    $0x10,%eax
imul   -0x88(%rbp),%eax
imul   $0x3,%eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x84(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x88(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x60(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x12,%edx
call   1050 <memset@plt>
movb   $0x2,-0x4e(%rbp)
mov    -0x5c(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x44(%rbp)
mov    -0x5c(%rbp),%eax
sar    $0x8,%eax
mov    %al,-0x43(%rbp)
mov    -0x60(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x42(%rbp)
mov    -0x60(%rbp),%eax
sar    $0x8,%eax
mov    %al,-0x41(%rbp)
movb   $0x18,-0x40(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x12,%edx
call   10a0 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
shl    $0x8,%eax
add    -0x54(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
shl    $0x8,%eax
add    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
cmpl   $0x0,-0x54(%rbp)
jne    136c <main+0x1ec>
cmpl   $0x0,-0x58(%rbp)
jne    136c <main+0x1ec>
jmp    1595 <main+0x415>
mov    -0x54(%rbp),%esi
mov    -0x58(%rbp),%edx
lea    0xc98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x58(%rbp),%edi
sub    -0x54(%rbp),%edi
add    $0x1,%edi
mov    -0x84(%rbp),%eax
imul   -0x88(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
imul   %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x58(%rbp),%esi
sub    -0x54(%rbp),%esi
add    $0x1,%esi
mov    -0x84(%rbp),%eax
imul   -0x88(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
mov    -0x18(%rbp),%rcx
call   1030 <fread@plt>
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    -0x58(%rbp),%ecx
sub    -0x54(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1590 <main+0x410>
mov    -0x64(%rbp),%eax
add    -0x54(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
and    $0xff,%eax
imul   -0x84(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x68(%rbp),%eax
sar    $0x8,%eax
imul   -0x88(%rbp),%eax
mov    %eax,-0x78(%rbp)
movl   $0x0,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x84(%rbp),%eax
imul   -0x88(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x8c(%rbp),%eax
cmp    %ecx,%eax
jge    157d <main+0x3fd>
movl   $0x0,-0x70(%rbp)
cmpl   $0x8,-0x70(%rbp)
jge    156a <main+0x3ea>
mov    -0x28(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x64(%rbp),%ecx
mov    -0x84(%rbp),%eax
imul   -0x88(%rbp),%eax
mov    $0x8,%esi
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x98(%rbp),%rax
imul   %edx,%ecx
add    -0x6c(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x70(%rbp),%ecx
mov    $0x80,%edx
sar    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1557 <main+0x3d7>
mov    -0x6c(%rbp),%eax
shl    $0x3,%eax
add    -0x70(%rbp),%eax
cltd
idivl  -0x84(%rbp)
mov    %edx,-0x7c(%rbp)
mov    -0x6c(%rbp),%eax
shl    $0x3,%eax
add    -0x70(%rbp),%eax
cltd
idivl  -0x84(%rbp)
mov    %eax,-0x80(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x60(%rbp),%ecx
mov    -0x78(%rbp),%edx
add    -0x80(%rbp),%edx
sub    %edx,%ecx
sub    $0x1,%ecx
imul   -0x5c(%rbp),%ecx
mov    -0x74(%rbp),%edx
add    -0x7c(%rbp),%edx
add    %edx,%ecx
imul   $0x3,%ecx,%ecx
movslq %ecx,%rcx
movb   $0xff,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
mov    -0x60(%rbp),%ecx
mov    -0x78(%rbp),%edx
add    -0x80(%rbp),%edx
sub    %edx,%ecx
sub    $0x1,%ecx
imul   -0x5c(%rbp),%ecx
mov    -0x74(%rbp),%edx
add    -0x7c(%rbp),%edx
add    %edx,%ecx
imul   $0x3,%ecx,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0xff,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
mov    -0x60(%rbp),%ecx
mov    -0x78(%rbp),%edx
add    -0x80(%rbp),%edx
sub    %edx,%ecx
sub    $0x1,%ecx
imul   -0x5c(%rbp),%ecx
mov    -0x74(%rbp),%edx
add    -0x7c(%rbp),%edx
add    %edx,%ecx
imul   $0x3,%ecx,%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movb   $0xff,(%rax,%rcx,1)
jmp    155c <main+0x3dc>
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
jmp    1459 <main+0x2d9>
jmp    156f <main+0x3ef>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    1424 <main+0x2a4>
jmp    1582 <main+0x402>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    13de <main+0x25e>
jmp    1317 <main+0x197>
mov    -0x30(%rbp),%rdi
mov    -0x88(%rbp),%esi
shl    $0x8,%esi
mov    -0x84(%rbp),%eax
shl    $0x8,%eax
imul   $0x3,%eax,%edx
mov    -0x20(%rbp),%rcx
call   10a0 <fwrite@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe54(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
lea    0xe44(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,0x28(%rsp)
mov    %r15,%rdi
call   1070 <fgetc@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1070 <fgetc@plt>
mov    %eax,%ebp
shl    $0x8,%ebp
add    %ebx,%ebp
mov    %r15,%rdi
call   1070 <fgetc@plt>
mov    %eax,%r14d
mov    %r15,%rdi
call   1070 <fgetc@plt>
cmp    $0xbf00,%ebp
jne    1478 <main+0x2e8>
mov    %eax,%ebx
shl    $0x8,%ebx
add    %r14d,%ebx
mov    $0x10,%edi
call   1080 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
movsbl 0x1(%rbp),%r14d
movsbl 0x2(%rbp),%ebx
mov    %r14d,%eax
imul   %ebx,%eax
mov    %rax,0x38(%rsp)
shl    $0x10,%eax
lea    (%rax,%rax,2),%ebp
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1060 <memset@plt>
mov    %ebx,%r12d
shl    $0x8,%r12d
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x12,%edx
call   1060 <memset@plt>
movb   $0x2,0x12(%rsp)
movb   $0x0,0x1c(%rsp)
mov    %r14b,0x1d(%rsp)
movb   $0x0,0x1e(%rsp)
mov    %ebx,0xc(%rsp)
mov    %bl,0x1f(%rsp)
movb   $0x18,0x20(%rsp)
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x12,%edx
mov    0x28(%rsp),%rcx
call   10b0 <fwrite@plt>
mov    %r15,%rdi
call   1070 <fgetc@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1070 <fgetc@plt>
mov    %eax,%ebx
shl    $0x8,%ebx
add    %ebp,%ebx
mov    %r15,%rdi
call   1070 <fgetc@plt>
mov    %eax,(%rsp)
mov    %r15,%rdi
call   1070 <fgetc@plt>
mov    %eax,%ebp
shl    $0x8,%ebp
add    (%rsp),%ebp
mov    %ebx,%eax
or     %ebp,%eax
mov    %r15,0x30(%rsp)
je     144f <main+0x2bf>
mov    0x38(%rsp),%rcx
lea    0x7(%rcx),%eax
test   %cx,%cx
cmovns %ecx,%eax
cwtl
sar    $0x3,%eax
mov    %rax,(%rsp)
cltq
mov    %rax,0x40(%rsp)
jmp    1355 <main+0x1c5>
nopl   (%rax)
mov    0x30(%rsp),%rbp
mov    %rbp,%rdi
call   1070 <fgetc@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
call   1070 <fgetc@plt>
mov    %eax,%ebx
shl    $0x8,%ebx
add    %r15d,%ebx
mov    %rbp,%rdi
call   1070 <fgetc@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
call   1070 <fgetc@plt>
mov    %eax,%ebp
shl    $0x8,%ebp
add    %r15d,%ebp
mov    %ebx,%eax
or     %ebp,%eax
je     144f <main+0x2bf>
lea    0xcaa(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,0x48(%rsp)
sub    %ebx,%ebp
lea    0x1(%rbp),%ebx
mov    %ebx,%edi
imul   (%rsp),%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,0x50(%rsp)
mov    %ebx,%esi
mov    (%rsp),%rdx
mov    0x30(%rsp),%rcx
call   1040 <fread@plt>
test   %ebp,%ebp
mov    0xc(%rsp),%r11d
js     1310 <main+0x180>
xor    %r8d,%r8d
jmp    13bf <main+0x22f>
nopl   0x0(%rax)
add    $0x1,%r8
cmp    0x50(%rsp),%r8
je     1310 <main+0x180>
cmpl   $0x8,0x38(%rsp)
jl     13b0 <main+0x220>
mov    0x48(%rsp),%rax
lea    (%rax,%r8,1),%esi
movzbl %sil,%edi
sar    $0x8,%esi
imul   %r11d,%esi
mov    %r8,%r9
imul   0x40(%rsp),%r9
xor    %ebp,%ebp
xor    %r10d,%r10d
jmp    13fd <main+0x26d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r10
add    $0x8,%ebp
cmp    (%rsp),%r10
je     13b0 <main+0x220>
lea    (%r10,%r9,1),%rax
movzbl (%r15,%rax,1),%ebx
xor    %ecx,%ecx
jmp    1418 <main+0x288>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ecx
cmp    $0x8,%ecx
je     13f0 <main+0x260>
mov    %ebx,%eax
shl    %cl,%eax
test   $0x80,%al
je     1410 <main+0x280>
lea    (%rcx,%rbp,1),%eax
cltd
idiv   %r14d
add    %esi,%eax
not    %eax
add    %r12d,%eax
shl    $0x8,%eax
or     %edi,%eax
imul   %r14d,%eax
add    %edx,%eax
cltq
lea    (%rax,%rax,2),%rax
movb   $0xff,0x0(%r13,%rax,1)
movw   $0xffff,0x1(%r13,%rax,1)
ff
jmp    1410 <main+0x280>
shl    $0x8,%r14d
lea    (%r14,%r14,2),%edx
mov    %r13,%rdi
mov    %r12d,%esi
mov    0x28(%rsp),%rcx
call   10b0 <fwrite@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb94(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [11 x i8] c"no header\0A\00"
@.str.3 = [13 x i8] c"chunk %d-%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [18 x i8]
%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 i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %28, i32** %6
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %32, i32** %7
%33 = load i32*, i32** %6
%34 = call i32 @fgetc(i32* %33)
store i32 %34, i32* %11
%35 = load i32*, i32** %6
%36 = call i32 @fgetc(i32* %35)
%37 = shl i32 %36, 8
%38 = load i32, i32* %11
%39 = add nsw i32 %38, %37
store i32 %39, i32* %11
%40 = load i32*, i32** %6
%41 = call i32 @fgetc(i32* %40)
store i32 %41, i32* %12
%42 = load i32*, i32** %6
%43 = call i32 @fgetc(i32* %42)
%44 = shl i32 %43, 8
%45 = load i32, i32* %12
%46 = add nsw i32 %45, %44
store i32 %46, i32* %12
%47 = load i32, i32* %11
%48 = icmp eq i32 %47, 48896
br i1 %48, label %49, label %63
49: ; preds = %2
%50 = call i8* @malloc(i32 16)
store i8* %50, i8** %8
%51 = load i8*, i8** %8
%52 = load i32, i32* %12
%53 = load i32*, i32** %6
%54 = call i32 @fread(i8* %51, i32 1, i32 %52, i32* %53)
%55 = load i8*, i8** %8
%56 = getelementptr inbounds i8, i8* %55, i64 1
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
store i32 %58, i32* %23
%59 = load i8*, i8** %8
%60 = getelementptr inbounds i8, i8* %59, i64 2
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
store i32 %62, i32* %24
br label %66
63: ; preds = %2
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%65 = call i32 @exit(i32 -1)
unreachable
66: ; preds = %49
%67 = load i32, i32* %23
%68 = mul nsw i32 65536, %67
%69 = load i32, i32* %24
%70 = mul nsw i32 %68, %69
%71 = mul nsw i32 %70, 3
%72 = call i8* @malloc(i32 %71)
store i8* %72, i8** %9
%73 = load i8*, i8** %9
%74 = load i32, i32* %23
%75 = mul nsw i32 65536, %74
%76 = load i32, i32* %24
%77 = mul nsw i32 %75, %76
%78 = mul nsw i32 %77, 3
%79 = call i32 @memset(i8* %73, i32 0, i32 %78)
%80 = load i32, i32* %23
%81 = mul nsw i32 256, %80
store i32 %81, i32* %13
%82 = load i32, i32* %24
%83 = mul nsw i32 256, %82
store i32 %83, i32* %14
%84 = getelementptr inbounds [18 x i8], [18 x i8]* %10, i64 0, i64 0
%85 = call i32 @memset(i8* %84, i32 0, i32 18)
%86 = getelementptr inbounds [18 x i8], [18 x i8]* %10, i64 0, i64 2
store i8 2, i8* %86
%87 = load i32, i32* %13
%88 = and i32 %87, 255
%89 = trunc i32 %88 to i8
%90 = getelementptr inbounds [18 x i8], [18 x i8]* %10, i64 0, i64 12
store i8 %89, i8* %90
%91 = load i32, i32* %13
%92 = ashr i32 %91, 8
%93 = trunc i32 %92 to i8
%94 = getelementptr inbounds [18 x i8], [18 x i8]* %10, i64 0, i64 13
store i8 %93, i8* %94
%95 = load i32, i32* %14
%96 = and i32 %95, 255
%97 = trunc i32 %96 to i8
%98 = getelementptr inbounds [18 x i8], [18 x i8]* %10, i64 0, i64 14
store i8 %97, i8* %98
%99 = load i32, i32* %14
%100 = ashr i32 %99, 8
%101 = trunc i32 %100 to i8
%102 = getelementptr inbounds [18 x i8], [18 x i8]* %10, i64 0, i64 15
store i8 %101, i8* %102
%103 = getelementptr inbounds [18 x i8], [18 x i8]* %10, i64 0, i64 16
store i8 24, i8* %103
%104 = getelementptr inbounds [18 x i8], [18 x i8]* %10, i64 0, i64 0
%105 = load i32*, i32** %7
%106 = call i32 @fwrite(i8* %104, i32 1, i32 18, i32* %105)
br label %107
107: ; preds = %66, %276
%108 = load i32*, i32** %6
%109 = call i32 @fgetc(i32* %108)
store i32 %109, i32* %11
%110 = load i32*, i32** %6
%111 = call i32 @fgetc(i32* %110)
%112 = shl i32 %111, 8
%113 = load i32, i32* %11
%114 = add nsw i32 %113, %112
store i32 %114, i32* %11
%115 = load i32*, i32** %6
%116 = call i32 @fgetc(i32* %115)
store i32 %116, i32* %12
%117 = load i32*, i32** %6
%118 = call i32 @fgetc(i32* %117)
%119 = shl i32 %118, 8
%120 = load i32, i32* %12
%121 = add nsw i32 %120, %119
store i32 %121, i32* %12
%122 = load i32, i32* %11
%123 = icmp ne i32 %122, 0
br i1 %123, label %128, label %124
124: ; preds = %107
%125 = load i32, i32* %12
%126 = icmp ne i32 %125, 0
br i1 %126, label %128, label %127
127: ; preds = %124
br label %277
128: ; preds = %124, %107
%129 = load i32, i32* %11
%130 = load i32, i32* %12
%131 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %129, i32 %130)
%132 = load i32, i32* %12
%133 = load i32, i32* %11
%134 = sub nsw i32 %132, %133
%135 = add nsw i32 %134, 1
%136 = load i32, i32* %23
%137 = load i32, i32* %24
%138 = mul nsw i32 %136, %137
%139 = sdiv i32 %138, 8
%140 = mul nsw i32 %135, %139
%141 = call i8* @malloc(i32 %140)
store i8* %141, i8** %8
%142 = load i8*, i8** %8
%143 = load i32, i32* %12
%144 = load i32, i32* %11
%145 = sub nsw i32 %143, %144
%146 = add nsw i32 %145, 1
%147 = load i32, i32* %23
%148 = load i32, i32* %24
%149 = mul nsw i32 %147, %148
%150 = sdiv i32 %149, 8
%151 = load i32*, i32** %6
%152 = call i32 @fread(i8* %142, i32 %146, i32 %150, i32* %151)
store i32 0, i32* %15
br label %153
153: ; preds = %273, %128
%154 = load i32, i32* %15
%155 = load i32, i32* %12
%156 = load i32, i32* %11
%157 = sub nsw i32 %155, %156
%158 = add nsw i32 %157, 1
%159 = icmp slt i32 %154, %158
br i1 %159, label %160, label %276
160: ; preds = %153
%161 = load i32, i32* %15
%162 = load i32, i32* %11
%163 = add nsw i32 %161, %162
store i32 %163, i32* %16
%164 = load i32, i32* %16
%165 = and i32 %164, 255
%166 = load i32, i32* %23
%167 = mul nsw i32 %165, %166
store i32 %167, i32* %19
%168 = load i32, i32* %16
%169 = ashr i32 %168, 8
%170 = load i32, i32* %24
%171 = mul nsw i32 %169, %170
store i32 %171, i32* %20
store i32 0, i32* %17
br label %172
172: ; preds = %269, %160
%173 = load i32, i32* %17
%174 = load i32, i32* %23
%175 = load i32, i32* %24
%176 = mul nsw i32 %174, %175
%177 = sdiv i32 %176, 8
%178 = icmp slt i32 %173, %177
br i1 %178, label %179, label %272
179: ; preds = %172
store i32 0, i32* %18
br label %180
180: ; preds = %265, %179
%181 = load i32, i32* %18
%182 = icmp slt i32 %181, 8
br i1 %182, label %183, label %268
183: ; preds = %180
%184 = load i8*, i8** %8
%185 = load i32, i32* %15
%186 = load i32, i32* %23
%187 = load i32, i32* %24
%188 = mul nsw i32 %186, %187
%189 = sdiv i32 %188, 8
%190 = mul nsw i32 %185, %189
%191 = load i32, i32* %17
%192 = add nsw i32 %190, %191
%193 = sext i32 %192 to i64
%194 = getelementptr inbounds i8, i8* %184, i64 %193
%195 = load i8, i8* %194
%196 = sext i8 %195 to i32
%197 = load i32, i32* %18
%198 = ashr i32 128, %197
%199 = and i32 %196, %198
%200 = icmp ne i32 %199, 0
br i1 %200, label %201, label %264
201: ; preds = %183
%202 = load i32, i32* %17
%203 = mul nsw i32 %202, 8
%204 = load i32, i32* %18
%205 = add nsw i32 %203, %204
%206 = load i32, i32* %23
%207 = srem i32 %205, %206
store i32 %207, i32* %21
%208 = load i32, i32* %17
%209 = mul nsw i32 %208, 8
%210 = load i32, i32* %18
%211 = add nsw i32 %209, %210
%212 = load i32, i32* %23
%213 = sdiv i32 %211, %212
store i32 %213, i32* %22
%214 = load i8*, i8** %9
%215 = load i32, i32* %14
%216 = load i32, i32* %20
%217 = load i32, i32* %22
%218 = add nsw i32 %216, %217
%219 = sub nsw i32 %215, %218
%220 = sub nsw i32 %219, 1
%221 = load i32, i32* %13
%222 = mul nsw i32 %220, %221
%223 = load i32, i32* %19
%224 = load i32, i32* %21
%225 = add nsw i32 %223, %224
%226 = add nsw i32 %222, %225
%227 = mul nsw i32 %226, 3
%228 = sext i32 %227 to i64
%229 = getelementptr inbounds i8, i8* %214, i64 %228
store i8 -1, i8* %229
%230 = load i8*, i8** %9
%231 = load i32, i32* %14
%232 = load i32, i32* %20
%233 = load i32, i32* %22
%234 = add nsw i32 %232, %233
%235 = sub nsw i32 %231, %234
%236 = sub nsw i32 %235, 1
%237 = load i32, i32* %13
%238 = mul nsw i32 %236, %237
%239 = load i32, i32* %19
%240 = load i32, i32* %21
%241 = add nsw i32 %239, %240
%242 = add nsw i32 %238, %241
%243 = mul nsw i32 %242, 3
%244 = add nsw i32 %243, 1
%245 = sext i32 %244 to i64
%246 = getelementptr inbounds i8, i8* %230, i64 %245
store i8 -1, i8* %246
%247 = load i8*, i8** %9
%248 = load i32, i32* %14
%249 = load i32, i32* %20
%250 = load i32, i32* %22
%251 = add nsw i32 %249, %250
%252 = sub nsw i32 %248, %251
%253 = sub nsw i32 %252, 1
%254 = load i32, i32* %13
%255 = mul nsw i32 %253, %254
%256 = load i32, i32* %19
%257 = load i32, i32* %21
%258 = add nsw i32 %256, %257
%259 = add nsw i32 %255, %258
%260 = mul nsw i32 %259, 3
%261 = add nsw i32 %260, 2
%262 = sext i32 %261 to i64
%263 = getelementptr inbounds i8, i8* %247, i64 %262
store i8 -1, i8* %263
br label %264
264: ; preds = %201, %183
br label %265
265: ; preds = %264
%266 = load i32, i32* %18
%267 = add nsw i32 %266, 1
store i32 %267, i32* %18
br label %180
268: ; preds = %180
br label %269
269: ; preds = %268
%270 = load i32, i32* %17
%271 = add nsw i32 %270, 1
store i32 %271, i32* %17
br label %172
272: ; preds = %172
br label %273
273: ; preds = %272
%274 = load i32, i32* %15
%275 = add nsw i32 %274, 1
store i32 %275, i32* %15
br label %153
276: ; preds = %153
br label %107
277: ; preds = %127
%278 = load i8*, i8** %9
%279 = load i32, i32* %24
%280 = mul nsw i32 256, %279
%281 = load i32, i32* %23
%282 = mul nsw i32 256, %281
%283 = mul nsw i32 %282, 3
%284 = load i32*, i32** %7
%285 = call i32 @fwrite(i8* %278, i32 %280, i32 %283, i32* %284)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.3 = [13 x i8] c"chunk %d-%d\0A\00"
@str = [10 x i8] c"no header\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [18 x i8]
%4 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @fgetc(i32* %7)
%12 = tail call i32 @fgetc(i32* %7)
%13 = shl i32 %12, 8
%14 = add nsw i32 %13, %11
%15 = tail call i32 @fgetc(i32* %7)
%16 = tail call i32 @fgetc(i32* %7)
%17 = icmp eq i32 %14, 48896
br i1 %17, label %18, label %61
18: ; preds = %2
%19 = shl i32 %16, 8
%20 = add nsw i32 %19, %15
%21 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%22 = tail call i32 @fread(i8* %21, i32 1, i32 %20, i32* %7)
%23 = getelementptr inbounds i8, i8* %21, i64 1
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = getelementptr inbounds i8, i8* %21, i64 2
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = mul nsw i32 %25, 196608
%30 = mul i32 %29, %28
%31 = tail call i8* @malloc(i32 %30)
%32 = tail call i32 @memset(i8* %31, i32 0, i32 %30)
%33 = shl nsw i32 %28, 8
%34 = call i32 @memset(i8* %4, i32 0, i32 18)
%35 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 2
store i8 2, i8* %35
%36 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 12
store i8 0, i8* %36
%37 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 13
store i8 %24, i8* %37
%38 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 14
store i8 0, i8* %38
%39 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 15
store i8 %27, i8* %39
%40 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 16
store i8 24, i8* %40
%41 = call i32 @fwrite(i8* %4, i32 1, i32 18, i32* %10)
%42 = call i32 @fgetc(i32* %7)
%43 = call i32 @fgetc(i32* %7)
%44 = shl i32 %43, 8
%45 = add nsw i32 %44, %42
%46 = call i32 @fgetc(i32* %7)
%47 = call i32 @fgetc(i32* %7)
%48 = shl i32 %47, 8
%49 = add nsw i32 %48, %46
%50 = icmp ne i32 %45, 0
%51 = icmp ne i32 %49, 0
%52 = select i1 %50, i1 true, i1 %51
br i1 %52, label %53, label %141
53: ; preds = %18
%54 = mul nsw i32 %28, %25
%55 = trunc i32 %54 to i16
%56 = sdiv i16 %55, 8
%57 = sext i16 %56 to i32
%58 = icmp sgt i32 %54, 7
%59 = sext i16 %56 to i64
%60 = zext i32 %57 to i64
br label %76
61: ; preds = %2
%62 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%63 = tail call i32 @exit(i32 -1)
unreachable
64: ; preds = %138, %76
%65 = call i32 @fgetc(i32* %7)
%66 = call i32 @fgetc(i32* %7)
%67 = shl i32 %66, 8
%68 = add nsw i32 %67, %65
%69 = call i32 @fgetc(i32* %7)
%70 = call i32 @fgetc(i32* %7)
%71 = shl i32 %70, 8
%72 = add nsw i32 %71, %69
%73 = icmp ne i32 %68, 0
%74 = icmp ne i32 %72, 0
%75 = select i1 %73, i1 true, i1 %74
br i1 %75, label %76, label %141
76: ; preds = %53, %64
%77 = phi i32 [ %49, %53 ], [ %72, %64 ]
%78 = phi i32 [ %45, %53 ], [ %68, %64 ]
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %78, i32 %77)
%80 = sub nsw i32 %77, %78
%81 = add nsw i32 %80, 1
%82 = mul nsw i32 %81, %57
%83 = call i8* @malloc(i32 %82)
%84 = call i32 @fread(i8* %83, i32 %81, i32 %57, i32* %7)
%85 = icmp slt i32 %80, 0
br i1 %85, label %64, label %86
86: ; preds = %76
%87 = add i32 %77, 1
%88 = sub i32 %87, %78
%89 = zext i32 %88 to i64
br label %90
90: ; preds = %86, %138
%91 = phi i64 [ 0, %86 ], [ %139, %138 ]
%92 = trunc i64 %91 to i32
%93 = add i32 %78, %92
%94 = and i32 %93, 255
%95 = ashr i32 %93, 8
%96 = mul nsw i32 %95, %28
br i1 %58, label %97, label %138
97: ; preds = %90
%98 = mul nsw i64 %91, %59
br label %99
99: ; preds = %97, %135
%100 = phi i64 [ 0, %97 ], [ %136, %135 ]
%101 = add nsw i64 %100, %98
%102 = getelementptr inbounds i8, i8* %83, i64 %101
%103 = load i8, i8* %102
%104 = zext i8 %103 to i32
%105 = trunc i64 %100 to i32
%106 = shl i32 %105, 3
br label %107
107: ; preds = %99, %132
%108 = phi i32 [ 0, %99 ], [ %133, %132 ]
%109 = lshr i32 128, %108
%110 = and i32 %109, %104
%111 = icmp eq i32 %110, 0
br i1 %111, label %132, label %112
112: ; preds = %107
%113 = add nuw nsw i32 %108, %106
%114 = srem i32 %113, %25
%115 = sdiv i32 %113, %25
%116 = add nsw i32 %115, %96
%117 = xor i32 %116, -1
%118 = add i32 %33, %117
%119 = shl i32 %118, 8
%120 = or i32 %119, %94
%121 = mul i32 %120, %25
%122 = add i32 %121, %114
%123 = mul nsw i32 %122, 3
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds i8, i8* %31, i64 %124
store i8 -1, i8* %125
%126 = add nsw i32 %123, 1
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds i8, i8* %31, i64 %127
store i8 -1, i8* %128
%129 = add nsw i32 %123, 2
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds i8, i8* %31, i64 %130
store i8 -1, i8* %131
br label %132
132: ; preds = %107, %112
%133 = add nuw nsw i32 %108, 1
%134 = icmp eq i32 %133, 8
br i1 %134, label %135, label %107
135: ; preds = %132
%136 = add nuw nsw i64 %100, 1
%137 = icmp eq i64 %136, %60
br i1 %137, label %138, label %99
138: ; preds = %135, %90
%139 = add nuw nsw i64 %91, 1
%140 = icmp eq i64 %139, %89
br i1 %140, label %64, label %90
141: ; preds = %64, %18
%142 = mul nsw i32 %25, 768
%143 = call i32 @fwrite(i8* %31, i32 %33, i32 %142, i32* %10)
ret i32 0
}