#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 */
typedef int /*<<< orphan*/ res;
typedef int /*<<< orphan*/ out;

/* Variables and functions */
int /*<<< orphan*/ b64_decode(char *, size_t, char *, size_t *);
int /*<<< orphan*/ b64_encode(char *, int /*<<< orphan*/, char *, size_t *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ urlsafe_b64_decode(char *, size_t, char *, size_t *);
int /*<<< orphan*/ urlsafe_b64_encode(char *, int /*<<< orphan*/, char *,
                                      size_t *);
int main(int argc, char *argv[]) {
  char in[] = "bradley";
  char out[256] = {0};
  char res[256] = {0};
  size_t len = 0;
  size_t len_res = 0;
  len = sizeof(out);
  len_res = sizeof(res);
  b64_encode(in, strlen(in), out, &len);
  printf("b64_enc: %s\n", out);
  b64_decode(out, len, res, &len_res);
  printf("b64_dec: %s\n", res);
  memset(out, 0, sizeof(out));
  len = sizeof(out);
  memset(res, 0, sizeof(res));
  len_res = sizeof(res);
  urlsafe_b64_encode(in, strlen(in), out, &len);
  printf("urlsafe_b64_enc: %s\n", out);
  urlsafe_b64_decode(out, len, res, &len_res);
  printf("urlsafe_b64_dec: %s\n", res);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe70(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
movq   $0x0,-0x228(%rbp)
movq   $0x0,-0x230(%rbp)
movq   $0x100,-0x228(%rbp)
movq   $0x100,-0x230(%rbp)
lea    -0x18(%rbp),%rax
mov    %rax,-0x240(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x240(%rbp),%rdi
mov    %eax,%esi
lea    -0x120(%rbp),%rdx
lea    -0x228(%rbp),%rcx
call   1060 <b64_encode@plt>
lea    -0x120(%rbp),%rsi
lea    0xdec(%rip),%rdi
call   1050 <printf@plt>
lea    -0x120(%rbp),%rdi
mov    -0x228(%rbp),%rsi
lea    -0x220(%rbp),%rdx
lea    -0x230(%rbp),%rcx
call   1030 <b64_decode@plt>
lea    -0x220(%rbp),%rsi
lea    0xdcd(%rip),%rdi
call   1050 <printf@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
movq   $0x100,-0x228(%rbp)
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
movq   $0x100,-0x230(%rbp)
lea    -0x18(%rbp),%rax
mov    %rax,-0x238(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x238(%rbp),%rdi
mov    %eax,%esi
lea    -0x120(%rbp),%rdx
lea    -0x228(%rbp),%rcx
call   1090 <urlsafe_b64_encode@plt>
lea    -0x120(%rbp),%rsi
lea    0xd31(%rip),%rdi
call   1050 <printf@plt>
lea    -0x120(%rbp),%rdi
mov    -0x228(%rbp),%rsi
lea    -0x220(%rbp),%rdx
lea    -0x230(%rbp),%rcx
call   1080 <urlsafe_b64_decode@plt>
lea    -0x220(%rbp),%rsi
lea    0xd12(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x220,%rsp
movabs $0x79656c64617262,%rax
mov    %rax,0x18(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x210(%rsp)
movaps %xmm0,0x200(%rsp)
movaps %xmm0,0x1f0(%rsp)
movaps %xmm0,0x1e0(%rsp)
movaps %xmm0,0x1d0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
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)
movq   $0x100,0x8(%rsp)
movq   $0x100,0x10(%rsp)
lea    0x18(%rsp),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0x120(%rsp),%rbx
lea    0x8(%rsp),%r12
mov    %r15,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1060 <b64_encode@plt>
lea    0xd45(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    0x8(%rsp),%rsi
lea    0x20(%rsp),%r14
lea    0x10(%rsp),%r13
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r13,%rcx
call   1030 <b64_decode@plt>
lea    0xd2e(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
movq   $0x100,0x8(%rsp)
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
movq   $0x100,0x10(%rsp)
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1090 <urlsafe_b64_encode@plt>
lea    0xcba(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r13,%rcx
call   1080 <urlsafe_b64_decode@plt>
lea    0xcad(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.in = [8 x i8] c"bradley\00"
@.str = [13 x i8] c"b64_enc: %s\0A\00"
@.str.1 = [13 x i8] c"b64_dec: %s\0A\00"
@.str.2 = [21 x i8] c"urlsafe_b64_enc: %s\0A\00"
@.str.3 = [21 x i8] c"urlsafe_b64_dec: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [8 x i8]
%7 = alloca [256 x i8]
%8 = alloca [256 x i8]
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [8 x i8]* %6 to i8*
%12 = bitcast [256 x i8]* %7 to i8*
%13 = bitcast [256 x i8]* %8 to i8*
store i64 0, i64* %9
store i64 0, i64* %10
store i64 256, i64* %9
store i64 256, i64* %10
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%18 = call i32 @b64_encode(i8* %14, i32 %16, i8* %17, i64* %9)
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%20 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%22 = load i64, i64* %9
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%24 = call i32 @b64_decode(i8* %21, i64 %22, i8* %23, i64* %10)
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%26 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%28 = call i32 @memset(i8* %27, i32 0, i32 256)
store i64 256, i64* %9
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%30 = call i32 @memset(i8* %29, i32 0, i32 256)
store i64 256, i64* %10
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%32 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%33 = call i32 @strlen(i8* %32)
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%35 = call i32 @urlsafe_b64_encode(i8* %31, i32 %33, i8* %34, i64* %9)
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%37 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %36)
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%39 = load i64, i64* %9
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%41 = call i32 @urlsafe_b64_decode(i8* %38, i64 %39, i8* %40, i64* %10)
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%43 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %42)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"b64_enc: %s\0A\00"
@.str.1 = [13 x i8] c"b64_dec: %s\0A\00"
@.str.2 = [21 x i8] c"urlsafe_b64_enc: %s\0A\00"
@.str.3 = [21 x i8] c"urlsafe_b64_dec: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = alloca i64
%7 = alloca i64
%8 = bitcast i64* %3 to i8*
store i64 34169988396970594, i64* %3
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%11 = bitcast i64* %6 to i8*
%12 = bitcast i64* %7 to i8*
store i64 256, i64* %6
store i64 256, i64* %7
%13 = call i32 @strlen(i8* %8)
%14 = call i32 @b64_encode(i8* %8, i32 %13, i8* %9, i64* %6)
%15 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %9)
%16 = load i64, i64* %6
%17 = call i32 @b64_decode(i8* %9, i64 %16, i8* %10, i64* %7)
%18 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%19 = call i32 @memset(i8* %9, i32 0, i32 256)
store i64 256, i64* %6
%20 = call i32 @memset(i8* %10, i32 0, i32 256)
store i64 256, i64* %7
%21 = call i32 @strlen(i8* %8)
%22 = call i32 @urlsafe_b64_encode(i8* %8, i32 %21, i8* %9, i64* %6)
%23 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%24 = load i64, i64* %6
%25 = call i32 @urlsafe_b64_decode(i8* %9, i64 %24, i8* %10, i64* %7)
%26 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %10)
ret i32 0
}