#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 */

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freopen(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int unpack(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  int rc;
  if ((argc > 3) || ((argc > 1) && (argv[1][0] == '-')))
    usage();
  if (argc <= 1)
    fprintf(stderr, "stdin");
  else {
    freopen(argv[1], "rb", stdin);
    fprintf(stderr, "%s", argv[1]);
  }
  if (argc <= 2)
    fprintf(stderr, " to stdout\n");
  else {
    freopen(argv[2], "wb", stdout);
    fprintf(stderr, " to %s\n", argv[2]);
  }
  rc = unpack(stdout, stdin);
  if (rc == -1) {
    fprintf(stderr, "could not successfully open input data\n");
    return 1;
  } else if (rc == -2) {
    fprintf(stderr, "OOM!\n");
    return 2;
  }
  return rc;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jg     117e <main+0x3e>
cmpl   $0x1,-0x8(%rbp)
jle    1185 <main+0x45>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1185 <main+0x45>
mov    $0x0,%al
call   1060 <usage@plt>
cmpl   $0x1,-0x8(%rbp)
jg     11ab <main+0x6b>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11e7 <main+0xa7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
lea    0xe43(%rip),%rsi
call   1030 <freopen@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpl   $0x2,-0x8(%rbp)
jg     120d <main+0xcd>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1249 <main+0x109>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2db4(%rip),%rax
mov    (%rax),%edx
lea    0xdf3(%rip),%rsi
call   1030 <freopen@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
mov    0x2d8f(%rip),%rax
mov    (%rax),%esi
call   1040 <unpack@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1290 <main+0x150>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
lea    0xda6(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c8 <main+0x188>
cmpl   $0xfffffffe,-0x14(%rbp)
jne    12bd <main+0x17d>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
lea    0xda1(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    12c8 <main+0x188>
jmp    12c2 <main+0x182>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0x3,%edi
jg     115c <main+0x1c>
cmp    $0x2,%ebp
jl     11cd <main+0x8d>
mov    0x8(%rbx),%rdi
cmpb   $0x2d,(%rdi)
jne    1167 <main+0x27>
xor    %eax,%eax
call   1060 <usage@plt>
mov    0x8(%rbx),%rdi
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
lea    0xe8f(%rip),%rsi
call   1030 <freopen@plt>
mov    0x2e55(%rip),%r14
mov    (%r14),%edi
mov    0x8(%rbx),%rdx
lea    0xe78(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
cmp    $0x2,%ebp
jbe    11e4 <main+0xa4>
mov    0x10(%rbx),%rdi
mov    0x2e28(%rip),%rax
mov    (%rax),%edx
lea    0xe67(%rip),%rsi
call   1030 <freopen@plt>
mov    (%r14),%edi
mov    0x10(%rbx),%rdx
lea    0xe57(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11fb <main+0xbb>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
call   1040 <unpack@plt>
cmp    $0xffffffff,%eax
je     122c <main+0xec>
mov    %eax,%ebx
cmp    $0xfffffffe,%eax
jne    1248 <main+0x108>
mov    $0x2,%ebx
lea    0xe21(%rip),%rsi
jmp    1238 <main+0xf8>
mov    $0x1,%ebx
lea    0xdeb(%rip),%rsi
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [6 x i8] c"stdin\00"
@.str.1 = [3 x i8] c"rb\00"
@stdin = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [12 x i8] c" to stdout\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@stdout = global i32 0
@.str.5 = [8 x i8] c" to %s\0A\00"
@.str.6 = [40 x i8] c"could not successfully open input data\0A\00"
@.str.7 = [6 x i8] c"OOM!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp sgt i32 %7, 3
br i1 %8, label %20, label %9
9: ; preds = %2
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %22
12: ; preds = %9
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 45
br i1 %19, label %20, label %22
20: ; preds = %12, %2
%21 = call i32 (...) @usage()
br label %22
22: ; preds = %20, %12, %9
%23 = load i32, i32* %4
%24 = icmp sle i32 %23, 1
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %39
28: ; preds = %22
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = load i32, i32* @stdin
%33 = call i32 @freopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = load i32, i32* @stderr
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %28, %25
%40 = load i32, i32* %4
%41 = icmp sle i32 %40, 2
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %56
45: ; preds = %39
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 2
%48 = load i8*, i8** %47
%49 = load i32, i32* @stdout
%50 = call i32 @freopen(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %49)
%51 = load i32, i32* @stderr
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 2
%54 = load i8*, i8** %53
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %45, %42
%57 = load i32, i32* @stdout
%58 = load i32, i32* @stdin
%59 = call i32 @unpack(i32 %57, i32 %58)
store i32 %59, i32* %6
%60 = load i32, i32* %6
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %65
62: ; preds = %56
%63 = load i32, i32* @stderr
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %74
65: ; preds = %56
%66 = load i32, i32* %6
%67 = icmp eq i32 %66, -2
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = load i32, i32* @stderr
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
store i32 2, i32* %3
br label %74
71: ; preds = %65
br label %72
72: ; preds = %71
%73 = load i32, i32* %6
store i32 %73, i32* %3
br label %74
74: ; preds = %72, %68, %62
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [6 x i8] c"stdin\00"
@.str.1 = [3 x i8] c"rb\00"
@stdin = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [12 x i8] c" to stdout\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@stdout = global i32 0
@.str.5 = [8 x i8] c" to %s\0A\00"
@.str.6 = [40 x i8] c"could not successfully open input data\0A\00"
@.str.7 = [6 x i8] c"OOM!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 3
br i1 %3, label %11, label %4
4: ; preds = %2
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %15
6: ; preds = %4
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 45
br i1 %10, label %11, label %18
11: ; preds = %6, %2
%12 = tail call i32 (...) @usage()
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
br label %18
15: ; preds = %4
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %27
18: ; preds = %6, %11
%19 = phi i8* [ %8, %6 ], [ %14, %11 ]
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i32, i32* @stdin
%22 = tail call i32 @freopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %20
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = icmp ult i32 %0, 3
br i1 %26, label %27, label %30
27: ; preds = %15, %18
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %38
30: ; preds = %18
%31 = getelementptr inbounds i8*, i8** %1, i64 2
%32 = load i8*, i8** %31
%33 = load i32, i32* @stdout
%34 = tail call i32 @freopen(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %33)
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %31
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %30, %27
%39 = load i32, i32* @stdout
%40 = load i32, i32* @stdin
%41 = tail call i32 @unpack(i32 %39, i32 %40)
switch i32 %41, label %48 [
i32 -1, label %43
i32 -2, label %42
]
42: ; preds = %38
br label %43
43: ; preds = %38, %42
%44 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), %42 ], [ getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), %38 ]
%45 = phi i32 [ 2, %42 ], [ 1, %38 ]
%46 = load i32, i32* @stderr
%47 = tail call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* %44)
br label %48
48: ; preds = %43, %38
%49 = phi i32 [ %41, %38 ], [ %45, %43 ]
ret i32 %49
}