#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 */
struct option {
  char *member_0;
  char member_3;
  int /*<<< orphan*/ member_2;
  int /*<<< orphan*/ member_1;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ base64_dec(int /*<<< orphan*/ *);
int /*<<< orphan*/ base64_enc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getopt_long(int, char **, char *, struct option *, int *);
int optind;
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ *stdin;
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  char *file;
  FILE *fp;
  int decode = 0;
  for (;;) {
    int c;
    int opt_index = 0;
    static struct option opt_long[] = {{"decode", 0, 0, 'd'}, {0, 0, 0, 0}};
    if ((c = getopt_long(argc, argv, "d", opt_long, &opt_index)) == -1) {
      break;
    }
    switch (c) {
    case 'd':
      decode = 1;
      break;
    }
  }
  if (optind >= argc) {
    fp = stdin;
  } else if (optind + 1 == argc) {
    file = argv[optind];
    if (strcmp(file, "-") == 0) {
      fp = stdin;
    } else if ((fp = fopen(file, "rb")) == NULL) {
      printf("cannot open %s\n", file);
      return 1;
    }
  } else {
    printf("Usage: %s <file>\n", argv[0]);
    return 1;
  }
  int success = (decode) ? !base64_dec(fp) : !base64_enc(fp);
  return success;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe75(%rip),%rdx
lea    0x2ec7(%rip),%rcx
lea    -0x2c(%rbp),%r8
call   1040 <getopt_long@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
jne    11b3 <main+0x53>
jmp    11d0 <main+0x70>
mov    -0x28(%rbp),%eax
sub    $0x64,%eax
jne    11cb <main+0x6b>
jmp    11c4 <main+0x64>
movl   $0x1,-0x24(%rbp)
jmp    117d <main+0x1d>
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     11f5 <main+0x95>
mov    0x2dff(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    12b5 <main+0x155>
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
cmp    -0x8(%rbp),%eax
jne    1291 <main+0x131>
mov    -0x10(%rbp),%rax
mov    0x2dcb(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdde(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    124d <main+0xed>
mov    0x2da7(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    128c <main+0x12c>
mov    -0x18(%rbp),%rdi
lea    0xdb3(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1287 <main+0x127>
mov    -0x18(%rbp),%rsi
lea    0xd98(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1302 <main+0x1a2>
jmp    128c <main+0x12c>
jmp    12b0 <main+0x150>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd7f(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1302 <main+0x1a2>
jmp    12b5 <main+0x155>
cmpl   $0x0,-0x24(%rbp)
je     12dd <main+0x17d>
mov    -0x20(%rbp),%rdi
call   1070 <base64_dec@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x34(%rbp)
jmp    12f6 <main+0x196>
mov    -0x20(%rbp),%rdi
call   1030 <base64_enc@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %r13d,%r13d
lea    0xe8d(%rip),%r14
lea    0x2edf(%rip),%r15
lea    0x4(%rsp),%r12
jmp    1196 <main+0x36>
nopl   0x0(%rax,%rax,1)
mov    $0x1,%r13d
movl   $0x0,0x4(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %r12,%r8
call   1040 <getopt_long@plt>
cmp    $0x64,%eax
je     1190 <main+0x30>
cmp    $0xffffffff,%eax
jne    1196 <main+0x36>
mov    0x2e1e(%rip),%rax
movslq (%rax),%rax
cmp    %ebp,%eax
jge    120b <main+0xab>
lea    0x1(%rax),%ecx
cmp    %ebp,%ecx
jne    122a <main+0xca>
mov    (%rbx,%rax,8),%rbx
lea    0xe2e(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     120b <main+0xab>
lea    0xe1c(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%rdi
test   %rax,%rax
je     124d <main+0xed>
test   %r13d,%r13d
je     121a <main+0xba>
call   1070 <base64_dec@plt>
jmp    121f <main+0xbf>
mov    0x2dd6(%rip),%rax
mov    (%rax),%rdi
test   %r13d,%r13d
jne    1204 <main+0xa4>
call   1030 <base64_enc@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
jmp    123e <main+0xde>
mov    (%rbx),%rsi
lea    0xdea(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdba(%rip),%rdi
mov    %rbx,%rsi
jmp    1234 <main+0xd4>

LLVM IR (-O0):
%struct.option = type { i8*, i8, i32, i32 }
@main.opt_long = internal global [2 x %struct.option] [%struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8 0, i32 0, i32 100 }, %struct.option zeroinitializer]
@.str = [7 x i8] c"decode\00"
@.str.1 = [2 x i8] c"d\00"
@optind = global i32 0
@stdin = global i32* null
@.str.2 = [2 x i8] c"-\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [16 x i8] c"cannot open %s\0A\00"
@.str.5 = [18 x i8] c"Usage: %s <file>\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
br label %12
12: ; preds = %21, %2
store i32 0, i32* %10
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt_long(i32 %13, i8** %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %struct.option* getelementptr inbounds ([2 x %struct.option], [2 x %struct.option]* @main.opt_long, i64 0, i64 0), i32* %10)
store i32 %15, i32* %9
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %12
br label %22
18: ; preds = %12
%19 = load i32, i32* %9
switch i32 %19, label %21 [
i32 100, label %20
]
20: ; preds = %18
store i32 1, i32* %8
br label %21
21: ; preds = %18, %20
br label %12
22: ; preds = %17
%23 = load i32, i32* @optind
%24 = load i32, i32* %4
%25 = icmp sge i32 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = load i32*, i32** @stdin
store i32* %27, i32** %7
br label %59
28: ; preds = %22
%29 = load i32, i32* @optind
%30 = add nsw i32 %29, 1
%31 = load i32, i32* %4
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %53
33: ; preds = %28
%34 = load i8**, i8*** %5
%35 = load i32, i32* @optind
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
store i8* %38, i8** %6
%39 = load i8*, i8** %6
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %33
%43 = load i32*, i32** @stdin
store i32* %43, i32** %7
br label %52
44: ; preds = %33
%45 = load i8*, i8** %6
%46 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %46, i32** %7
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = load i8*, i8** %6
%50 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %49)
store i32 1, i32* %3
br label %77
51: ; preds = %44
br label %52
52: ; preds = %51, %42
br label %58
53: ; preds = %28
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 0
%56 = load i8*, i8** %55
%57 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %56)
store i32 1, i32* %3
br label %77
58: ; preds = %52
br label %59
59: ; preds = %58, %26
%60 = load i32, i32* %8
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %68
62: ; preds = %59
%63 = load i32*, i32** %7
%64 = call i32 @base64_dec(i32* %63)
%65 = icmp ne i32 %64, 0
%66 = xor i1 %65, true
%67 = zext i1 %66 to i32
br label %74
68: ; preds = %59
%69 = load i32*, i32** %7
%70 = call i32 @base64_enc(i32* %69)
%71 = icmp ne i32 %70, 0
%72 = xor i1 %71, true
%73 = zext i1 %72 to i32
br label %74
74: ; preds = %68, %62
%75 = phi i32 [ %67, %62 ], [ %73, %68 ]
store i32 %75, i32* %11
%76 = load i32, i32* %11
store i32 %76, i32* %3
br label %77
77: ; preds = %74, %53, %48
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32, i32 }
@main.opt_long = internal global [2 x %struct.option] [%struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8 0, i32 0, i32 100 }, %struct.option zeroinitializer]
@.str = [7 x i8] c"decode\00"
@.str.1 = [2 x i8] c"d\00"
@optind = global i32 0
@stdin = global i32* null
@.str.2 = [2 x i8] c"-\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [16 x i8] c"cannot open %s\0A\00"
@.str.5 = [18 x i8] c"Usage: %s <file>\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
br label %5
5: ; preds = %9, %2
%6 = phi i32 [ 0, %2 ], [ %10, %9 ]
store i32 0, i32* %3
%7 = call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %struct.option* getelementptr inbounds ([2 x %struct.option], [2 x %struct.option]* @main.opt_long, i64 0, i64 0), i32* %3)
switch i32 %7, label %9 [
i32 -1, label %11
i32 100, label %8
]
8: ; preds = %5
br label %9
9: ; preds = %8, %5
%10 = phi i32 [ 1, %8 ], [ %6, %5 ]
br label %5
11: ; preds = %5
%12 = load i32, i32* @optind
%13 = icmp slt i32 %12, %0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = load i32*, i32** @stdin
br label %35
16: ; preds = %11
%17 = add nsw i32 %12, 1
%18 = icmp eq i32 %17, %0
br i1 %18, label %19, label %32
19: ; preds = %16
%20 = sext i32 %12 to i64
%21 = getelementptr inbounds i8*, i8** %1, i64 %20
%22 = load i8*, i8** %21
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = load i32*, i32** @stdin
br label %35
27: ; preds = %19
%28 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %22)
br label %46
32: ; preds = %16
%33 = load i8*, i8** %1
%34 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %33)
br label %46
35: ; preds = %27, %25, %14
%36 = phi i32* [ %15, %14 ], [ %26, %25 ], [ %28, %27 ]
%37 = icmp eq i32 %6, 0
br i1 %37, label %40, label %38
38: ; preds = %35
%39 = call i32 @base64_dec(i32* %36)
br label %42
40: ; preds = %35
%41 = call i32 @base64_enc(i32* %36)
br label %42
42: ; preds = %40, %38
%43 = phi i32 [ %39, %38 ], [ %41, %40 ]
%44 = icmp eq i32 %43, 0
%45 = zext i1 %44 to i32
br label %46
46: ; preds = %42, %32, %30
%47 = phi i32 [ %45, %42 ], [ 1, %30 ], [ 1, %32 ]
ret i32 %47
}