#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*/ uint8_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int compress(int /*<<< orphan*/ *, int, int /*<<< orphan*/ *, int);
int decompress(int /*<<< orphan*/ *, int, int /*<<< orphan*/ **);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  if (argc != 4 || (strcmp(argv[1], "-c") != 0 && strcmp(argv[1], "-d") != 0)) {
    printf("Unexpected arguments. Format is:\ncompression-demo -c/-d inputfile "
           "outputfile\n");
    return 1;
  }
  int bufferSize = 640000;
  FILE *inputfp = fopen(argv[2], "r");
  FILE *outputfp = fopen(argv[3], "w");
  uint8_t *input = malloc(bufferSize);
  int inputLength = fread(input, 1, bufferSize, inputfp);
  uint8_t *output = NULL;
  int outputLength;
  printf("Before %d\n", inputLength);
  if (strcmp(argv[1], "-c") == 0) {
    output = malloc(bufferSize);
    outputLength = compress(input, inputLength, output, bufferSize);
  } else {
    outputLength = decompress(input, inputLength, &output);
  }
  fwrite(output, 1, outputLength, outputfp);
  printf("After %d\n", outputLength);
  fclose(inputfp);
  fclose(outputfp);
  free(input);
  free(output);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    11fc <main+0x5c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe31(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1216 <main+0x76>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe16(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1216 <main+0x76>
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1333 <main+0x193>
movl   $0x9c400,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe28(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe12(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    %eax,-0x34(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x34(%rbp),%esi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd67(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12cf <main+0x12f>
mov    -0x14(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x40(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1040 <compress@plt>
mov    %eax,-0x44(%rbp)
jmp    12e2 <main+0x142>
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
lea    -0x40(%rbp),%rdx
call   10c0 <decompress@plt>
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   10b0 <fwrite@plt>
mov    -0x44(%rbp),%esi
lea    0xd62(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x4,%edi
jne    11ee <main+0x3e>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe31(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1204 <main+0x54>
mov    0x8(%rbx),%rdi
lea    0xe1f(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1204 <main+0x54>
lea    0xe2a(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%ebx
jmp    1300 <main+0x150>
mov    0x10(%rbx),%rdi
lea    0xdf7(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r14
mov    0x18(%rbx),%rdi
lea    0xde6(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r15
mov    $0x9c400,%edi
call   10a0 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x9c400,%edx
mov    %r14,%rcx
call   1060 <fread@plt>
mov    %eax,%ebp
movq   $0x0,0x8(%rsp)
lea    0xdac(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x8(%rbx),%rdi
lea    0xd8e(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1294 <main+0xe4>
lea    0x8(%rsp),%rdx
mov    %r12,%rdi
mov    %ebp,%esi
call   10d0 <decompress@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rbx
jmp    12ba <main+0x10a>
mov    $0x9c400,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,0x8(%rsp)
mov    %r12,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
mov    $0x9c400,%ecx
call   1040 <compress@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r15,%rcx
call   10c0 <fwrite@plt>
lea    0xd42(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r14,%rdi
call   1070 <fclose@plt>
mov    %r15,%rdi
call   1070 <fclose@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"-c\00"
@.str.1 = [3 x i8] c"-d\00"
@.str.2 = [78 x i8] c"Unexpected arguments. Format is:\0Acompression-demo -c/-d inputfile outputfile\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [11 x i8] c"Before %d\0A\00"
@.str.6 = [10 x i8] c"After %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 i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 4
br i1 %14, label %27, label %15
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %15
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %21, %2
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %78
29: ; preds = %21, %15
store i32 640000, i32* %6
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %33, i32** %7
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 3
%36 = load i8*, i8** %35
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %37, i32** %8
%38 = load i32, i32* %6
%39 = call i32* @malloc(i32 %38)
store i32* %39, i32** %9
%40 = load i32*, i32** %9
%41 = load i32, i32* %6
%42 = load i32*, i32** %7
%43 = call i32 @fread(i32* %40, i32 1, i32 %41, i32* %42)
store i32 %43, i32* %10
store i32* null, i32** %11
%44 = load i32, i32* %10
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %44)
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = call i64 @strcmp(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %59
51: ; preds = %29
%52 = load i32, i32* %6
%53 = call i32* @malloc(i32 %52)
store i32* %53, i32** %11
%54 = load i32*, i32** %9
%55 = load i32, i32* %10
%56 = load i32*, i32** %11
%57 = load i32, i32* %6
%58 = call i32 @compress(i32* %54, i32 %55, i32* %56, i32 %57)
store i32 %58, i32* %12
br label %63
59: ; preds = %29
%60 = load i32*, i32** %9
%61 = load i32, i32* %10
%62 = call i32 @decompress(i32* %60, i32 %61, i32** %11)
store i32 %62, i32* %12
br label %63
63: ; preds = %59, %51
%64 = load i32*, i32** %11
%65 = load i32, i32* %12
%66 = load i32*, i32** %8
%67 = call i32 @fwrite(i32* %64, i32 1, i32 %65, i32* %66)
%68 = load i32, i32* %12
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %68)
%70 = load i32*, i32** %7
%71 = call i32 @fclose(i32* %70)
%72 = load i32*, i32** %8
%73 = call i32 @fclose(i32* %72)
%74 = load i32*, i32** %9
%75 = call i32 @free(i32* %74)
%76 = load i32*, i32** %11
%77 = call i32 @free(i32* %76)
store i32 0, i32* %3
br label %78
78: ; preds = %63, %27
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@.str = [3 x i8] c"-c\00"
@.str.1 = [3 x i8] c"-d\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [11 x i8] c"Before %d\0A\00"
@.str.6 = [10 x i8] c"After %d\0A\00"
@str = [77 x i8] c"Unexpected arguments. Format is:\0Acompression-demo -c/-d inputfile outputfile\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32*
%4 = icmp eq i32 %0, 4
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %5
%11 = load i8*, i8** %6
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %10, %2
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @str, i64 0, i64 0))
br label %46
16: ; preds = %10, %5
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%20 = getelementptr inbounds i8*, i8** %1, i64 3
%21 = load i8*, i8** %20
%22 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%23 = tail call i32* @malloc(i32 640000)
%24 = tail call i32 @fread(i32* %23, i32 1, i32 640000, i32* %19)
%25 = bitcast i32** %3 to i8*
store i32* null, i32** %3
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %24)
%27 = load i8*, i8** %6
%28 = tail call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %16
%31 = tail call i32* @malloc(i32 640000)
store i32* %31, i32** %3
%32 = tail call i32 @compress(i32* %23, i32 %24, i32* %31, i32 640000)
br label %36
33: ; preds = %16
%34 = call i32 @decompress(i32* %23, i32 %24, i32** %3)
%35 = load i32*, i32** %3
br label %36
36: ; preds = %33, %30
%37 = phi i32* [ %31, %30 ], [ %35, %33 ]
%38 = phi i32 [ %32, %30 ], [ %34, %33 ]
%39 = call i32 @fwrite(i32* %37, i32 1, i32 %38, i32* %22)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %38)
%41 = call i32 @fclose(i32* %19)
%42 = call i32 @fclose(i32* %22)
%43 = call i32 @free(i32* %23)
%44 = load i32*, i32** %3
%45 = call i32 @free(i32* %44)
br label %46
46: ; preds = %36, %14
%47 = phi i32 [ 1, %14 ], [ 0, %36 ]
ret i32 %47
}