#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 decode();
int encode();
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ *freopen(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ usage();
int /*<<< orphan*/ warnx(char *);
int main(int argc, char *argv[]) {
  if (argc - 1 < 1) {
    warnx("not enough arguments");
    usage();
    return 1;
  }
  if (strcmp(argv[1], "-h") == 0) {
    usage();
    return 0;
  }
  if (argc - 1 > 1) {
    if (freopen(argv[2], "r", stdin) == NULL) {
      err(1, "freopen");
    }
  }
  if (argc - 1 > 2) {
    if (freopen(argv[3], "w", stdout) == NULL) {
      err(1, "freopen");
    }
  }
  if (strcmp(argv[1], "e") == 0) {
    if (encode() == -1) {
      err(1, "encode");
    }
    return 0;
  } else if (strcmp(argv[1], "d") == 0) {
    if (decode() == -1) {
      err(1, "decode");
    }
    return 0;
  }
  usage();
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cmp    $0x1,%eax
jge    11b4 <main+0x44>
lea    0xe64(%rip),%rdi
call   1040 <warnx@plt>
mov    $0x0,%al
call   1080 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1326 <main+0x1b6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe52(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11e5 <main+0x75>
mov    $0x0,%al
call   1080 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    1326 <main+0x1b6>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cmp    $0x1,%eax
jle    1231 <main+0xc1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2de5(%rip),%rax
mov    (%rax),%edx
lea    0xe0c(%rip),%rsi
call   1050 <freopen@plt>
cmp    $0x0,%rax
jne    122c <main+0xbc>
mov    $0x1,%edi
lea    0xdf3(%rip),%rsi
call   1070 <err@plt>
jmp    1231 <main+0xc1>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cmp    $0x2,%eax
jle    127d <main+0x10d>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    0x2d89(%rip),%rax
mov    (%rax),%edx
lea    0xdca(%rip),%rsi
call   1050 <freopen@plt>
cmp    $0x0,%rax
jne    1278 <main+0x108>
mov    $0x1,%edi
lea    0xda7(%rip),%rsi
call   1070 <err@plt>
jmp    127d <main+0x10d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xda6(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12c8 <main+0x158>
mov    $0x0,%al
call   1030 <encode@plt>
cmp    $0xffffffff,%eax
jne    12bc <main+0x14c>
mov    $0x1,%edi
lea    0xd6d(%rip),%rsi
call   1070 <err@plt>
movl   $0x0,-0x4(%rbp)
jmp    1326 <main+0x1b6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd54(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1313 <main+0x1a3>
mov    $0x0,%al
call   1090 <decode@plt>
cmp    $0xffffffff,%eax
jne    1307 <main+0x197>
mov    $0x1,%edi
lea    0xd2b(%rip),%rsi
call   1070 <err@plt>
movl   $0x0,-0x4(%rbp)
jmp    1326 <main+0x1b6>
jmp    1318 <main+0x1a8>
mov    $0x0,%al
call   1080 <usage@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     1195 <main+0x25>
lea    0xe81(%rip),%rdi
call   1040 <warnx@plt>
xor    %eax,%eax
call   1080 <usage@plt>
mov    $0x1,%ebx
jmp    128a <main+0x11a>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
lea    0xe70(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1260 <main+0xf0>
cmp    $0x3,%ebp
jb     121b <main+0xab>
mov    0x10(%rbx),%rdi
mov    0x2e25(%rip),%rax
mov    (%rax),%edx
lea    0xe4c(%rip),%rsi
call   1050 <freopen@plt>
test   %rax,%rax
jne    11e7 <main+0x77>
lea    0xe3d(%rip),%rsi
mov    $0x1,%edi
call   1070 <err@plt>
cmp    $0x4,%ebp
jb     121b <main+0xab>
mov    0x18(%rbx),%rdi
mov    0x2de1(%rip),%rax
mov    (%rax),%edx
lea    0xe22(%rip),%rsi
call   1050 <freopen@plt>
test   %rax,%rax
jne    121b <main+0xab>
lea    0xe09(%rip),%rsi
mov    $0x1,%edi
call   1070 <err@plt>
mov    0x8(%rbx),%rdi
lea    0xe0c(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     126b <main+0xfb>
mov    0x8(%rbx),%rdi
lea    0xdf0(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1184 <main+0x14>
xor    %ebx,%ebx
xor    %eax,%eax
call   1090 <decode@plt>
cmp    $0xffffffff,%eax
jne    128a <main+0x11a>
lea    0xdcf(%rip),%rsi
jmp    1280 <main+0x110>
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <usage@plt>
jmp    128a <main+0x11a>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <encode@plt>
cmp    $0xffffffff,%eax
jne    128a <main+0x11a>
lea    0xda4(%rip),%rsi
mov    $0x1,%edi
call   1070 <err@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"not enough arguments\00"
@.str.1 = [3 x i8] c"-h\00"
@.str.2 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.3 = [8 x i8] c"freopen\00"
@.str.4 = [2 x i8] c"w\00"
@stdout = global i32 0
@.str.5 = [2 x i8] c"e\00"
@.str.6 = [7 x i8] c"encode\00"
@.str.7 = [2 x i8] c"d\00"
@.str.8 = [7 x i8] c"decode\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = sub nsw i32 %6, 1
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = call i32 @warnx(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (...) @usage()
store i32 1, i32* %3
br label %75
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 (...) @usage()
store i32 0, i32* %3
br label %75
20: ; preds = %12
%21 = load i32, i32* %4
%22 = sub nsw i32 %21, 1
%23 = icmp sgt i32 %22, 1
br i1 %23, label %24, label %34
24: ; preds = %20
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = load i32, i32* @stdin
%29 = call i32* @freopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %33
31: ; preds = %24
%32 = call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %31, %24
br label %34
34: ; preds = %33, %20
%35 = load i32, i32* %4
%36 = sub nsw i32 %35, 1
%37 = icmp sgt i32 %36, 2
br i1 %37, label %38, label %48
38: ; preds = %34
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 3
%41 = load i8*, i8** %40
%42 = load i32, i32* @stdout
%43 = call i32* @freopen(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 %42)
%44 = icmp eq i32* %43, null
br i1 %44, label %45, label %47
45: ; preds = %38
%46 = call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %45, %38
br label %48
48: ; preds = %47, %34
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = call i64 @strcmp(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %60
54: ; preds = %48
%55 = call i32 (...) @encode()
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %59
57: ; preds = %54
%58 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %59
59: ; preds = %57, %54
store i32 0, i32* %3
br label %75
60: ; preds = %48
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 1
%63 = load i8*, i8** %62
%64 = call i64 @strcmp(i8* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %72
66: ; preds = %60
%67 = call i32 (...) @decode()
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %71
69: ; preds = %66
%70 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %71
71: ; preds = %69, %66
store i32 0, i32* %3
br label %75
72: ; preds = %60
br label %73
73: ; preds = %72
%74 = call i32 (...) @usage()
store i32 1, i32* %3
br label %75
75: ; preds = %73, %71, %59, %18, %9
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@.str = [21 x i8] c"not enough arguments\00"
@.str.1 = [3 x i8] c"-h\00"
@.str.2 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.3 = [8 x i8] c"freopen\00"
@.str.4 = [2 x i8] c"w\00"
@stdout = global i32 0
@.str.5 = [2 x i8] c"e\00"
@.str.6 = [7 x i8] c"encode\00"
@.str.7 = [2 x i8] c"d\00"
@.str.8 = [7 x i8] c"decode\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @warnx(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 (...) @usage()
br label %54
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 (...) @usage()
br label %54
14: ; preds = %7
%15 = icmp ugt i32 %0, 2
br i1 %15, label %16, label %34
16: ; preds = %14
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = load i32, i32* @stdin
%20 = tail call i32* @freopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %16, %22
%25 = icmp ugt i32 %0, 3
br i1 %25, label %26, label %34
26: ; preds = %24
%27 = getelementptr inbounds i8*, i8** %1, i64 3
%28 = load i8*, i8** %27
%29 = load i32, i32* @stdout
%30 = tail call i32* @freopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 %29)
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %14, %26, %32, %24
%35 = load i8*, i8** %8
%36 = tail call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = tail call i32 (...) @encode()
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %54
41: ; preds = %38
%42 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %54
43: ; preds = %34
%44 = load i8*, i8** %8
%45 = tail call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %43
%48 = tail call i32 (...) @decode()
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %54
50: ; preds = %47
%51 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %54
52: ; preds = %43
%53 = tail call i32 (...) @usage()
br label %54
54: ; preds = %47, %50, %38, %41, %52, %12, %4
%55 = phi i32 [ 1, %4 ], [ 0, %12 ], [ 1, %52 ], [ 0, %41 ], [ 0, %38 ], [ 0, %50 ], [ 0, %47 ]
ret i32 %55
}