#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*/ base64_decode_alloc(char *, int /*<<< orphan*/, char **,
                                       int *);
int base64_encode_alloc(char *, int /*<<< orphan*/, char **);
int getopt(int, char **, char *);
char *optarg;
int /*<<< orphan*/ printf(char *, char *, char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  if (argc < 2) {
    usage(argv[0]);
    return -1;
  }
  int ch = 0;
  char *out = NULL;
  int len = -1;
  while ((ch = getopt(argc, argv, "e:d:h")) != -1) {
    switch (ch) {
    case 'e': {
      len = base64_encode_alloc(optarg, strlen(optarg), &out);
      printf("source:%s , encoded:%s , encode_len:%d\n", optarg, out, len);
      out = NULL;
      len = -1;
    } break;
    case 'd': {
      base64_decode_alloc(optarg, strlen(optarg), &out, &len);
      printf("source:%s , encoded:%s , decode_len:%d\n", optarg, out, len);
      out = NULL;
      len = -1;
    } break;
    case 'h': {
      usage(argv[0]);
    } break;
    case '?': {
      usage(argv[0]);
    } break;
    }
  }
  return 0;
}


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)
cmpl   $0x2,-0x8(%rbp)
jge    1198 <main+0x38>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12fe <main+0x19e>
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe44(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     12f7 <main+0x197>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x3f,%eax
je     12e6 <main+0x186>
jmp    11e1 <main+0x81>
mov    -0x28(%rbp),%eax
sub    $0x64,%eax
je     1274 <main+0x114>
jmp    11f2 <main+0x92>
mov    -0x28(%rbp),%eax
sub    $0x65,%eax
je     1214 <main+0xb4>
jmp    1203 <main+0xa3>
mov    -0x28(%rbp),%eax
sub    $0x68,%eax
je     12d5 <main+0x175>
jmp    12f2 <main+0x192>
mov    0x2ddd(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
lea    -0x20(%rbp),%rdx
call   1060 <base64_encode_alloc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2dae(%rip),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    0xdab(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
jmp    12f2 <main+0x192>
mov    0x2d7d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d6f(%rip),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
call   1040 <base64_decode_alloc@plt>
mov    0x2d4d(%rip),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    0xd72(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
jmp    12f2 <main+0x192>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
jmp    12f2 <main+0x192>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
jmp    11ae <main+0x4e>
movl   $0x0,-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
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     1188 <main+0x28>
mov    (%rbx),%rdi
call   1070 <usage@plt>
mov    $0xffffffff,%eax
jmp    1283 <main+0x123>
mov    %edi,%r12d
movq   $0x0,0x10(%rsp)
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xe5d(%rip),%r14
mov    0x2e4e(%rip),%r15
lea    0x10(%rsp),%r13
jmp    11c8 <main+0x68>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%rdi
call   1070 <usage@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1080 <getopt@plt>
cmp    $0x64,%eax
jg     1220 <main+0xc0>
cmp    $0x3f,%eax
je     11c0 <main+0x60>
cmp    $0x64,%eax
jne    1278 <main+0x118>
mov    (%r15),%rbp
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %rbp,%rdi
mov    %eax,%esi
mov    %r13,%rdx
lea    0xc(%rsp),%rcx
call   1040 <base64_decode_alloc@plt>
mov    (%r15),%rsi
mov    0x10(%rsp),%rdx
mov    0xc(%rsp),%ecx
lea    0xe15(%rip),%rdi
jmp    125d <main+0xfd>
nopl   0x0(%rax,%rax,1)
cmp    $0x68,%eax
je     11c0 <main+0x60>
cmp    $0x65,%eax
jne    11c8 <main+0x68>
mov    %r13,%rbp
mov    (%r15),%r13
mov    %r13,%rdi
call   1030 <strlen@plt>
mov    %r13,%rdi
mov    %rbp,%r13
mov    %eax,%esi
mov    %rbp,%rdx
call   1060 <base64_encode_alloc@plt>
mov    %eax,0xc(%rsp)
mov    (%r15),%rsi
mov    0x10(%rsp),%rdx
lea    0xdab(%rip),%rdi
mov    %eax,%ecx
call   1050 <printf@plt>
movq   $0x0,0x10(%rsp)
movl   $0xffffffff,0xc(%rsp)
ff
jmp    11c8 <main+0x68>
cmp    $0xffffffff,%eax
jne    11c8 <main+0x68>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"e:d:h\00"
@optarg = global i8* null
@.str.1 = [40 x i8] c"source:%s , encoded:%s , encode_len:%d\0A\00"
@.str.2 = [40 x i8] c"source:%s , encoded:%s , decode_len:%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @usage(i8* %7)
br label %37
9: ; preds = %2
%10 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%11 = bitcast i32* %4 to i8*
store i32 -1, i32* %4
br label %12
12: ; preds = %14, %9
%13 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
switch i32 %13, label %14 [
i32 -1, label %36
i32 101, label %15
i32 100, label %22
i32 104, label %30
i32 63, label %33
]
14: ; preds = %12, %33, %30, %22, %15
br label %12
15: ; preds = %12
%16 = load i8*, i8** @optarg
%17 = call i32 @strlen(i8* %16)
%18 = call i32 @base64_encode_alloc(i8* %16, i32 %17, i8** %3)
store i32 %18, i32* %4
%19 = load i8*, i8** @optarg
%20 = load i8*, i8** %3
%21 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %20, i32 %18)
store i8* null, i8** %3
store i32 -1, i32* %4
br label %14
22: ; preds = %12
%23 = load i8*, i8** @optarg
%24 = call i32 @strlen(i8* %23)
%25 = call i32 @base64_decode_alloc(i8* %23, i32 %24, i8** %3, i32* %4)
%26 = load i8*, i8** @optarg
%27 = load i8*, i8** %3
%28 = load i32, i32* %4
%29 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %26, i8* %27, i32 %28)
store i8* null, i8** %3
store i32 -1, i32* %4
br label %14
30: ; preds = %12
%31 = load i8*, i8** %1
%32 = call i32 @usage(i8* %31)
br label %14
33: ; preds = %12
%34 = load i8*, i8** %1
%35 = call i32 @usage(i8* %34)
br label %14
36: ; preds = %12
br label %37
37: ; preds = %36, %6
%38 = phi i32 [ -1, %6 ], [ 0, %36 ]
ret i32 %38
}