#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, 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);
int /*<<< orphan*/ printf(char *, unsigned long, unsigned long, long);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
int main(int argc, char *argv[]) {
  FILE *ifp;
  FILE *ofp;
  unsigned char *input_data;
  unsigned char *output_data;
  size_t input_size;
  size_t output_size;
  size_t partial_counter;
  size_t total_counter;
  char *output_name;
  long delta;
  if (argc == 2) {
    output_name = (char *)malloc(strlen(argv[1]) + 5);
    strcpy(output_name, argv[1]);
    strcat(output_name, ".zx7");
  } else if (argc == 3) {
    output_name = argv[2];
  } else {
    fprintf(stderr, "Usage: %s input [output.zx7]\n", argv[0]);
    exit(1);
  }
  ifp = fopen(argv[1], "rb");
  if (!ifp) {
    fprintf(stderr, "Error: Cannot access input file %s\n", argv[1]);
    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[1]);
    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[1]);
    exit(1);
  }
  fclose(ifp);
  if (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);
  }
  output_data = compress(optimize(input_data, input_size), input_data,
                         input_size, &output_size, &delta);
  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("Optimal LZ77/LZSS compression by Einar Saukas\nFile converted from "
         "%lu to %lu bytes! (delta %ld)\n",
         (unsigned long)input_size, (unsigned long)output_size, delta);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1253 <main+0x63>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <strlen@plt>
