#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(char *, int, char *);
int /*<<< orphan*/ base64_encode(char *, int, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  int len, decode_len, nopad;
  len = strlen(argv[1]);
  nopad = (len * 4) / 3;
  if (nopad & 0x03) {
    decode_len = nopad + (4 - (nopad % 4));
  } else {
    decode_len = nopad;
  }
  char *output = (char *)malloc(decode_len);
  base64_encode(argv[1], len, output);
  printf("encode: %s\n", output);
  char *decode = (char *)malloc(len + 1);
  base64_decode(output, decode_len, decode);
  printf("decode: %s\n", decode);
  free(output);
  free(decode);
  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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x2,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x3,%eax
cmp    $0x0,%eax
je     11cb <main+0x6b>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0x34(%rbp),%eax
mov    $0x4,%ecx
sub    %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    11d1 <main+0x71>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x14(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1070 <base64_encode@plt>
mov    -0x28(%rbp),%rsi
lea    0xe04(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x30(%rbp),%rdx
call   1080 <base64_decode@plt>
mov    -0x30(%rbp),%rsi
lea    0xde1(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
lea    0x0(,%r14,4),%eax
cltq
imul   $0x55555556,%rax,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
shr    $0x20,%rbx
add    %eax,%ebx
test   $0x3,%bl
je     11aa <main+0x4a>
lea    0x3(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xfffffffc,%eax
add    $0x4,%eax
mov    %eax,%ebx
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    0x8(%r15),%rdi
mov    %r14d,%esi
mov    %rax,%rdx
call   1070 <base64_encode@plt>
lea    0xe36(%rip),%rdi
mov    %r12,%rsi
call   1050 <printf@plt>
add    $0x1,%r14d
mov    %r14d,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %r12,%rdi
mov    %ebx,%esi
mov    %rax,%rdx
call   1080 <base64_decode@plt>
lea    0xe17(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [12 x i8] c"encode: %s\0A\00"
@.str.1 = [12 x i8] c"decode: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @strlen(i8* %4)
%6 = shl nsw i32 %5, 2
%7 = sdiv i32 %6, 3
%8 = and i32 %7, 3
%9 = icmp eq i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = srem i32 %7, 4
%12 = add nsw i32 %7, 4
%13 = sub nsw i32 %12, %11
br label %14
14: ; preds = %2, %10
%15 = phi i32 [ %13, %10 ], [ %7, %2 ]
%16 = tail call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
%18 = load i8*, i8** %3
%19 = tail call i32 @base64_encode(i8* %18, i32 %5, i8* %17)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %17)
%21 = add nsw i32 %5, 1
%22 = tail call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
%24 = tail call i32 @base64_decode(i8* %17, i32 %15, i8* %23)
%25 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%26 = tail call i32 @free(i8* %17)
%27 = tail call i32 @free(i8* %23)
ret i32 0
}