#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 */
char *malloc(size_t);
char *base64encode(const char *input, size_t inlength) {
  static char b64_lkp[] =
      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  char *buffer = malloc(((inlength + 2) / 3 * 4) + 2);
  char *dest = buffer;
  while (inlength >= 3) {
    unsigned char b1 = *(input++);
    unsigned char b2 = *(input++);
    unsigned char b3 = *(input++);
    *(dest++) = b64_lkp[b1 >> 2];
    *(dest++) = b64_lkp[((b1 & 0x03) << 4) | (b2 >> 4)];
    *(dest++) = b64_lkp[((b2 & 0x0F) << 2) | (b3 >> 6)];
    *(dest++) = b64_lkp[b3 & 0x3F];
    inlength -= 3;
  }
  if (inlength > 0) {
    unsigned char b1 = *(input++);
    *(dest++) = b64_lkp[b1 >> 2];
    if (inlength == 1) {
      *(dest++) = b64_lkp[(b1 & 0x03) << 4];
      *(dest++) = '=';
    } else {
      unsigned char b2 = *input;
      *(dest++) = b64_lkp[((b1 & 0x03) << 4) | (b2 >> 4)];
      *(dest++) = b64_lkp[((b2 & 0x0F) << 2)];
    }
    *(dest++) = '=';
  }
  *dest = 0;
  return buffer;
}


