#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*/ compress(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ decompress(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *in;
  FILE *out;
  if (argc != 4) {
    fprintf(stderr, "Usage: %s input output c/d\n",
            argc > 0 ? argv[0] : "compress");
    return 1;
  }
  in = fopen(argv[1], "rb");
  if (in == NULL) {
    fputs("input file open error\n", stderr);
    return 1;
  }
  out = fopen(argv[2], "wb");
  if (out == NULL) {
    fputs("output file open error\n", stderr);
    fclose(out);
    return 0;
  }
  if (argv[3][0] == 'd') {
    decompress(in, out);
  } else {
    compress(in, out);
  }
  fclose(in);
  fclose(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)
cmpl   $0x4,-0x8(%rbp)
je     11d5 <main+0x75>
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11a6 <main+0x46>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    11b6 <main+0x56>
lea    0xe6f(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11b6 <main+0x56>
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rdx
lea    0xe3c(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b2 <main+0x152>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe41(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1219 <main+0xb9>
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
lea    0xe20(%rip),%rdi
call   1050 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b2 <main+0x152>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe17(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1266 <main+0x106>
mov    0x2d9d(%rip),%rax
mov    (%rax),%esi
lea    0xdf6(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    12b2 <main+0x152>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
movsbl (%rax),%eax
cmp    $0x64,%eax
jne    128c <main+0x12c>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <decompress@plt>
jmp    1299 <main+0x139>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <compress@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    11b3 <main+0x53>
mov    0x8(%rbx),%rdi
lea    0xead(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c7 <main+0x67>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xeaf(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11fd <main+0x9d>
mov    %rax,%r15
mov    0x18(%rbx),%rax
cmpb   $0x64,(%rax)
jne    121d <main+0xbd>
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <decompress@plt>
jmp    1228 <main+0xc8>
mov    %edi,%eax
mov    0x2e24(%rip),%rcx
mov    (%rcx),%edi
test   %eax,%eax
jle    11e3 <main+0x83>
mov    (%rbx),%rdx
jmp    11ea <main+0x8a>
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
lea    0xe51(%rip),%rdi
call   1050 <fputs@plt>
mov    $0x1,%ebx
jmp    123a <main+0xda>
lea    0xe32(%rip),%rdx
lea    0xe0f(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%ebx
jmp    123a <main+0xda>
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
lea    0xe35(%rip),%rdi
call   1050 <fputs@plt>
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <fclose@plt>
jmp    123a <main+0xda>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <compress@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Usage: %s input output c/d\0A\00"
@.str.1 = [9 x i8] c"compress\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [23 x i8] c"input file open error\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [24 x i8] c"output file open error\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 4
br i1 %9, label %10, label %22
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
br label %19
18: ; preds = %10
br label %19
19: ; preds = %18, %14
%20 = phi i8* [ %17, %14 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), %18 ]
%21 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 1, i32* %3
br label %65
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %26, i32** %6
%27 = load i32*, i32** %6
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = load i32, i32* @stderr
%31 = call i32 @fputs(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %30)
store i32 1, i32* %3
br label %65
32: ; preds = %22
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %36, i32** %7
%37 = load i32*, i32** %7
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %44
39: ; preds = %32
%40 = load i32, i32* @stderr
%41 = call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %40)
%42 = load i32*, i32** %7
%43 = call i32 @fclose(i32* %42)
store i32 0, i32* %3
br label %65
44: ; preds = %32
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 3
%47 = load i8*, i8** %46
%48 = getelementptr inbounds i8, i8* %47, i64 0
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 100
br i1 %51, label %52, label %56
52: ; preds = %44
%53 = load i32*, i32** %6
%54 = load i32*, i32** %7
%55 = call i32 @decompress(i32* %53, i32* %54)
br label %60
56: ; preds = %44
%57 = load i32*, i32** %6
%58 = load i32*, i32** %7
%59 = call i32 @compress(i32* %57, i32* %58)
br label %60
60: ; preds = %56, %52
%61 = load i32*, i32** %6
%62 = call i32 @fclose(i32* %61)
%63 = load i32*, i32** %7
%64 = call i32 @fclose(i32* %63)
store i32 0, i32* %3
br label %65
65: ; preds = %60, %39, %29, %19
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Usage: %s input output c/d\0A\00"
@.str.1 = [9 x i8] c"compress\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [23 x i8] c"input file open error\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [24 x i8] c"output file open error\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %12, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = load i8*, i8** %1
br label %9
9: ; preds = %4, %7
%10 = phi i8* [ %8, %7 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), %4 ]
%11 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %41
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = tail call i32 @fputs(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %18)
br label %41
20: ; preds = %12
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = tail call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %26)
%28 = tail call i32 @fclose(i32* null)
br label %41
29: ; preds = %20
%30 = getelementptr inbounds i8*, i8** %1, i64 3
%31 = load i8*, i8** %30
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 100
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = tail call i32 @decompress(i32* %15, i32* %23)
br label %38
36: ; preds = %29
%37 = tail call i32 @compress(i32* %15, i32* %23)
br label %38
38: ; preds = %36, %34
%39 = tail call i32 @fclose(i32* %15)
%40 = tail call i32 @fclose(i32* %23)
br label %41
41: ; preds = %38, %25, %17, %9
%42 = phi i32 [ 1, %9 ], [ 1, %17 ], [ 0, %25 ], [ 0, %38 ]
ret i32 %42
}