#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
unsigned char *compress(int /*<<< orphan*/, unsigned char *, size_t, long,
                        size_t *, long *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
size_t fread(unsigned char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
size_t fwrite(unsigned char *, int, size_t, int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ optimize(unsigned char *, size_t, long);
long parse_long(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ reverse(unsigned char *, unsigned char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
int main(int argc, char *argv[]) {
  long skip = 0;
  int forced_mode = 0;
  int backwards_mode = 0;
  char *output_name;
  unsigned char *input_data;
  unsigned char *output_data;
  FILE *ifp;
  FILE *ofp;
  size_t input_size;
  size_t output_size;
  size_t partial_counter;
  size_t total_counter;
  long delta;
  int i;
  printf("ZX7: Optimal LZ77/LZSS compression by Einar Saukas\n");
  for (i = 1; i < argc && (*argv[i] == '-' || *argv[i] == '+'); i++) {
    if (!strcmp(argv[i], "-f")) {
      forced_mode = 1;
    } else if (!strcmp(argv[i], "-b")) {
      backwards_mode = 1;
    } else if ((skip = parse_long(argv[i])) <= 0) {
      fprintf(stderr, "Error: Invalid parameter %s\n", argv[i]);
      exit(1);
    }
  }
  if (argc == i + 1) {
    output_name = (char *)malloc(strlen(argv[i]) + 5);
    strcpy(output_name, argv[i]);
    strcat(output_name, ".zx7");
  } else if (argc == i + 2) {
    output_name = argv[i + 1];
  } else {
    fprintf(stderr,
            "Usage: %s [-f] [-b] input [output.zx7]\n"
            "  -f      Force overwrite of output file\n"
            "  -b      Compress backwards\n",
            argv[0]);
    exit(1);
  }
  ifp = fopen(argv[i], "rb");
  if (!ifp) {
    fprintf(stderr, "Error: Cannot access input file %s\n", argv[i]);
    exit(1);
  }
  fseek(ifp, 0L, SEEK_END);
  input_size = ftell(ifp);
  fseek(ifp, 0L, SEEK_SET);
  if (!input_size) {
    fprintf(stderr, "Error: Empty input file %s\n", argv[i]);
    exit(1);
  }
  if (skip >= input_size) {
    fprintf(stderr, "Error: Skipping entire input file %s\n", argv[i]);
    exit(1);
  }
  input_data = (unsigned char *)malloc(input_size);
  if (!input_data) {
    fprintf(stderr, "Error: Insufficient memory\n");
    exit(1);
  }
  total_counter = 0;
  do {
    partial_counter = fread(input_data + total_counter, sizeof(char),
                            input_size - total_counter, ifp);
    total_counter += partial_counter;
  } while (partial_counter > 0);
  if (total_counter != input_size) {
    fprintf(stderr, "Error: Cannot read input file %s\n", argv[i]);
    exit(1);
  }
  fclose(ifp);
  if (!forced_mode && fopen(output_name, "rb") != NULL) {
    fprintf(stderr, "Error: Already existing output file %s\n", output_name);
    exit(1);
  }
  ofp = fopen(output_name, "wb");
  if (!ofp) {
    fprintf(stderr, "Error: Cannot create output file %s\n", output_name);
    exit(1);
  }
  if (backwards_mode) {
    reverse(input_data, input_data + input_size - 1);
  }
  output_data = compress(optimize(input_data, input_size, skip), input_data,
                         input_size, skip, &output_size, &delta);
  if (backwards_mode) {
    reverse(output_data, output_data + output_size - 1);
  }
  if (fwrite(output_data, sizeof(char), output_size, ofp) != output_size) {
    fprintf(stderr, "Error: Cannot write output file %s\n", output_name);
    exit(1);
  }
  fclose(ofp);
  printf("File%s converted%s from %lu to %lu bytes! (delta %ld)\n",
         (skip ? " partially" : ""), (backwards_mode ? " backwards" : ""),
         (unsigned long)(input_size - skip), (unsigned long)output_size, delta);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
movl   $0x1,-0x74(%rbp)
mov    -0x74(%rbp),%ecx
xor    %eax,%eax
cmp    -0x8(%rbp),%ecx
mov    %al,-0x75(%rbp)
jge    12b0 <main+0x90>
mov    -0x10(%rbp),%rax
movslq -0x74(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x2d,%ecx
mov    %al,-0x76(%rbp)
je     12aa <main+0x8a>
mov    -0x10(%rbp),%rax
movslq -0x74(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
sete   %al
mov    %al,-0x76(%rbp)
mov    -0x76(%rbp),%al
mov    %al,-0x75(%rbp)
mov    -0x75(%rbp),%al
test   $0x1,%al
jne    12c0 <main+0xa0>
jmp    1383 <main+0x163>
mov    -0x10(%rbp),%rax
movslq -0x74(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd61(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    12ed <main+0xcd>
movl   $0x1,-0x1c(%rbp)
jmp    1370 <main+0x150>
mov    -0x10(%rbp),%rax
movslq -0x74(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd37(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    131a <main+0xfa>
movl   $0x1,-0x20(%rbp)
jmp    136b <main+0x14b>
mov    -0x10(%rbp),%rax
movslq -0x74(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10e0 <parse_long@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jg     1366 <main+0x146>
mov    0x2c98(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x74(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xce5(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
jmp    136b <main+0x14b>
jmp    1370 <main+0x150>
jmp    1375 <main+0x155>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1264 <main+0x44>
mov    -0x8(%rbp),%eax
mov    -0x74(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jne    13df <main+0x1bf>
mov    -0x10(%rbp),%rax
movslq -0x74(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <strlen@plt>
mov    %rax,%rdi
add    $0x5,%rdi
call   10f0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x74(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1050 <strcpy@plt>
mov    -0x28(%rbp),%rdi
lea    0xc82(%rip),%rsi
call   1120 <strcat@plt>
jmp    1437 <main+0x217>
mov    -0x8(%rbp),%eax
mov    -0x74(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jne    140a <main+0x1ea>
mov    -0x10(%rbp),%rax
mov    -0x74(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
jmp    1432 <main+0x212>
mov    0x2bc7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xc3b(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
jmp    1437 <main+0x217>
mov    -0x10(%rbp),%rax
movslq -0x74(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xc80(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    148b <main+0x26b>
mov    0x2b73(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x74(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xc53(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x40(%rbp),%rdi
mov    0x2b52(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1100 <fseek@plt>
mov    -0x40(%rbp),%rdi
call   10c0 <ftell@plt>
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rdi
mov    0x2b17(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1100 <fseek@plt>
cmpq   $0x0,-0x50(%rbp)
jne    14fc <main+0x2dc>
mov    0x2b02(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x74(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xc06(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x18(%rbp),%rax
cmp    -0x50(%rbp),%rax
jb     1537 <main+0x317>
mov    0x2ac7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x74(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xbe7(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x50(%rbp),%rdi
call   10f0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1570 <main+0x350>
mov    0x2a82(%rip),%rax
mov    (%rax),%edi
lea    0xbd4(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
movq   $0x0,-0x68(%rbp)
mov    -0x30(%rbp),%rdi
add    -0x68(%rbp),%rdi
mov    -0x50(%rbp),%rdx
sub    -0x68(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fread@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
add    -0x68(%rbp),%rax
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x60(%rbp)
ja     1578 <main+0x358>
mov    -0x68(%rbp),%rax
cmp    -0x50(%rbp),%rax
je     15ec <main+0x3cc>
mov    0x2a12(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x74(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xb74(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x40(%rbp),%rdi
call   1070 <fclose@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    163e <main+0x41e>
mov    -0x28(%rbp),%rdi
lea    0xac0(%rip),%rsi
call   1110 <fopen@plt>
cmp    $0x0,%rax
je     163e <main+0x41e>
mov    0x29b8(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xb44(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x28(%rbp),%rdi
lea    0xb50(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1682 <main+0x462>
mov    0x2974(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xb2b(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
cmpl   $0x0,-0x20(%rbp)
je     16a1 <main+0x481>
mov    -0x30(%rbp),%rdi
mov    -0x30(%rbp),%rsi
add    -0x50(%rbp),%rsi
add    $0xffffffffffffffff,%rsi
call   1030 <reverse@plt>
mov    -0x30(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   10d0 <optimize@plt>
mov    %eax,%edi
mov    -0x30(%rbp),%rsi
mov    -0x50(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x58(%rbp),%r8
lea    -0x70(%rbp),%r9
call   1040 <compress@plt>
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     16f0 <main+0x4d0>
mov    -0x38(%rbp),%rdi
mov    -0x38(%rbp),%rsi
add    -0x58(%rbp),%rsi
add    $0xffffffffffffffff,%rsi
call   1030 <reverse@plt>
mov    -0x38(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    $0x1,%esi
call   1140 <fwrite@plt>
cmp    -0x58(%rbp),%rax
je     1735 <main+0x515>
mov    0x28c1(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xa9d(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x48(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x18(%rbp),%rcx
lea    0xad2(%rip),%rsi
lea    0xacc(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
mov    -0x20(%rbp),%ecx
lea    0xab9(%rip),%rdx
lea    0xabe(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
mov    -0x50(%rbp),%rcx
sub    -0x18(%rbp),%rcx
mov    -0x58(%rbp),%r8
mov    -0x70(%rbp),%r9
lea    0xa5e(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xfb4(%rip),%rdi
call   1060 <puts@plt>
cmp    $0x2,%ebx
jl     12ec <main+0xbc>
mov    %ebx,0x8(%rsp)
mov    %ebx,%r12d
xor    %r13d,%r13d
mov    $0x1,%r15d
lea    0xd91(%rip),%rbx
movl   $0x0,0x4(%rsp)
xor    %eax,%eax
mov    %rax,0x18(%rsp)
jmp    1291 <main+0x61>
movl   $0x1,0x4(%rsp)
add    $0x1,%r15
cmp    %r15,%r12
je     1306 <main+0xd6>
mov    (%r14,%r15,8),%rbp
movzbl 0x0(%rbp),%eax
cmp    $0x2d,%al
je     12a1 <main+0x71>
cmp    $0x2b,%al
jne    1309 <main+0xd9>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10b0 <strcmp@plt>
test   %eax,%eax
je     1280 <main+0x50>
mov    %rbp,%rdi
lea    0xd49(%rip),%rsi
call   10b0 <strcmp@plt>
test   %eax,%eax
je     12e0 <main+0xb0>
mov    %rbp,%rdi
call   10f0 <parse_long@plt>
mov    %rax,%r13
test   %rax,%rax
jg     1288 <main+0x58>
jmp    1537 <main+0x307>
nopl   0x0(%rax,%rax,1)
mov    $0x1,%eax
mov    %rax,0x18(%rsp)
jmp    1288 <main+0x58>
xor    %eax,%eax
mov    %rax,0x18(%rsp)
mov    $0x1,%r15d
movl   $0x0,0x4(%rsp)
xor    %r13d,%r13d
jmp    130d <main+0xdd>
mov    %r12d,%r15d
mov    0x8(%rsp),%ebx
lea    0x1(%r15),%eax
cmp    %ebx,%eax
jne    134a <main+0x11a>
mov    %r15d,%ebx
mov    (%r14,%rbx,8),%rdi
call   1090 <strlen@plt>
lea    0x5(%rax),%rdi
call   1100 <malloc@plt>
mov    %rax,%r12
mov    (%r14,%rbx,8),%rsi
mov    %rax,%rdi
call   1050 <strcpy@plt>
lea    0xce3(%rip),%rsi
mov    %r12,%rdi
call   1130 <strcat@plt>
jmp    135f <main+0x12f>
lea    0x2(%r15),%ecx
cmp    %ebx,%ecx
jne    15fb <main+0x3cb>
mov    %eax,%eax
mov    (%r14,%rax,8),%r12
mov    %r15d,%ebx
mov    (%r14,%rbx,8),%rdi
lea    0xd2c(%rip),%rsi
call   1120 <fopen@plt>
test   %rax,%rax
je     1550 <main+0x320>
mov    %rax,%r15
mov    0x2c66(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1110 <fseek@plt>
mov    %r15,%rdi
call   10d0 <ftell@plt>
mov    %rax,%rbp
mov    0x2c30(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1110 <fseek@plt>
test   %rbp,%rbp
je     1569 <main+0x339>
mov    %rbp,%rax
sub    %r13,%rax
jbe    1582 <main+0x352>
mov    %rbx,0x20(%rsp)
mov    %rax,0x28(%rsp)
mov    %r12,0x8(%rsp)
mov    %rbp,%rdi
call   1100 <malloc@plt>
test   %rax,%rax
je     159b <main+0x36b>
mov    %rax,%rbx
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
lea    (%rbx,%r12,1),%rdi
mov    %rbp,%rdx
sub    %r12,%rdx
mov    $0x1,%esi
mov    %r15,%rcx
call   1070 <fread@plt>
add    %rax,%r12
test   %rax,%rax
jne    13f0 <main+0x1c0>
cmp    %rbp,%r12
jne    15bc <main+0x38c>
mov    %r15,%rdi
call   1080 <fclose@plt>
cmpl   $0x0,0x4(%rsp)
mov    0x8(%rsp),%r12
jne    1444 <main+0x214>
lea    0xc63(%rip),%rsi
mov    %r12,%rdi
call   1120 <fopen@plt>
test   %rax,%rax
jne    1610 <main+0x3e0>
lea    0xd1a(%rip),%rsi
mov    %r12,%rdi
call   1120 <fopen@plt>
test   %rax,%rax
mov    0x18(%rsp),%r15
je     15d7 <main+0x3a7>
mov    %rax,%r14
test   %r15d,%r15d
je     1479 <main+0x249>
lea    (%rbx,%rbp,1),%rsi
add    $0xffffffffffffffff,%rsi
mov    %rbx,%rdi
call   1030 <reverse@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
call   10e0 <optimize@plt>
lea    0x10(%rsp),%r8
lea    0x30(%rsp),%r9
mov    %eax,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %r13,%rcx
call   1040 <compress@plt>
mov    %rax,%rbx
test   %r15d,%r15d
je     14be <main+0x28e>
mov    0x10(%rsp),%rax
lea    (%rbx,%rax,1),%rsi
add    $0xffffffffffffffff,%rsi
mov    %rbx,%rdi
call   1030 <reverse@plt>
mov    0x10(%rsp),%rdx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14,%rcx
call   1150 <fwrite@plt>
cmp    0x10(%rsp),%rax
jne    15e9 <main+0x3b9>
mov    %r14,%rdi
call   1080 <fclose@plt>
test   %r13,%r13
lea    0xcf7(%rip),%rax
lea    0xcf1(%rip),%rsi
cmove  %rax,%rsi
test   %r15d,%r15d
lea    0xcee(%rip),%rdx
cmove  %rax,%rdx
mov    0x10(%rsp),%r8
mov    0x30(%rsp),%r9
lea    0xc97(%rip),%rdi
mov    0x28(%rsp),%rcx
xor    %eax,%eax
call   10a0 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2a9a(%rip),%rax
mov    (%rax),%edi
mov    (%r14,%r15,8),%rdx
lea    0xabb(%rip),%rsi
jmp    1623 <main+0x3f3>
mov    0x2a81(%rip),%rax
mov    (%rax),%edi
mov    (%r14,%rbx,8),%rdx
lea    0xb35(%rip),%rsi
jmp    1623 <main+0x3f3>
mov    0x2a68(%rip),%rax
mov    (%rax),%edi
mov    (%r14,%rbx,8),%rdx
lea    0xb40(%rip),%rsi
jmp    1623 <main+0x3f3>
mov    0x2a4f(%rip),%rax
mov    (%rax),%edi
mov    (%r14,%rbx,8),%rdx
lea    0xb43(%rip),%rsi
jmp    1623 <main+0x3f3>
mov    0x2a36(%rip),%rax
mov    (%rax),%edi
lea    0xb54(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    0x2a15(%rip),%rax
mov    (%rax),%edi
mov    0x20(%rsp),%rax
mov    (%r14,%rax,8),%rdx
lea    0xb46(%rip),%rsi
jmp    1623 <main+0x3f3>
mov    0x29fa(%rip),%rax
mov    (%rax),%edi
lea    0xb81(%rip),%rsi
jmp    1620 <main+0x3f0>
mov    0x29e8(%rip),%rax
mov    (%rax),%edi
lea    0xb94(%rip),%rsi
jmp    1620 <main+0x3f0>
mov    0x29d6(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xa1a(%rip),%rsi
jmp    1623 <main+0x3f3>
mov    0x29c1(%rip),%rax
mov    (%rax),%edi
lea    0xb1d(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1140 <exit@plt>

LLVM IR (-O0):
@.str = [52 x i8] c"ZX7: Optimal LZ77/LZSS compression by Einar Saukas\0A\00"
@.str.1 = [3 x i8] c"-f\00"
@.str.2 = [3 x i8] c"-b\00"
@stderr = global i32 0
@.str.3 = [29 x i8] c"Error: Invalid parameter %s\0A\00"
@.str.4 = [5 x i8] c".zx7\00"
@.str.5 = [110 x i8] c"Usage: %s [-f] [-b] input [output.zx7]\0A -f Force overwrite of output file\0A -b Compress backwards\0A\00"
@.str.6 = [3 x i8] c"rb\00"
@.str.7 = [36 x i8] c"Error: Cannot access input file %s\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.8 = [28 x i8] c"Error: Empty input file %s\0A\00"
@.str.9 = [38 x i8] c"Error: Skipping entire input file %s\0A\00"
@.str.10 = [28 x i8] c"Error: Insufficient memory\0A\00"
@.str.11 = [34 x i8] c"Error: Cannot read input file %s\0A\00"
@.str.12 = [40 x i8] c"Error: Already existing output file %s\0A\00"
@.str.13 = [3 x i8] c"wb\00"
@.str.14 = [37 x i8] c"Error: Cannot create output file %s\0A\00"
@.str.15 = [36 x i8] c"Error: Cannot write output file %s\0A\00"
@.str.16 = [55 x i8] c"File%s converted%s from %lu to %lu bytes! (delta %ld)\0A\00"
@.str.17 = [11 x i8] c" partially\00"
@.str.18 = [1 x i8] zeroinitializer
@.str.19 = [11 x i8] c" backwards\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
%19 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
store i32 0, i32* %7
store i32 0, i32* %8
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %19
br label %21
21: ; preds = %85, %2
%22 = load i32, i32* %19
%23 = load i32, i32* %4
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %45
25: ; preds = %21
%26 = load i8**, i8*** %5
%27 = load i32, i32* %19
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 45
br i1 %33, label %43, label %34
34: ; preds = %25
%35 = load i8**, i8*** %5
%36 = load i32, i32* %19
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %35, i64 %37
%39 = load i8*, i8** %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 43
br label %43
43: ; preds = %34, %25
%44 = phi i1 [ true, %25 ], [ %42, %34 ]
br label %45
45: ; preds = %43, %21
%46 = phi i1 [ false, %21 ], [ %44, %43 ]
br i1 %46, label %47, label %88
47: ; preds = %45
%48 = load i8**, i8*** %5
%49 = load i32, i32* %19
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = call i32 @strcmp(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%54 = icmp ne i32 %53, 0
br i1 %54, label %56, label %55
55: ; preds = %47
store i32 1, i32* %7
br label %84
56: ; preds = %47
%57 = load i8**, i8*** %5
%58 = load i32, i32* %19
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8*, i8** %57, i64 %59
%61 = load i8*, i8** %60
%62 = call i32 @strcmp(i8* %61, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%63 = icmp ne i32 %62, 0
br i1 %63, label %65, label %64
64: ; preds = %56
store i32 1, i32* %8
br label %83
65: ; preds = %56
%66 = load i8**, i8*** %5
%67 = load i32, i32* %19
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8*, i8** %66, i64 %68
%70 = load i8*, i8** %69
%71 = call i64 @parse_long(i8* %70)
store i64 %71, i64* %6
%72 = icmp sle i64 %71, 0
br i1 %72, label %73, label %82
73: ; preds = %65
%74 = load i32, i32* @stderr
%75 = load i8**, i8*** %5
%76 = load i32, i32* %19
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8*, i8** %75, i64 %77
%79 = load i8*, i8** %78
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %79)
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %65
br label %83
83: ; preds = %82, %64
br label %84
84: ; preds = %83, %55
br label %85
85: ; preds = %84
%86 = load i32, i32* %19
%87 = add nsw i32 %86, 1
store i32 %87, i32* %19
br label %21
88: ; preds = %45
%89 = load i32, i32* %4
%90 = load i32, i32* %19
%91 = add nsw i32 %90, 1
%92 = icmp eq i32 %89, %91
br i1 %92, label %93, label %112
93: ; preds = %88
%94 = load i8**, i8*** %5
%95 = load i32, i32* %19
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i8*, i8** %94, i64 %96
%98 = load i8*, i8** %97
%99 = call i64 @strlen(i8* %98)
%100 = add i64 %99, 5
%101 = call i64 @malloc(i64 %100)
%102 = inttoptr i64 %101 to i8*
store i8* %102, i8** %9
%103 = load i8*, i8** %9
%104 = load i8**, i8*** %5
%105 = load i32, i32* %19
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds i8*, i8** %104, i64 %106
%108 = load i8*, i8** %107
%109 = call i32 @strcpy(i8* %103, i8* %108)
%110 = load i8*, i8** %9
%111 = call i32 @strcat(i8* %110, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %132
112: ; preds = %88
%113 = load i32, i32* %4
%114 = load i32, i32* %19
%115 = add nsw i32 %114, 2
%116 = icmp eq i32 %113, %115
br i1 %116, label %117, label %124
117: ; preds = %112
%118 = load i8**, i8*** %5
%119 = load i32, i32* %19
%120 = add nsw i32 %119, 1
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds i8*, i8** %118, i64 %121
%123 = load i8*, i8** %122
store i8* %123, i8** %9
br label %131
124: ; preds = %112
%125 = load i32, i32* @stderr
%126 = load i8**, i8*** %5
%127 = getelementptr inbounds i8*, i8** %126, i64 0
%128 = load i8*, i8** %127
%129 = call i32 (i32, i8*, ...) @fprintf(i32 %125, i8* getelementptr inbounds ([110 x i8], [110 x i8]* @.str.5, i64 0, i64 0), i8* %128)
%130 = call i32 @exit(i32 1)
unreachable
131: ; preds = %117
br label %132
132: ; preds = %131, %93
%133 = load i8**, i8*** %5
%134 = load i32, i32* %19
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds i8*, i8** %133, i64 %135
%137 = load i8*, i8** %136
%138 = call i32* @fopen(i8* %137, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %138, i32** %12
%139 = load i32*, i32** %12
%140 = icmp ne i32* %139, null
br i1 %140, label %150, label %141
141: ; preds = %132
%142 = load i32, i32* @stderr
%143 = load i8**, i8*** %5
%144 = load i32, i32* %19
%145 = sext i32 %144 to i64
%146 = getelementptr inbounds i8*, i8** %143, i64 %145
%147 = load i8*, i8** %146
%148 = call i32 (i32, i8*, ...) @fprintf(i32 %142, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* %147)
%149 = call i32 @exit(i32 1)
unreachable
150: ; preds = %132
%151 = load i32*, i32** %12
%152 = load i32, i32* @SEEK_END
%153 = call i32 @fseek(i32* %151, i64 0, i32 %152)
%154 = load i32*, i32** %12
%155 = call i64 @ftell(i32* %154)
store i64 %155, i64* %14
%156 = load i32*, i32** %12
%157 = load i32, i32* @SEEK_SET
%158 = call i32 @fseek(i32* %156, i64 0, i32 %157)
%159 = load i64, i64* %14
%160 = icmp ne i64 %159, 0
br i1 %160, label %170, label %161
161: ; preds = %150
%162 = load i32, i32* @stderr
%163 = load i8**, i8*** %5
%164 = load i32, i32* %19
%165 = sext i32 %164 to i64
%166 = getelementptr inbounds i8*, i8** %163, i64 %165
%167 = load i8*, i8** %166
%168 = call i32 (i32, i8*, ...) @fprintf(i32 %162, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %167)
%169 = call i32 @exit(i32 1)
unreachable
170: ; preds = %150
%171 = load i64, i64* %6
%172 = load i64, i64* %14
%173 = icmp uge i64 %171, %172
br i1 %173, label %174, label %183
174: ; preds = %170
%175 = load i32, i32* @stderr
%176 = load i8**, i8*** %5
%177 = load i32, i32* %19
%178 = sext i32 %177 to i64
%179 = getelementptr inbounds i8*, i8** %176, i64 %178
%180 = load i8*, i8** %179
%181 = call i32 (i32, i8*, ...) @fprintf(i32 %175, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.9, i64 0, i64 0), i8* %180)
%182 = call i32 @exit(i32 1)
unreachable
183: ; preds = %170
%184 = load i64, i64* %14
%185 = call i64 @malloc(i64 %184)
%186 = inttoptr i64 %185 to i8*
store i8* %186, i8** %10
%187 = load i8*, i8** %10
%188 = icmp ne i8* %187, null
br i1 %188, label %193, label %189
189: ; preds = %183
%190 = load i32, i32* @stderr
%191 = call i32 (i32, i8*, ...) @fprintf(i32 %190, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
%192 = call i32 @exit(i32 1)
unreachable
193: ; preds = %183
store i64 0, i64* %17
br label %194
194: ; preds = %206, %193
%195 = load i8*, i8** %10
%196 = load i64, i64* %17
%197 = getelementptr inbounds i8, i8* %195, i64 %196
%198 = load i64, i64* %14
%199 = load i64, i64* %17
%200 = sub i64 %198, %199
%201 = load i32*, i32** %12
%202 = call i64 @fread(i8* %197, i32 1, i64 %200, i32* %201)
store i64 %202, i64* %16
%203 = load i64, i64* %16
%204 = load i64, i64* %17
%205 = add i64 %204, %203
store i64 %205, i64* %17
br label %206
206: ; preds = %194
%207 = load i64, i64* %16
%208 = icmp ugt i64 %207, 0
br i1 %208, label %194, label %209
209: ; preds = %206
%210 = load i64, i64* %17
%211 = load i64, i64* %14
%212 = icmp ne i64 %210, %211
br i1 %212, label %213, label %222
213: ; preds = %209
%214 = load i32, i32* @stderr
%215 = load i8**, i8*** %5
%216 = load i32, i32* %19
%217 = sext i32 %216 to i64
%218 = getelementptr inbounds i8*, i8** %215, i64 %217
%219 = load i8*, i8** %218
%220 = call i32 (i32, i8*, ...) @fprintf(i32 %214, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0), i8* %219)
%221 = call i32 @exit(i32 1)
unreachable
222: ; preds = %209
%223 = load i32*, i32** %12
%224 = call i32 @fclose(i32* %223)
%225 = load i32, i32* %7
%226 = icmp ne i32 %225, 0
br i1 %226, label %236, label %227
227: ; preds = %222
%228 = load i8*, i8** %9
%229 = call i32* @fopen(i8* %228, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%230 = icmp ne i32* %229, null
br i1 %230, label %231, label %236
231: ; preds = %227
%232 = load i32, i32* @stderr
%233 = load i8*, i8** %9
%234 = call i32 (i32, i8*, ...) @fprintf(i32 %232, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.12, i64 0, i64 0), i8* %233)
%235 = call i32 @exit(i32 1)
unreachable
236: ; preds = %227, %222
%237 = load i8*, i8** %9
%238 = call i32* @fopen(i8* %237, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0))
store i32* %238, i32** %13
%239 = load i32*, i32** %13
%240 = icmp ne i32* %239, null
br i1 %240, label %246, label %241
241: ; preds = %236
%242 = load i32, i32* @stderr
%243 = load i8*, i8** %9
%244 = call i32 (i32, i8*, ...) @fprintf(i32 %242, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.14, i64 0, i64 0), i8* %243)
%245 = call i32 @exit(i32 1)
unreachable
246: ; preds = %236
%247 = load i32, i32* %8
%248 = icmp ne i32 %247, 0
br i1 %248, label %249, label %256
249: ; preds = %246
%250 = load i8*, i8** %10
%251 = load i8*, i8** %10
%252 = load i64, i64* %14
%253 = getelementptr inbounds i8, i8* %251, i64 %252
%254 = getelementptr inbounds i8, i8* %253, i64 -1
%255 = call i32 @reverse(i8* %250, i8* %254)
br label %256
256: ; preds = %249, %246
%257 = load i8*, i8** %10
%258 = load i64, i64* %14
%259 = load i64, i64* %6
%260 = call i32 @optimize(i8* %257, i64 %258, i64 %259)
%261 = load i8*, i8** %10
%262 = load i64, i64* %14
%263 = load i64, i64* %6
%264 = call i8* @compress(i32 %260, i8* %261, i64 %262, i64 %263, i64* %15, i64* %18)
store i8* %264, i8** %11
%265 = load i32, i32* %8
%266 = icmp ne i32 %265, 0
br i1 %266, label %267, label %274
267: ; preds = %256
%268 = load i8*, i8** %11
%269 = load i8*, i8** %11
%270 = load i64, i64* %15
%271 = getelementptr inbounds i8, i8* %269, i64 %270
%272 = getelementptr inbounds i8, i8* %271, i64 -1
%273 = call i32 @reverse(i8* %268, i8* %272)
br label %274
274: ; preds = %267, %256
%275 = load i8*, i8** %11
%276 = load i64, i64* %15
%277 = load i32*, i32** %13
%278 = call i64 @fwrite(i8* %275, i32 1, i64 %276, i32* %277)
%279 = load i64, i64* %15
%280 = icmp ne i64 %278, %279
br i1 %280, label %281, label %286
281: ; preds = %274
%282 = load i32, i32* @stderr
%283 = load i8*, i8** %9
%284 = call i32 (i32, i8*, ...) @fprintf(i32 %282, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.15, i64 0, i64 0), i8* %283)
%285 = call i32 @exit(i32 1)
unreachable
286: ; preds = %274
%287 = load i32*, i32** %13
%288 = call i32 @fclose(i32* %287)
%289 = load i64, i64* %6
%290 = icmp ne i64 %289, 0
%291 = zext i1 %290 to i64
%292 = select i1 %290, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.17, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.18, i64 0, i64 0)
%293 = load i32, i32* %8
%294 = icmp ne i32 %293, 0
%295 = zext i1 %294 to i64
%296 = select i1 %294, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.19, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.18, i64 0, i64 0)
%297 = load i64, i64* %14
%298 = load i64, i64* %6
%299 = sub i64 %297, %298
%300 = load i64, i64* %15
%301 = load i64, i64* %18
%302 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.16, i64 0, i64 0), i8* %292, i8* %296, i64 %299, i64 %300, i64 %301)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"-f\00"
@.str.2 = [3 x i8] c"-b\00"
@stderr = global i32 0
@.str.3 = [29 x i8] c"Error: Invalid parameter %s\0A\00"
@.str.4 = [5 x i8] c".zx7\00"
@.str.5 = [110 x i8] c"Usage: %s [-f] [-b] input [output.zx7]\0A -f Force overwrite of output file\0A -b Compress backwards\0A\00"
@.str.6 = [3 x i8] c"rb\00"
@.str.7 = [36 x i8] c"Error: Cannot access input file %s\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.8 = [28 x i8] c"Error: Empty input file %s\0A\00"
@.str.9 = [38 x i8] c"Error: Skipping entire input file %s\0A\00"
@.str.10 = [28 x i8] c"Error: Insufficient memory\0A\00"
@.str.11 = [34 x i8] c"Error: Cannot read input file %s\0A\00"
@.str.12 = [40 x i8] c"Error: Already existing output file %s\0A\00"
@.str.13 = [3 x i8] c"wb\00"
@.str.14 = [37 x i8] c"Error: Cannot create output file %s\0A\00"
@.str.15 = [36 x i8] c"Error: Cannot write output file %s\0A\00"
@.str.16 = [55 x i8] c"File%s converted%s from %lu to %lu bytes! (delta %ld)\0A\00"
@.str.17 = [11 x i8] c" partially\00"
@.str.18 = [1 x i8] zeroinitializer
@.str.19 = [11 x i8] c" backwards\00"
@str = [51 x i8] c"ZX7: Optimal LZ77/LZSS compression by Einar Saukas\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = alloca i64
%5 = bitcast i64* %3 to i8*
%6 = bitcast i64* %4 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
%8 = icmp sgt i32 %0, 1
br i1 %8, label %9, label %43
9: ; preds = %2
%10 = zext i32 %0 to i64
br label %11
11: ; preds = %9, %35
%12 = phi i64 [ 1, %9 ], [ %39, %35 ]
%13 = phi i64 [ 0, %9 ], [ %38, %35 ]
%14 = phi i32 [ 0, %9 ], [ %37, %35 ]
%15 = phi i32 [ 0, %9 ], [ %36, %35 ]
%16 = getelementptr inbounds i8*, i8** %1, i64 %12
%17 = load i8*, i8** %16
%18 = load i8, i8* %17
switch i8 %18, label %41 [
i8 45, label %19
i8 43, label %19
]
19: ; preds = %11, %11
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %17, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %35, label %22
22: ; preds = %19
%23 = tail call i32 @strcmp(i8* dereferenceable(1) %17, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
br i1 %24, label %35, label %25
25: ; preds = %22
%26 = tail call i64 @parse_long(i8* %17)
%27 = icmp slt i64 %26, 1
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = and i64 %12, 4294967295
%30 = getelementptr inbounds i8*, i8** %1, i64 %29
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %30
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %22, %19, %25
%36 = phi i32 [ %15, %25 ], [ %15, %19 ], [ 1, %22 ]
%37 = phi i32 [ %14, %25 ], [ 1, %19 ], [ %14, %22 ]
%38 = phi i64 [ %26, %25 ], [ %13, %19 ], [ %13, %22 ]
%39 = add nuw nsw i64 %12, 1
%40 = icmp eq i64 %39, %10
br i1 %40, label %43, label %11
41: ; preds = %11
%42 = trunc i64 %12 to i32
br label %43
43: ; preds = %35, %41, %2
%44 = phi i32 [ 0, %2 ], [ %15, %41 ], [ %36, %35 ]
%45 = phi i32 [ 0, %2 ], [ %14, %41 ], [ %37, %35 ]
%46 = phi i64 [ 0, %2 ], [ %13, %41 ], [ %38, %35 ]
%47 = phi i32 [ 1, %2 ], [ %42, %41 ], [ %0, %35 ]
%48 = add nuw nsw i32 %47, 1
%49 = icmp eq i32 %48, %0
br i1 %49, label %50, label %61
50: ; preds = %43
%51 = zext i32 %47 to i64
%52 = getelementptr inbounds i8*, i8** %1, i64 %51
%53 = load i8*, i8** %52
%54 = tail call i64 @strlen(i8* dereferenceable(1) %53)
%55 = add i64 %54, 5
%56 = tail call i64 @malloc(i64 %55)
%57 = inttoptr i64 %56 to i8*
%58 = load i8*, i8** %52
%59 = tail call i32 @strcpy(i8* %57, i8* %58)
%60 = tail call i32 @strcat(i8* %57, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %74
61: ; preds = %43
%62 = add nuw nsw i32 %47, 2
%63 = icmp eq i32 %62, %0
br i1 %63, label %64, label %69
64: ; preds = %61
%65 = zext i32 %48 to i64
%66 = getelementptr inbounds i8*, i8** %1, i64 %65
%67 = load i8*, i8** %66
%68 = zext i32 %47 to i64
br label %74
69: ; preds = %61
%70 = load i32, i32* @stderr
%71 = load i8*, i8** %1
%72 = tail call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([110 x i8], [110 x i8]* @.str.5, i64 0, i64 0), i8* %71)
%73 = tail call i32 @exit(i32 1)
unreachable
74: ; preds = %64, %50
%75 = phi i64 [ %68, %64 ], [ %51, %50 ]
%76 = phi i8* [ %67, %64 ], [ %57, %50 ]
%77 = getelementptr inbounds i8*, i8** %1, i64 %75
%78 = load i8*, i8** %77
%79 = tail call i32* @fopen(i8* %78, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%80 = icmp eq i32* %79, null
br i1 %80, label %81, label %86
81: ; preds = %74
%82 = load i32, i32* @stderr
%83 = load i8*, i8** %77
%84 = tail call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* %83)
%85 = tail call i32 @exit(i32 1)
unreachable
86: ; preds = %74
%87 = load i32, i32* @SEEK_END
%88 = tail call i32 @fseek(i32* %79, i64 0, i32 %87)
%89 = tail call i64 @ftell(i32* %79)
%90 = load i32, i32* @SEEK_SET
%91 = tail call i32 @fseek(i32* %79, i64 0, i32 %90)
%92 = icmp eq i64 %89, 0
br i1 %92, label %93, label %98
93: ; preds = %86
%94 = load i32, i32* @stderr
%95 = load i8*, i8** %77
%96 = tail call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %95)
%97 = tail call i32 @exit(i32 1)
unreachable
98: ; preds = %86
%99 = icmp ugt i64 %89, %46
br i1 %99, label %105, label %100
100: ; preds = %98
%101 = load i32, i32* @stderr
%102 = load i8*, i8** %77
%103 = tail call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.9, i64 0, i64 0), i8* %102)
%104 = tail call i32 @exit(i32 1)
unreachable
105: ; preds = %98
%106 = tail call i64 @malloc(i64 %89)
%107 = inttoptr i64 %106 to i8*
%108 = icmp eq i64 %106, 0
br i1 %108, label %109, label %113
109: ; preds = %105
%110 = load i32, i32* @stderr
%111 = tail call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
%112 = tail call i32 @exit(i32 1)
unreachable
113: ; preds = %105, %113
%114 = phi i64 [ %118, %113 ], [ 0, %105 ]
%115 = getelementptr inbounds i8, i8* %107, i64 %114
%116 = sub i64 %89, %114
%117 = tail call i64 @fread(i8* %115, i32 1, i64 %116, i32* %79)
%118 = add i64 %117, %114
%119 = icmp eq i64 %117, 0
br i1 %119, label %120, label %113
120: ; preds = %113
%121 = icmp eq i64 %118, %89
br i1 %121, label %127, label %122
122: ; preds = %120
%123 = load i32, i32* @stderr
%124 = load i8*, i8** %77
%125 = tail call i32 (i32, i8*, ...) @fprintf(i32 %123, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0), i8* %124)
%126 = tail call i32 @exit(i32 1)
unreachable
127: ; preds = %120
%128 = tail call i32 @fclose(i32* %79)
%129 = icmp eq i32 %45, 0
br i1 %129, label %130, label %137
130: ; preds = %127
%131 = tail call i32* @fopen(i8* %76, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%132 = icmp eq i32* %131, null
br i1 %132, label %137, label %133
133: ; preds = %130
%134 = load i32, i32* @stderr
%135 = tail call i32 (i32, i8*, ...) @fprintf(i32 %134, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.12, i64 0, i64 0), i8* %76)
%136 = tail call i32 @exit(i32 1)
unreachable
137: ; preds = %130, %127
%138 = tail call i32* @fopen(i8* %76, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0))
%139 = icmp eq i32* %138, null
br i1 %139, label %140, label %144
140: ; preds = %137
%141 = load i32, i32* @stderr
%142 = tail call i32 (i32, i8*, ...) @fprintf(i32 %141, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.14, i64 0, i64 0), i8* %76)
%143 = tail call i32 @exit(i32 1)
unreachable
144: ; preds = %137
%145 = icmp eq i32 %44, 0
br i1 %145, label %150, label %146
146: ; preds = %144
%147 = getelementptr inbounds i8, i8* %107, i64 %89
%148 = getelementptr inbounds i8, i8* %147, i64 -1
%149 = tail call i32 @reverse(i8* %107, i8* %148)
br label %150
150: ; preds = %146, %144
%151 = tail call i32 @optimize(i8* %107, i64 %89, i64 %46)
%152 = call i8* @compress(i32 %151, i8* %107, i64 %89, i64 %46, i64* %3, i64* %4)
br i1 %145, label %158, label %153
153: ; preds = %150
%154 = load i64, i64* %3
%155 = getelementptr inbounds i8, i8* %152, i64 %154
%156 = getelementptr inbounds i8, i8* %155, i64 -1
%157 = call i32 @reverse(i8* %152, i8* %156)
br label %158
158: ; preds = %153, %150
%159 = load i64, i64* %3
%160 = call i64 @fwrite(i8* %152, i32 1, i64 %159, i32* %138)
%161 = load i64, i64* %3
%162 = icmp eq i64 %160, %161
br i1 %162, label %167, label %163
163: ; preds = %158
%164 = load i32, i32* @stderr
%165 = call i32 (i32, i8*, ...) @fprintf(i32 %164, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.15, i64 0, i64 0), i8* %76)
%166 = call i32 @exit(i32 1)
unreachable
167: ; preds = %158
%168 = call i32 @fclose(i32* %138)
%169 = icmp eq i64 %46, 0
%170 = select i1 %169, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.18, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.17, i64 0, i64 0)
%171 = select i1 %145, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.18, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.19, i64 0, i64 0)
%172 = sub i64 %89, %46
%173 = load i64, i64* %3
%174 = load i64, i64* %4
%175 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.16, i64 0, i64 0), i8* %170, i8* %171, i64 %172, i64 %173, i64 %174)
ret i32 0
}