#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(unsigned long);
char *b64_encode(char *str, unsigned long len) {
  const char b64[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                       "abcdefghijklmnopqrstuvwxyz"
                       "0123456789+/";
  char *ret, *chunk;
  chunk = malloc(((len + 3) << 2) / 4);
  ret = chunk;
  do {
    if (len >= 3) {
      unsigned long bitwise = (str[0] << 16) | (str[1] << 8) | str[2];
      *(chunk++) = b64[bitwise >> 18];
      *(chunk++) = b64[(bitwise >> 12) & 0x3F];
      *(chunk++) = b64[(bitwise >> 6) & 0x3F];
      *(chunk++) = b64[bitwise & 0x3F];
      len -= 3;
      str += 3;
    } else if (len == 2) {
      unsigned long bitwise = (str[0] << 16) | (str[1] << 8);
      *(chunk++) = b64[bitwise >> 18];
      *(chunk++) = b64[(bitwise >> 12) & 0x3F];
      *(chunk++) = b64[(bitwise >> 6) & 0x3D];
      *(chunk++) = '=';
      len -= 2;
      str += 2;
    } else {
      unsigned long bitwise = (str[0] << 16);
      ;
      *(chunk++) = b64[bitwise >> 18];
      *(chunk++) = b64[(bitwise >> 12) & 0x3F];
      *(chunk++) = '=';
      *(chunk++) = '=';
      len--;
      str++;
    }
  } while (len);
  *chunk = 0;
  return ret;
}


x86 assembly (clang, -O0):
<b64_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xec2(%rip),%rsi
mov    $0x40,%edx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rdi
add    $0x3,%rdi
shl    $0x2,%rdi
shr    $0x2,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x3,-0x10(%rbp)
jb     1234 <b64_encode+0x114>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
shl    $0x10,%eax
mov    -0x8(%rbp),%rcx
movsbl 0x1(%rcx),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x8(%rbp),%rcx
movsbl 0x2(%rcx),%ecx
or     %ecx,%eax
cltq
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
shr    $0x12,%rax
mov    -0x50(%rbp,%rax,1),%cl
mov    -0x60(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x60(%rbp)
mov    %cl,(%rax)
mov    -0x68(%rbp),%rax
shr    $0xc,%rax
and    $0x3f,%rax
mov    -0x50(%rbp,%rax,1),%cl
mov    -0x60(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x60(%rbp)
mov    %cl,(%rax)
mov    -0x68(%rbp),%rax
shr    $0x6,%rax
and    $0x3f,%rax
mov    -0x50(%rbp,%rax,1),%cl
mov    -0x60(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x60(%rbp)
mov    %cl,(%rax)
mov    -0x68(%rbp),%rax
and    $0x3f,%rax
mov    -0x50(%rbp,%rax,1),%cl
mov    -0x60(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x60(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
sub    $0x3,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x8(%rbp)
jmp    1379 <b64_encode+0x259>
cmpq   $0x2,-0x10(%rbp)
jne    12ea <b64_encode+0x1ca>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
shl    $0x10,%eax
mov    -0x8(%rbp),%rcx
movsbl 0x1(%rcx),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
cltq
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rax
shr    $0x12,%rax
mov    -0x50(%rbp,%rax,1),%cl
mov    -0x60(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x60(%rbp)
mov    %cl,(%rax)
mov    -0x70(%rbp),%rax
shr    $0xc,%rax
and    $0x3f,%rax
mov    -0x50(%rbp,%rax,1),%cl
mov    -0x60(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x60(%rbp)
mov    %cl,(%rax)
mov    -0x70(%rbp),%rax
shr    $0x6,%rax
and    $0x3d,%rax
mov    -0x50(%rbp,%rax,1),%cl
mov    -0x60(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x60(%rbp)
mov    %cl,(%rax)
mov    -0x60(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x60(%rbp)
movb   $0x3d,(%rax)
mov    -0x10(%rbp),%rax
sub    $0x2,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
jmp    1374 <b64_encode+0x254>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
shl    $0x10,%eax
cltq
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
shr    $0x12,%rax
mov    -0x50(%rbp,%rax,1),%cl
mov    -0x60(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x60(%rbp)
mov    %cl,(%rax)
mov    -0x78(%rbp),%rax
shr    $0xc,%rax
and    $0x3f,%rax
mov    -0x50(%rbp,%rax,1),%cl
mov    -0x60(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x60(%rbp)
mov    %cl,(%rax)
mov    -0x60(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x60(%rbp)
movb   $0x3d,(%rax)
mov    -0x60(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x60(%rbp)
movb   $0x3d,(%rax)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1379 <b64_encode+0x259>
jmp    137e <b64_encode+0x25e>
cmpq   $0x0,-0x10(%rbp)
jne    1169 <b64_encode+0x49>
mov    -0x60(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x58(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<b64_encode>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x3(%rsi),%rax
movabs $0x3fffffffffffffff,%rdi
ff ff 3f
and    %rax,%rdi
call   1030 <malloc@plt>
lea    0xec8(%rip),%r8
mov    %rax,%rcx
jmp    11b1 <b64_encode+0xa1>
nopl   (%rax)
movsbq (%r15),%rsi
shl    $0x10,%rsi
movsbq 0x1(%r15),%rdi
shl    $0x8,%rdi
or     %rsi,%rdi
movsbq 0x2(%r15),%rsi
or     %rdi,%rsi
mov    %rsi,%rdi
shr    $0x12,%rdi
movzbl (%rdi,%r8,1),%edx
mov    %dl,(%rcx)
mov    %esi,%edx
shr    $0xc,%edx
and    $0x3f,%edx
movzbl (%rdx,%r8,1),%edx
mov    %dl,0x1(%rcx)
mov    %esi,%edx
shr    $0x6,%edx
and    $0x3f,%edx
movzbl (%rdx,%r8,1),%edx
mov    %dl,0x2(%rcx)
and    $0x3f,%esi
movzbl (%rsi,%r8,1),%edx
mov    %dl,0x3(%rcx)
mov    $0x3,%edi
mov    $0xfffffffffffffffd,%rsi
add    %rdi,%r15
add    $0x4,%rcx
add    %rsi,%r14
je     1237 <b64_encode+0x127>
cmp    $0x3,%r14
jae    1140 <b64_encode+0x30>
movsbq (%r15),%rsi
shl    $0x10,%rsi
cmp    $0x2,%r14
je     11f9 <b64_encode+0xe9>
movslq %esi,%rdx
mov    %rdx,%rsi
shr    $0x12,%rsi
movzbl (%rsi,%r8,1),%ebx
mov    %bl,(%rcx)
shr    $0xc,%rdx
and    $0x30,%edx
movzbl (%rdx,%r8,1),%edx
mov    %dl,0x1(%rcx)
movw   $0x3d3d,0x2(%rcx)
mov    $0x1,%edi
mov    $0xffffffffffffffff,%rsi
jmp    11a1 <b64_encode+0x91>
movsbq 0x1(%r15),%rdx
shl    $0x8,%rdx
or     %rsi,%rdx
mov    %rdx,%rsi
shr    $0x12,%rsi
mov    (%rsi,%r8,1),%bl
mov    %bl,(%rcx)
mov    %edx,%esi
shr    $0xc,%esi
and    $0x3f,%esi
mov    (%rsi,%r8,1),%bl
mov    %bl,0x1(%rcx)
shr    $0x6,%rdx
and    $0x3c,%edx
mov    (%rdx,%r8,1),%dl
mov    %dl,0x2(%rcx)
movb   $0x3d,0x3(%rcx)
add    $0x4,%rcx
movb   $0x0,(%rcx)
pop    %rbx
pop    %r14
pop    %r15
ret

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

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