mov    %rax,%rdi
add    $0x5,%rdi
call   10c0 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x58(%rbp),%rdi
lea    0xdb7(%rip),%rsi
call   10f0 <strcat@plt>
jmp    129b <main+0xab>
cmpl   $0x3,-0x8(%rbp)
jne    126e <main+0x7e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x58(%rbp)
jmp    1296 <main+0xa6>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd80(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    129b <main+0xab>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd79(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12e7 <main+0xf7>
mov    0x2d13(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd50(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2cf6(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10d0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <ftell@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2cbb(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10d0 <fseek@plt>
cmpq   $0x0,-0x38(%rbp)
jne    1354 <main+0x164>
mov    0x2ca6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd07(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x38(%rbp),%rdi
call   10c0 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    138d <main+0x19d>
mov    0x2c65(%rip),%rax
mov    (%rax),%edi
lea    0xcea(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
movq   $0x0,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
add    -0x50(%rbp),%rdi
mov    -0x38(%rbp),%rdx
sub    -0x50(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
add    -0x50(%rbp),%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x48(%rbp)
ja     1395 <main+0x1a5>
mov    -0x50(%rbp),%rax
cmp    -0x38(%rbp),%rax
je     1405 <main+0x215>
mov    0x2bf5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xc8e(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x58(%rbp),%rdi
lea    0xc0a(%rip),%rsi
call   10e0 <fopen@plt>
cmp    $0x0,%rax
je     144d <main+0x25d>
mov    0x2ba9(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rdx
lea    0xc68(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x58(%rbp),%rdi
lea    0xc74(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1491 <main+0x2a1>
mov    0x2b65(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rdx
lea    0xc4f(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   10b0 <optimize@plt>
mov    %eax,%edi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    -0x60(%rbp),%r8
call   1030 <compress@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1110 <fwrite@plt>
cmp    -0x40(%rbp),%rax
je     14fe <main+0x30e>
mov    0x2af8(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rdx
lea    0xc07(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x60(%rbp),%rcx
lea    0xbfe(%rip),%rdi
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
cmp    $0x3,%edi
je     1241 <main+0x51>
cmp    $0x2,%edi
jne    1447 <main+0x257>
mov    0x8(%r15),%rdi
call   1070 <strlen@plt>
lea    0x5(%rax),%rdi
call   10c0 <malloc@plt>
mov    %rax,%r14
mov    0x8(%r15),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
lea    0xdc9(%rip),%rsi
mov    %r14,%rdi
call   10f0 <strcat@plt>
jmp    1245 <main+0x55>
mov    0x10(%r15),%r14
mov    0x8(%r15),%rdi
lea    0xdd3(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1399 <main+0x1a9>
mov    %rax,%rbx
mov    0x2d80(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    %rbx,%rdi
call   10a0 <ftell@plt>
mov    %rax,%r12
mov    0x2d4a(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10d0 <fseek@plt>
test   %r12,%r12
je     13b2 <main+0x1c2>
mov    %r12,%rdi
call   10c0 <malloc@plt>
test   %rax,%rax
je     13c8 <main+0x1d8>
mov    %rax,%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
add    %rbp,%rdi
mov    %r12,%rdx
sub    %rbp,%rdx
mov    $0x1,%esi
mov    %rbx,%rcx
call   1050 <fread@plt>
add    %rax,%rbp
test   %rax,%rax
jne    12c0 <main+0xd0>
cmp    %r12,%rbp
jne    13e9 <main+0x1f9>
mov    %rbx,%rdi
call   1060 <fclose@plt>
lea    0xd2a(%rip),%rsi
mov    %r14,%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
jne    13ff <main+0x20f>
lea    0xdbb(%rip),%rsi
mov    %r14,%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1411 <main+0x221>
mov    %rax,%rbx
mov    %r13,%rdi
mov    %r12,%rsi
call   10b0 <optimize@plt>
lea    0x8(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    %eax,%edi
mov    %r13,%rsi
mov    %r12,%rdx
call   1030 <compress@plt>
mov    0x8(%rsp),%rdx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbx,%rcx
call   1110 <fwrite@plt>
cmp    0x8(%rsp),%rax
jne    1423 <main+0x233>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    0x8(%rsp),%rdx
mov    0x10(%rsp),%rcx
lea    0xd98(%rip),%rdi
mov    %r12,%rsi
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c38(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rdx
lea    0xc79(%rip),%rsi
jmp    1436 <main+0x246>
mov    0x2c1f(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rdx
lea    0xc84(%rip),%rsi
jmp    1436 <main+0x246>
mov    0x2c09(%rip),%rax
mov    (%rax),%edi
lea    0xc8e(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2be8(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rdx
lea    0xc85(%rip),%rsi
jmp    1436 <main+0x246>
mov    0x2bd2(%rip),%rax
mov    (%rax),%edi
lea    0xc95(%rip),%rsi
jmp    1433 <main+0x243>
mov    0x2bc0(%rip),%rax
mov    (%rax),%edi
lea    0xcae(%rip),%rsi
jmp    1433 <main+0x243>
mov    0x2bae(%rip),%rax
mov    (%rax),%edi
lea    0xcc1(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2b8a(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xbab(%rip),%rsi
jmp    1436 <main+0x246>

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

LLVM IR (-O2):
@.str = [5 x i8] c".zx7\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Usage: %s input [output.zx7]\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [36 x i8] c"Error: Cannot access input file %s\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [28 x i8] c"Error: Empty input file %s\0A\00"
@.str.5 = [28 x i8] c"Error: Insufficient memory\0A\00"
@.str.6 = [34 x i8] c"Error: Cannot read input file %s\0A\00"
@.str.7 = [40 x i8] c"Error: Already existing output file %s\0A\00"
@.str.8 = [3 x i8] c"wb\00"
@.str.9 = [37 x i8] c"Error: Cannot create output file %s\0A\00"
@.str.10 = [36 x i8] c"Error: Cannot write output file %s\0A\00"
@.str.11 = [97 x i8] c"Optimal LZ77/LZSS compression by Einar Saukas\0AFile converted from %lu to %lu bytes! (delta %ld)\0A\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*
switch i32 %0, label %20 [
i32 2, label %7
i32 3, label %17
]
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @strlen(i8* dereferenceable(1) %9)
%11 = add i64 %10, 5
%12 = tail call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to i8*
%14 = load i8*, i8** %8
%15 = tail call i32 @strcpy(i8* %13, i8* %14)
%16 = tail call i32 @strcat(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %25
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
br label %25
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %1
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %17, %7
%26 = phi i8* [ %13, %7 ], [ %19, %17 ]
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = tail call i32* @fopen(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %36
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %27
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %33)
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %25
%37 = load i32, i32* @SEEK_END
%38 = tail call i32 @fseek(i32* %29, i64 0, i32 %37)
%39 = tail call i64 @ftell(i32* %29)
%40 = load i32, i32* @SEEK_SET
%41 = tail call i32 @fseek(i32* %29, i64 0, i32 %40)
%42 = icmp eq i64 %39, 0
br i1 %42, label %43, label %48
43: ; preds = %36
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %27
%46 = tail call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %45)
%47 = tail call i32 @exit(i32 1)
unreachable
48: ; preds = %36
%49 = tail call i64 @malloc(i64 %39)
%50 = inttoptr i64 %49 to i8*
%51 = icmp eq i64 %49, 0
br i1 %51, label %52, label %56
52: ; preds = %48
%53 = load i32, i32* @stderr
%54 = tail call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%55 = tail call i32 @exit(i32 1)
unreachable
56: ; preds = %48, %56
%57 = phi i64 [ %61, %56 ], [ 0, %48 ]
%58 = getelementptr inbounds i8, i8* %50, i64 %57
%59 = sub i64 %39, %57
%60 = tail call i64 @fread(i8* %58, i32 1, i64 %59, i32* %29)
%61 = add i64 %60, %57
%62 = icmp eq i64 %60, 0
br i1 %62, label %63, label %56
63: ; preds = %56
%64 = icmp eq i64 %61, %39
br i1 %64, label %70, label %65
65: ; preds = %63
%66 = load i32, i32* @stderr
%67 = load i8*, i8** %27
%68 = tail call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %67)
%69 = tail call i32 @exit(i32 1)
unreachable
70: ; preds = %63
%71 = tail call i32 @fclose(i32* %29)
%72 = tail call i32* @fopen(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%73 = icmp eq i32* %72, null
br i1 %73, label %78, label %74
74: ; preds = %70
%75 = load i32, i32* @stderr
%76 = tail call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), i8* %26)
%77 = tail call i32 @exit(i32 1)
unreachable
78: ; preds = %70
%79 = tail call i32* @fopen(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%80 = icmp eq i32* %79, null
br i1 %80, label %81, label %85
81: ; preds = %78
%82 = load i32, i32* @stderr
%83 = tail call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0), i8* %26)
%84 = tail call i32 @exit(i32 1)
unreachable
85: ; preds = %78
%86 = tail call i32 @optimize(i8* %50, i64 %39)
%87 = call i8* @compress(i32 %86, i8* %50, i64 %39, i64* %3, i64* %4)
%88 = load i64, i64* %3
%89 = call i64 @fwrite(i8* %87, i32 1, i64 %88, i32* %79)
%90 = load i64, i64* %3
%91 = icmp eq i64 %89, %90
br i1 %91, label %96, label %92
92: ; preds = %85
%93 = load i32, i32* @stderr
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0), i8* %26)
%95 = call i32 @exit(i32 1)
unreachable
96: ; preds = %85
%97 = call i32 @fclose(i32* %79)
%98 = load i64, i64* %3
%99 = load i64, i64* %4
%100 = call i32 @printf(i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str.11, i64 0, i64 0), i64 %39, i64 %98, i64 %99)
ret i32 0
}