#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;
char *compress(char *, long);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
char *malloc(long);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  char *buffer = 0;
  long length;
  FILE *f_in = fopen("input", "rb");
  FILE *f_out = fopen("output", "wb");
  if (f_in) {
    fseek(f_in, 0, SEEK_END);
    length = ftell(f_in);
    fseek(f_in, 0, SEEK_SET);
    buffer = malloc(length);
    if (buffer) {
      fread(buffer, 1, length, f_in);
    }
    fclose(f_in);
  } else {
    printf("File reading failed\n");
  }
  if (buffer && f_out) {
    buffer = compress(buffer, length);
    while (*buffer != 'e') {
      fwrite(buffer, 1, 1, f_out);
      buffer = buffer + 1;
    }
    fclose(f_out);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe4b(%rip),%rdi
lea    0xe4a(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
lea    0xe3d(%rip),%rdi
lea    0xe3d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1258 <main+0xc8>
mov    -0x28(%rbp),%rdi
mov    0x2df6(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2dc5(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     124a <main+0xba>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1264 <main+0xd4>
lea    0xdb4(%rip),%rdi
call   1060 <printf@plt>
cmpq   $0x0,-0x18(%rbp)
je     12c9 <main+0x139>
cmpq   $0x0,-0x30(%rbp)
je     12c9 <main+0x139>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <compress@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x65,%eax
je     12c0 <main+0x130>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   10b0 <fwrite@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    128b <main+0xfb>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe61(%rip),%rdi
lea    0xe60(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
lea    0xe54(%rip),%rdi
lea    0xe54(%rip),%rsi
call   10b0 <fopen@plt>
test   %rbx,%rbx
je     1270 <main+0xe0>
mov    %rax,%r14
mov    0x2e14(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
call   1080 <ftell@plt>
mov    %rax,%r15
mov    0x2de6(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r15,%rdi
call   1090 <malloc@plt>
mov    %rax,%r12
test   %rax,%rax
je     1221 <main+0x91>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1050 <fread@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
test   %r14,%r14
je     127c <main+0xec>
test   %r12,%r12
je     127c <main+0xec>
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <compress@plt>
mov    %rax,%rbx
mov    (%rax),%al
cmp    $0x65,%al
je     1266 <main+0xd6>
add    $0x1,%rbx
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %r14,%rsi
call   1070 <fputc@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
cmp    $0x65,%al
jne    1250 <main+0xc0>
mov    %r14,%rdi
call   1060 <fclose@plt>
jmp    127c <main+0xec>
lea    0xd9c(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"input\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [7 x i8] c"output\00"
@.str.3 = [3 x i8] c"wb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [21 x i8] c"File reading failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
%10 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %8
%11 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %11, i32** %9
%12 = load i32*, i32** %8
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %35
14: ; preds = %2
%15 = load i32*, i32** %8
%16 = load i32, i32* @SEEK_END
%17 = call i32 @fseek(i32* %15, i32 0, i32 %16)
%18 = load i32*, i32** %8
%19 = call i64 @ftell(i32* %18)
store i64 %19, i64* %7
%20 = load i32*, i32** %8
%21 = load i32, i32* @SEEK_SET
%22 = call i32 @fseek(i32* %20, i32 0, i32 %21)
%23 = load i64, i64* %7
%24 = call i8* @malloc(i64 %23)
store i8* %24, i8** %6
%25 = load i8*, i8** %6
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %32
27: ; preds = %14
%28 = load i8*, i8** %6
%29 = load i64, i64* %7
%30 = load i32*, i32** %8
%31 = call i32 @fread(i8* %28, i32 1, i64 %29, i32* %30)
br label %32
32: ; preds = %27, %14
%33 = load i32*, i32** %8
%34 = call i32 @fclose(i32* %33)
br label %37
35: ; preds = %2
%36 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %37
37: ; preds = %35, %32
%38 = load i8*, i8** %6
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %61
40: ; preds = %37
%41 = load i32*, i32** %9
%42 = icmp ne i32* %41, null
br i1 %42, label %43, label %61
43: ; preds = %40
%44 = load i8*, i8** %6
%45 = load i64, i64* %7
%46 = call i8* @compress(i8* %44, i64 %45)
store i8* %46, i8** %6
br label %47
47: ; preds = %52, %43
%48 = load i8*, i8** %6
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 101
br i1 %51, label %52, label %58
52: ; preds = %47
%53 = load i8*, i8** %6
%54 = load i32*, i32** %9
%55 = call i32 @fwrite(i8* %53, i32 1, i32 1, i32* %54)
%56 = load i8*, i8** %6
%57 = getelementptr inbounds i8, i8* %56, i64 1
store i8* %57, i8** %6
br label %47
58: ; preds = %47
%59 = load i32*, i32** %9
%60 = call i32 @fclose(i32* %59)
br label %61
61: ; preds = %58, %40, %37
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"input\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [7 x i8] c"output\00"
@.str.3 = [3 x i8] c"wb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@str = [20 x i8] c"File reading failed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%5 = icmp eq i32* %3, null
br i1 %5, label %16, label %6
6: ; preds = %2
%7 = load i32, i32* @SEEK_END
%8 = tail call i32 @fseek(i32* %3, i32 0, i32 %7)
%9 = tail call i64 @ftell(i32* %3)
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @fseek(i32* %3, i32 0, i32 %10)
%12 = tail call i8* @malloc(i64 %9)
%13 = icmp eq i8* %12, null
br i1 %13, label %18, label %14
14: ; preds = %6
%15 = tail call i32 @fread(i8* %12, i32 1, i64 %9, i32* %3)
br label %18
16: ; preds = %2
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %37
18: ; preds = %6, %14
%19 = tail call i32 @fclose(i32* %3)
%20 = icmp ne i8* %12, null
%21 = icmp ne i32* %4, null
%22 = and i1 %21, %20
br i1 %22, label %23, label %37
23: ; preds = %18
%24 = tail call i8* @compress(i8* %12, i64 %9)
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 101
br i1 %26, label %35, label %27
27: ; preds = %23, %27
%28 = phi i8 [ %33, %27 ], [ %25, %23 ]
%29 = phi i8* [ %32, %27 ], [ %24, %23 ]
%30 = sext i8 %28 to i32
%31 = tail call i32 @fputc(i32 %30, i32* %4)
%32 = getelementptr inbounds i8, i8* %29, i64 1
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 101
br i1 %34, label %35, label %27
35: ; preds = %27, %23
%36 = tail call i32 @fclose(i32* %4)
br label %37
37: ; preds = %16, %35, %18
ret i32 0
}