x86 assembly (clang, -O0):
<base64encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdi
shl    $0x2,%rdi
add    $0x2,%rdi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x3,-0x10(%rbp)
jb     1252 <base64encode+0x142>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x21(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x22(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x23(%rbp)
movzbl -0x21(%rbp),%eax
sar    $0x2,%eax
movslq %eax,%rcx
lea    0x2e8a(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
movzbl -0x21(%rbp),%eax
and    $0x3,%eax
shl    $0x4,%eax
movzbl -0x22(%rbp),%ecx
sar    $0x4,%ecx
or     %ecx,%eax
movslq %eax,%rcx
lea    0x2e59(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
movzbl -0x22(%rbp),%eax
and    $0xf,%eax
shl    $0x2,%eax
movzbl -0x23(%rbp),%ecx
sar    $0x6,%ecx
or     %ecx,%eax
movslq %eax,%rcx
lea    0x2e28(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
movzbl -0x23(%rbp),%eax
and    $0x3f,%eax
movslq %eax,%rcx
lea    0x2e03(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
sub    $0x3,%rax
mov    %rax,-0x10(%rbp)
jmp    114e <base64encode+0x3e>
cmpq   $0x0,-0x10(%rbp)
jbe    1354 <base64encode+0x244>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x24(%rbp)
movzbl -0x24(%rbp),%eax
sar    $0x2,%eax
movslq %eax,%rcx
lea    0x2dae(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
cmpq   $0x1,-0x10(%rbp)
jne    12e0 <base64encode+0x1d0>
movzbl -0x24(%rbp),%eax
and    $0x3,%eax
shl    $0x4,%eax
movslq %eax,%rcx
lea    0x2d7b(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x3d,(%rax)
jmp    1342 <base64encode+0x232>
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x25(%rbp)
movzbl -0x24(%rbp),%eax
and    $0x3,%eax
shl    $0x4,%eax
movzbl -0x25(%rbp),%ecx
sar    $0x4,%ecx
or     %ecx,%eax
movslq %eax,%rcx
lea    0x2d2a(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
movzbl -0x25(%rbp),%eax
and    $0xf,%eax
shl    $0x2,%eax
movslq %eax,%rcx
lea    0x2d02(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x3d,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64encode>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x2(%rsi),%rax
movabs $0xaaaaaaaaaaaaaaab,%rcx
aa aa aa
mul    %rcx
lea    (%rdx,%rdx,1),%rdi
or     $0x2,%rdi
call   1030 <malloc@plt>
cmp    $0x3,%r14
jb     11c2 <base64encode+0xb2>
lea    0xeb6(%rip),%r8
mov    %rax,%r9
nopl   (%rax)
movzbl (%r15),%ecx
movzbl 0x1(%r15),%edx
movzbl 0x2(%r15),%esi
add    $0x3,%r15
mov    %rcx,%rdi
shr    $0x2,%rdi
movzbl (%rdi,%r8,1),%ebx
mov    %bl,(%r9)
shl    $0x4,%ecx
and    $0x30,%ecx
mov    %rdx,%rdi
shr    $0x4,%rdi
or     %rcx,%rdi
movzbl (%r8,%rdi,1),%ecx
mov    %cl,0x1(%r9)
and    $0xf,%edx
mov    %rsi,%rcx
shr    $0x6,%rcx
lea    (%rcx,%rdx,4),%rcx
movzbl (%r8,%rcx,1),%ecx
mov    %cl,0x2(%r9)
and    $0x3f,%esi
movzbl (%rsi,%r8,1),%ecx
mov    %cl,0x3(%r9)
add    $0x4,%r9
add    $0xfffffffffffffffd,%r14
cmp    $0x2,%r14
ja     1150 <base64encode+0x40>
test   %r14,%r14
jne    11ca <base64encode+0xba>
jmp    1228 <base64encode+0x118>
mov    %rax,%r9
test   %r14,%r14
je     1228 <base64encode+0x118>
movzbl (%r15),%esi
mov    %rsi,%rcx
shr    $0x2,%rcx
lea    0xe24(%rip),%rdx
mov    (%rcx,%rdx,1),%cl
mov    %cl,(%r9)
cmp    $0x1,%r14
jne    11f9 <base64encode+0xe9>
shl    $0x4,%esi
and    $0x30,%esi
mov    (%rsi,%rdx,1),%cl
mov    %cl,0x1(%r9)
mov    $0x3d,%dl
jmp    121b <base64encode+0x10b>
movzbl 0x1(%r15),%ecx
shl    $0x4,%esi
and    $0x30,%esi
mov    %rcx,%rdi
shr    $0x4,%rdi
or     %rsi,%rdi
mov    (%rdx,%rdi,1),%bl
mov    %bl,0x1(%r9)
and    $0xf,%ecx
mov    (%rdx,%rcx,4),%dl
mov    %dl,0x2(%r9)
movb   $0x3d,0x3(%r9)
add    $0x4,%r9
movb   $0x0,(%r9)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@base64encode.b64_lkp = internal global [65 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\00"
define i8* @base64encode(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8
store i8* %0, i8** %3
store i64 %1, i64* %4
%12 = load i64, i64* %4
%13 = add i64 %12, 2
%14 = udiv i64 %13, 3
%15 = mul i64 %14, 4
%16 = add i64 %15, 2
%17 = call i8* @malloc(i64 %16)
store i8* %17, i8** %5
%18 = load i8*, i8** %5
store i8* %18, i8** %6
br label %19
19: ; preds = %22, %2
%20 = load i64, i64* %4
%21 = icmp uge i64 %20, 3
br i1 %21, label %22, label %76
22: ; preds = %19
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %3
%25 = load i8, i8* %23
store i8 %25, i8* %7
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %3
%28 = load i8, i8* %26
store i8 %28, i8* %8
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %3
%31 = load i8, i8* %29
store i8 %31, i8* %9
%32 = load i8, i8* %7
%33 = zext i8 %32 to i32
%34 = ashr i32 %33, 2
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [65 x i8], [65 x i8]* @base64encode.b64_lkp, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = load i8*, i8** %6
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %6
store i8 %37, i8* %38
%40 = load i8, i8* %7
%41 = zext i8 %40 to i32
%42 = and i32 %41, 3
%43 = shl i32 %42, 4
%44 = load i8, i8* %8
%45 = zext i8 %44 to i32
%46 = ashr i32 %45, 4
%47 = or i32 %43, %46
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [65 x i8], [65 x i8]* @base64encode.b64_lkp, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = load i8*, i8** %6
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %6
store i8 %50, i8* %51
%53 = load i8, i8* %8
%54 = zext i8 %53 to i32
%55 = and i32 %54, 15
%56 = shl i32 %55, 2
%57 = load i8, i8* %9
%58 = zext i8 %57 to i32
%59 = ashr i32 %58, 6
%60 = or i32 %56, %59
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [65 x i8], [65 x i8]* @base64encode.b64_lkp, i64 0, i64 %61
%63 = load i8, i8* %62
%64 = load i8*, i8** %6
%65 = getelementptr inbounds i8, i8* %64, i32 1
store i8* %65, i8** %6
store i8 %63, i8* %64
%66 = load i8, i8* %9
%67 = zext i8 %66 to i32
%68 = and i32 %67, 63
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [65 x i8], [65 x i8]* @base64encode.b64_lkp, i64 0, i64 %69
%71 = load i8, i8* %70
%72 = load i8*, i8** %6
%73 = getelementptr inbounds i8, i8* %72, i32 1
store i8* %73, i8** %6
store i8 %71, i8* %72
%74 = load i64, i64* %4
%75 = sub i64 %74, 3
store i64 %75, i64* %4
br label %19
76: ; preds = %19
%77 = load i64, i64* %4
%78 = icmp ugt i64 %77, 0
br i1 %78, label %79, label %133
79: ; preds = %76
%80 = load i8*, i8** %3
%81 = getelementptr inbounds i8, i8* %80, i32 1
store i8* %81, i8** %3
%82 = load i8, i8* %80
store i8 %82, i8* %10
%83 = load i8, i8* %10
%84 = zext i8 %83 to i32
%85 = ashr i32 %84, 2
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [65 x i8], [65 x i8]* @base64encode.b64_lkp, i64 0, i64 %86
%88 = load i8, i8* %87
%89 = load i8*, i8** %6
%90 = getelementptr inbounds i8, i8* %89, i32 1
store i8* %90, i8** %6
store i8 %88, i8* %89
%91 = load i64, i64* %4
%92 = icmp eq i64 %91, 1
br i1 %92, label %93, label %105
93: ; preds = %79
%94 = load i8, i8* %10
%95 = zext i8 %94 to i32
%96 = and i32 %95, 3
%97 = shl i32 %96, 4
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds [65 x i8], [65 x i8]* @base64encode.b64_lkp, i64 0, i64 %98
%100 = load i8, i8* %99
%101 = load i8*, i8** %6
%102 = getelementptr inbounds i8, i8* %101, i32 1
store i8* %102, i8** %6
store i8 %100, i8* %101
%103 = load i8*, i8** %6
%104 = getelementptr inbounds i8, i8* %103, i32 1
store i8* %104, i8** %6
store i8 61, i8* %103
br label %130
105: ; preds = %79
%106 = load i8*, i8** %3
%107 = load i8, i8* %106
store i8 %107, i8* %11
%108 = load i8, i8* %10
%109 = zext i8 %108 to i32
%110 = and i32 %109, 3
%111 = shl i32 %110, 4
%112 = load i8, i8* %11
%113 = zext i8 %112 to i32
%114 = ashr i32 %113, 4
%115 = or i32 %111, %114
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds [65 x i8], [65 x i8]* @base64encode.b64_lkp, i64 0, i64 %116
%118 = load i8, i8* %117
%119 = load i8*, i8** %6
%120 = getelementptr inbounds i8, i8* %119, i32 1
store i8* %120, i8** %6
store i8 %118, i8* %119
%121 = load i8, i8* %11
%122 = zext i8 %121 to i32
%123 = and i32 %122, 15
%124 = shl i32 %123, 2
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds [65 x i8], [65 x i8]* @base64encode.b64_lkp, i64 0, i64 %125
%127 = load i8, i8* %126
%128 = load i8*, i8** %6
%129 = getelementptr inbounds i8, i8* %128, i32 1
store i8* %129, i8** %6
store i8 %127, i8* %128
br label %130
130: ; preds = %105, %93
%131 = load i8*, i8** %6
%132 = getelementptr inbounds i8, i8* %131, i32 1
store i8* %132, i8** %6
store i8 61, i8* %131
br label %133
133: ; preds = %130, %76
%134 = load i8*, i8** %6
store i8 0, i8* %134
%135 = load i8*, i8** %5
ret i8* %135
}

LLVM IR (-O2):
@base64encode.b64_lkp = internal unnamed_addr constant [65 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\00"
define noalias i8* @base64encode(i8* nocapture %0, i64 %1) {
%3 = add i64 %1, 2
%4 = udiv i64 %3, 3
%5 = shl i64 %4, 2
%6 = or i64 %5, 2
%7 = tail call i8* @malloc(i64 %6)
%8 = icmp ugt i64 %1, 2
br i1 %8, label %9, label %50
9: ; preds = %2, %9
%10 = phi i8* [ %17, %9 ], [ %0, %2 ]
%11 = phi i64 [ %48, %9 ], [ %1, %2 ]
%12 = phi i8* [ %47, %9 ], [ %7, %2 ]
%13 = getelementptr inbounds i8, i8* %10, i64 1
%14 = load i8, i8* %10
%15 = getelementptr inbounds i8, i8* %10, i64 2
%16 = load i8, i8* %13
%17 = getelementptr inbounds i8, i8* %10, i64 3
%18 = load i8, i8* %15
%19 = zext i8 %14 to i32
%20 = lshr i32 %19, 2
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [65 x i8], [65 x i8]* @base64encode.b64_lkp, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = getelementptr inbounds i8, i8* %12, i64 1
store i8 %23, i8* %12
%25 = shl nuw nsw i32 %19, 4
%26 = and i32 %25, 48
%27 = zext i8 %16 to i32
%28 = lshr i32 %27, 4
%29 = or i32 %26, %28
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds [65 x i8], [65 x i8]* @base64encode.b64_lkp, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = getelementptr inbounds i8, i8* %12, i64 2
store i8 %32, i8* %24
%34 = shl nuw nsw i32 %27, 2
%35 = and i32 %34, 60
%36 = zext i8 %18 to i32
%37 = lshr i32 %36, 6
%38 = or i32 %35, %37
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds [65 x i8], [65 x i8]* @base64encode.b64_lkp, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = getelementptr inbounds i8, i8* %12, i64 3
store i8 %41, i8* %33
%43 = and i32 %36, 63
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds [65 x i8], [65 x i8]* @base64encode.b64_lkp, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = getelementptr inbounds i8, i8* %12, i64 4
store i8 %46, i8* %42
%48 = add i64 %11, -3
%49 = icmp ugt i64 %48, 2
br i1 %49, label %9, label %50
50: ; preds = %9, %2
%51 = phi i8* [ %7, %2 ], [ %47, %9 ]
%52 = phi i64 [ %1, %2 ], [ %48, %9 ]
%53 = phi i8* [ %0, %2 ], [ %17, %9 ]
%54 = icmp eq i64 %52, 0
br i1 %54, label %91, label %55
55: ; preds = %50
%56 = load i8, i8* %53
%57 = zext i8 %56 to i32
%58 = lshr i32 %57, 2
%59 = zext i32 %58 to i64
%60 = getelementptr inbounds [65 x i8], [65 x i8]* @base64encode.b64_lkp, i64 0, i64 %59
%61 = load i8, i8* %60
%62 = getelementptr inbounds i8, i8* %51, i64 1
store i8 %61, i8* %51
%63 = icmp eq i64 %52, 1
br i1 %63, label %64, label %70
64: ; preds = %55
%65 = shl nuw nsw i32 %57, 4
%66 = and i32 %65, 48
%67 = zext i32 %66 to i64
%68 = getelementptr inbounds [65 x i8], [65 x i8]* @base64encode.b64_lkp, i64 0, i64 %67
%69 = load i8, i8* %68
store i8 %69, i8* %62
br label %86
70: ; preds = %55
%71 = getelementptr inbounds i8, i8* %53, i64 1
%72 = load i8, i8* %71
%73 = shl nuw nsw i32 %57, 4
%74 = and i32 %73, 48
%75 = zext i8 %72 to i32
%76 = lshr i32 %75, 4
%77 = or i32 %76, %74
%78 = zext i32 %77 to i64
%79 = getelementptr inbounds [65 x i8], [65 x i8]* @base64encode.b64_lkp, i64 0, i64 %78
%80 = load i8, i8* %79
store i8 %80, i8* %62
%81 = shl nuw nsw i32 %75, 2
%82 = and i32 %81, 60
%83 = zext i32 %82 to i64
%84 = getelementptr inbounds [65 x i8], [65 x i8]* @base64encode.b64_lkp, i64 0, i64 %83
%85 = load i8, i8* %84
br label %86
86: ; preds = %70, %64
%87 = phi i8 [ 61, %64 ], [ %85, %70 ]
%88 = getelementptr inbounds i8, i8* %51, i64 2
store i8 %87, i8* %88
%89 = getelementptr inbounds i8, i8* %51, i64 3
%90 = getelementptr inbounds i8, i8* %51, i64 4
store i8 61, i8* %89
br label %91
91: ; preds = %86, %50
%92 = phi i8* [ %90, %86 ], [ %51, %50 ]
store i8 0, i8* %92
ret i8* %7
}