#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 base64_decode(unsigned char *, int /*<<< orphan*/, unsigned char *,
                  unsigned long *);
int base64_encode(unsigned char *, int /*<<< orphan*/, unsigned char *,
                  unsigned long *);
int getopt(int, char **, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  int ch;
  char tmp[128] = {0};
  char buf[128] = {0};
  unsigned long outlen;
  int res;
  if (argc < 3)
    usage();
  while ((ch = getopt(argc, argv, "ed:")) != -1)
    switch (ch) {
    case 'e':
      strcpy(tmp, argv[2]);
      outlen = 128;
      res = base64_encode((unsigned char *)tmp, strlen(tmp),
                          (unsigned char *)buf, &outlen);
      printf("%s\n", buf);
      break;
    case 'd':
      strcpy(tmp, argv[2]);
      outlen = 128;
      res = base64_decode((unsigned char *)tmp, strlen(tmp),
                          (unsigned char *)buf, &outlen);
      printf("%s\n", buf);
      break;
    default:
      usage();
    }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
cmpl   $0x3,-0x8(%rbp)
jge    11d0 <main+0x50>
mov    $0x0,%al
call   1080 <usage@plt>
jmp    11d5 <main+0x55>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe1d(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1311 <main+0x191>
mov    -0x14(%rbp),%eax
mov    %eax,-0x130(%rbp)
sub    $0x64,%eax
je     1292 <main+0x112>
jmp    120b <main+0x8b>
mov    -0x130(%rbp),%eax
sub    $0x65,%eax
jne    1305 <main+0x185>
jmp    121f <main+0x9f>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1030 <strcpy@plt>
movq   $0x80,-0x128(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0x138(%rbp)
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x138(%rbp),%rdi
mov    %eax,%esi
lea    -0x120(%rbp),%rdx
lea    -0x128(%rbp),%rcx
call   1070 <base64_encode@plt>
mov    %eax,-0x12c(%rbp)
lea    -0x120(%rbp),%rsi
lea    0xd7c(%rip),%rdi
call   1050 <printf@plt>
jmp    130c <main+0x18c>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1030 <strcpy@plt>
movq   $0x80,-0x128(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0x140(%rbp)
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x140(%rbp),%rdi
mov    %eax,%esi
lea    -0x120(%rbp),%rdx
lea    -0x128(%rbp),%rcx
call   10a0 <base64_decode@plt>
mov    %eax,-0x12c(%rbp)
lea    -0x120(%rbp),%rsi
lea    0xd09(%rip),%rdi
call   1050 <printf@plt>
jmp    130c <main+0x18c>
mov    $0x0,%al
call   1080 <usage@plt>
jmp    11d5 <main+0x55>
xor    %eax,%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%rbx
mov    %edi,%r15d
xorps  %xmm0,%xmm0
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
cmp    $0x2,%edi
jg     1201 <main+0x91>
xor    %eax,%eax
call   1070 <usage@plt>
lea    0xdf8(%rip),%r14
lea    0x90(%rsp),%rbp
lea    0x10(%rsp),%r12
lea    0xde8(%rip),%r13
jmp    125a <main+0xea>
xchg   %ax,%ax
mov    0x10(%rbx),%rsi
mov    %rbp,%rdi
call   1030 <strcpy@plt>
movq   $0x80,0x8(%rsp)
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %rbp,%rdi
mov    %eax,%esi
mov    %r12,%rdx
lea    0x8(%rsp),%rcx
call   1060 <base64_encode@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <printf@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1080 <getopt@plt>
cmp    $0x64,%eax
je     1280 <main+0x110>
cmp    $0x65,%eax
je     1220 <main+0xb0>
cmp    $0xffffffff,%eax
je     12b1 <main+0x141>
xor    %eax,%eax
call   1070 <usage@plt>
jmp    125a <main+0xea>
mov    0x10(%rbx),%rsi
mov    %rbp,%rdi
call   1030 <strcpy@plt>
movq   $0x80,0x8(%rsp)
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %rbp,%rdi
mov    %eax,%esi
mov    %r12,%rdx
lea    0x8(%rsp),%rcx
call   1090 <base64_decode@plt>
jmp    124f <main+0xdf>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"ed:\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [128 x i8]
%8 = alloca [128 x i8]
%9 = alloca i64
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [128 x i8]* %7 to i8*
%12 = bitcast [128 x i8]* %8 to i8*
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (...) @usage()
br label %17
17: ; preds = %15, %2
br label %18
18: ; preds = %53, %17
%19 = load i32, i32* %4
%20 = load i8**, i8*** %5
%21 = call i32 @getopt(i32 %19, i8** %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %21, i32* %6
%22 = icmp ne i32 %21, -1
br i1 %22, label %23, label %54
23: ; preds = %18
%24 = load i32, i32* %6
switch i32 %24, label %51 [
i32 101, label %25
i32 100, label %38
]
25: ; preds = %23
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @strcpy(i8* %26, i8* %29)
store i64 128, i64* %9
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%33 = call i32 @strlen(i8* %32)
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%35 = call i32 @base64_encode(i8* %31, i32 %33, i8* %34, i64* %9)
store i32 %35, i32* %10
%36 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %36)
br label %53
38: ; preds = %23
%39 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i32 @strcpy(i8* %39, i8* %42)
store i64 128, i64* %9
%44 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%45 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%46 = call i32 @strlen(i8* %45)
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%48 = call i32 @base64_decode(i8* %44, i32 %46, i8* %47, i64* %9)
store i32 %48, i32* %10
%49 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%50 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %49)
br label %53
51: ; preds = %23
%52 = call i32 (...) @usage()
br label %53
53: ; preds = %51, %38, %25
br label %18
54: ; preds = %18
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"ed:\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = alloca i64
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%8 = bitcast i64* %5 to i8*
%9 = icmp slt i32 %0, 3
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 (...) @usage()
br label %12
12: ; preds = %10, %2
%13 = getelementptr inbounds i8*, i8** %1, i64 2
br label %14
14: ; preds = %30, %12
%15 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %15, label %28 [
i32 -1, label %31
i32 101, label %16
i32 100, label %22
]
16: ; preds = %14
%17 = load i8*, i8** %13
%18 = call i32 @strcpy(i8* %6, i8* %17)
store i64 128, i64* %5
%19 = call i32 @strlen(i8* %6)
%20 = call i32 @base64_encode(i8* %6, i32 %19, i8* %7, i64* %5)
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %30
22: ; preds = %14
%23 = load i8*, i8** %13
%24 = call i32 @strcpy(i8* %6, i8* %23)
store i64 128, i64* %5
%25 = call i32 @strlen(i8* %6)
%26 = call i32 @base64_decode(i8* %6, i32 %25, i8* %7, i64* %5)
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %30
28: ; preds = %14
%29 = call i32 (...) @usage()
br label %30
30: ; preds = %28, %22, %16
br label %14
31: ; preds = %14
ret i32 0
}