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

/* Variables and functions */
int CLOCKS_PER_SEC;
int clock();
int /*<<< orphan*/ decode(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ encode(char, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
char scan(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  time_t start, end;
  start = clock();
  if (argc != 4) {
    printf("usage: prepack_light.exe e/d in out\n");
    return 1;
  } else {
    FILE *in, *out;
    if ((in = fopen(argv[2], "rb")) == NULL) {
      printf("no input!\n");
      return 2;
    }
    if ((out = fopen(argv[3], "wb")) == NULL) {
      printf("no output!\n");
      return 3;
    }
    if (argv[1][0] == 'e') {
      char method = scan(in);
      encode(method, in, out);
    } else if (argv[1][0] == 'd') {
      decode(in, out);
    } else {
      printf("unknown argument!\n");
      return 4;
    }
    fclose(in);
    fclose(out);
  }
  end = clock();
  printf("took %li seconds\n", (end - start) / CLOCKS_PER_SEC);
  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)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11b4 <main+0x44>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ec <main+0x17c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe62(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11f0 <main+0x80>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    12ec <main+0x17c>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe34(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    122c <main+0xbc>
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x3,-0x4(%rbp)
jmp    12ec <main+0x17c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x65,%eax
jne    1264 <main+0xf4>
mov    -0x20(%rbp),%rdi
call   1080 <scan@plt>
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
movsbl %al,%edi
call   1030 <encode@plt>
jmp    12a9 <main+0x139>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x64,%eax
jne    128a <main+0x11a>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <decode@plt>
jmp    12a4 <main+0x134>
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x4,-0x4(%rbp)
jmp    12ec <main+0x17c>
jmp    12a9 <main+0x139>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    0x2d16(%rip),%rcx
cltd
idivl  (%rcx)
mov    %eax,%esi
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %edi,%ebx
xor    %eax,%eax
call   1050 <clock@plt>
cmp    $0x4,%ebx
jne    11f5 <main+0x75>
mov    %eax,%r14d
mov    0x10(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1208 <main+0x88>
mov    %rax,%rbx
mov    0x18(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     121b <main+0x9b>
mov    %rax,%r15
mov    0x8(%rbp),%rax
mov    (%rax),%al
cmp    $0x64,%al
je     122e <main+0xae>
cmp    $0x65,%al
jne    1271 <main+0xf1>
mov    %rbx,%rdi
call   1090 <scan@plt>
movsbl %al,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <encode@plt>
jmp    1239 <main+0xb9>
lea    0xe43(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
jmp    1282 <main+0x102>
lea    0xe26(%rip),%rdi
call   1040 <puts@plt>
mov    $0x2,%ebx
jmp    1282 <main+0x102>
lea    0xe08(%rip),%rdi
call   1040 <puts@plt>
mov    $0x3,%ebx
jmp    1282 <main+0x102>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <decode@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <clock@plt>
sub    %r14d,%eax
mov    0x2d8c(%rip),%rcx
cltd
idivl  (%rcx)
lea    0xda0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1282 <main+0x102>
lea    0xda0(%rip),%rdi
call   1040 <puts@plt>
mov    $0x4,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"usage: prepack_light.exe e/d in out\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [11 x i8] c"no input!\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [12 x i8] c"no output!\0A\00"
@.str.5 = [19 x i8] c"unknown argument!\0A\00"
@.str.6 = [18 x i8] c"took %li seconds\0A\00"
@CLOCKS_PER_SEC = global i32 0
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 i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 (...) @clock()
store i32 %11, i32* %6
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 4
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %75
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %8
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %75
24: ; preds = %16
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 3
%27 = load i8*, i8** %26
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %28, i32** %9
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
store i32 3, i32* %3
br label %75
32: ; preds = %24
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = getelementptr inbounds i8, i8* %35, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 101
br i1 %39, label %40, label %47
40: ; preds = %32
%41 = load i32*, i32** %8
%42 = call signext i8 @scan(i32* %41)
store i8 %42, i8* %10
%43 = load i8, i8* %10
%44 = load i32*, i32** %8
%45 = load i32*, i32** %9
%46 = call i32 @encode(i8 signext %43, i32* %44, i32* %45)
br label %62
47: ; preds = %32
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = getelementptr inbounds i8, i8* %50, i64 0
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 100
br i1 %54, label %55, label %59
55: ; preds = %47
%56 = load i32*, i32** %8
%57 = load i32*, i32** %9
%58 = call i32 @decode(i32* %56, i32* %57)
br label %61
59: ; preds = %47
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
store i32 4, i32* %3
br label %75
61: ; preds = %55
br label %62
62: ; preds = %61, %40
%63 = load i32*, i32** %8
%64 = call i32 @fclose(i32* %63)
%65 = load i32*, i32** %9
%66 = call i32 @fclose(i32* %65)
br label %67
67: ; preds = %62
%68 = call i32 (...) @clock()
store i32 %68, i32* %7
%69 = load i32, i32* %7
%70 = load i32, i32* %6
%71 = sub nsw i32 %69, %70
%72 = load i32, i32* @CLOCKS_PER_SEC
%73 = sdiv i32 %71, %72
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %73)
store i32 0, i32* %3
br label %75
75: ; preds = %67, %59, %30, %22, %14
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.6 = [18 x i8] c"took %li seconds\0A\00"
@CLOCKS_PER_SEC = global i32 0
@str = [18 x i8] c"unknown argument!\00"
@str.7 = [11 x i8] c"no output!\00"
@str.8 = [10 x i8] c"no input!\00"
@str.9 = [36 x i8] c"usage: prepack_light.exe e/d in out\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @clock()
%4 = icmp eq i32 %0, 4
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.9, i64 0, i64 0))
br label %40
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.8, i64 0, i64 0))
br label %40
14: ; preds = %7
%15 = getelementptr inbounds i8*, i8** %1, i64 3
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.7, i64 0, i64 0))
br label %40
21: ; preds = %14
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = load i8, i8* %23
switch i8 %24, label %30 [
i8 101, label %25
i8 100, label %28
]
25: ; preds = %21
%26 = tail call signext i8 @scan(i32* %10)
%27 = tail call i32 @encode(i8 signext %26, i32* %10, i32* %17)
br label %32
28: ; preds = %21
%29 = tail call i32 @decode(i32* %10, i32* %17)
br label %32
30: ; preds = %21
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %40
32: ; preds = %28, %25
%33 = tail call i32 @fclose(i32* %10)
%34 = tail call i32 @fclose(i32* %17)
%35 = tail call i32 (...) @clock()
%36 = sub nsw i32 %35, %3
%37 = load i32, i32* @CLOCKS_PER_SEC
%38 = sdiv i32 %36, %37
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %12, %19, %30, %32, %5
%41 = phi i32 [ 1, %5 ], [ 0, %32 ], [ 2, %12 ], [ 3, %19 ], [ 4, %30 ]
ret i32 %41
}