#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 uint32_t;

/* Variables and functions */
char base64b16(unsigned char const);
char base64b8(unsigned char const);
char base64char(unsigned char const);
int Base64Encode(const unsigned char *Input, uint32_t Length, char *Output,
                 uint32_t OutLen) {
  uint32_t reqSize;
  uint32_t curPos = 0;
  uint32_t dstPos = 0;
  uint32_t line = 0;
  if (!(Input)) {
    return -1;
  }
  reqSize = (Length == 0) ? (0) : ((((Length - 1) / 3) + 1) * 4);
  reqSize += ((reqSize + 63) / 64) * 2;
  if (Output == NULL) {
    return reqSize;
  } else if (OutLen < reqSize) {
    return -1;
  }
  while (Length - curPos >= 3) {
    char c1 = base64char(Input[curPos] >> 2);
    char c2 = base64char(((Input[curPos] & 3) << 4) | (Input[curPos + 1] >> 4));
    char c3 = base64char(((Input[curPos + 1] & 0x0F) << 2) |
                         ((Input[curPos + 2] >> 6) & 3));
    char c4 = base64char(Input[curPos + 2] & 0x3F);
    curPos += 3;
    Output[dstPos++] = c1;
    Output[dstPos++] = c2;
    Output[dstPos++] = c3;
    Output[dstPos++] = c4;
    if (line >= 15) {
      line = 0;
      Output[dstPos++] = '\r';
      Output[dstPos++] = '\n';
    } else
      line++;
  }
  if (Length - curPos == 2) {
    char c1 = base64char(Input[curPos] >> 2);
    char c2 =
        base64char(((Input[curPos] & 0x03) << 4) | (Input[curPos + 1] >> 4));
    char c3 = base64b16(Input[curPos + 1] & 0x0F);
    Output[dstPos++] = c1;
    Output[dstPos++] = c2;
    Output[dstPos++] = c3;
    Output[dstPos++] = '=';
  } else if (Length - curPos == 1) {
    char c1 = base64char(Input[curPos] >> 2);
    char c2 = base64b8(Input[curPos] & 0x03);
    Output[dstPos++] = c1;
    Output[dstPos++] = c2;
    Output[dstPos++] = '=';
    Output[dstPos++] = '=';
  }
  Output[dstPos++] = '\r';
  Output[dstPos++] = '\n';
  return dstPos;
}


x86 assembly (clang, -O0):
<Base64Encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1172 <Base64Encode+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    1515 <Base64Encode+0x3e5>
cmpl   $0x0,-0x14(%rbp)
jne    1186 <Base64Encode+0x56>
xor    %eax,%eax
mov    %eax,-0x44(%rbp)
jmp    119d <Base64Encode+0x6d>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
shl    $0x2,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    $0x3f,%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
shl    $0x1,%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d0 <Base64Encode+0xa0>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1515 <Base64Encode+0x3e5>
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11e8 <Base64Encode+0xb8>
movl   $0xffffffff,-0x4(%rbp)
jmp    1515 <Base64Encode+0x3e5>
jmp    11ed <Base64Encode+0xbd>
jmp    11f2 <Base64Encode+0xc2>
mov    -0x14(%rbp),%eax
sub    -0x2c(%rbp),%eax
cmp    $0x3,%eax
jl     1361 <Base64Encode+0x231>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
sar    $0x2,%eax
movzbl %al,%edi
call   1030 <base64char@plt>
mov    %al,-0x35(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0x3,%eax
shl    $0x4,%eax
mov    -0x10(%rbp),%rcx
mov    -0x2c(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
sar    $0x4,%ecx
or     %ecx,%eax
movzbl %al,%edi
call   1030 <base64char@plt>
mov    %al,-0x36(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
and    $0xf,%eax
shl    $0x2,%eax
mov    -0x10(%rbp),%rcx
mov    -0x2c(%rbp),%edx
add    $0x2,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
sar    $0x6,%ecx
and    $0x3,%ecx
or     %ecx,%eax
movzbl %al,%edi
call   1030 <base64char@plt>
mov    %al,-0x37(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
and    $0x3f,%eax
movzbl %al,%edi
call   1030 <base64char@plt>
mov    %al,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x35(%rbp),%dl
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x30(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x36(%rbp),%dl
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x30(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x37(%rbp),%dl
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x30(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x38(%rbp),%dl
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x30(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
cmpl   $0xf,-0x34(%rbp)
jl     1353 <Base64Encode+0x223>
movl   $0x0,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x30(%rbp)
movslq %ecx,%rcx
movb   $0xd,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x30(%rbp)
movslq %ecx,%rcx
movb   $0xa,(%rax,%rcx,1)
jmp    135c <Base64Encode+0x22c>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11f2 <Base64Encode+0xc2>
mov    -0x14(%rbp),%eax
sub    -0x2c(%rbp),%eax
cmp    $0x2,%eax
jne    143f <Base64Encode+0x30f>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
sar    $0x2,%eax
movzbl %al,%edi
call   1030 <base64char@plt>
mov    %al,-0x39(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0x3,%eax
shl    $0x4,%eax
mov    -0x10(%rbp),%rcx
mov    -0x2c(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
sar    $0x4,%ecx
or     %ecx,%eax
movzbl %al,%edi
call   1030 <base64char@plt>
mov    %al,-0x3a(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
and    $0xf,%eax
movzbl %al,%edi
call   1050 <base64b16@plt>
mov    %al,-0x3b(%rbp)
mov    -0x39(%rbp),%dl
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x30(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x3a(%rbp),%dl
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x30(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x3b(%rbp),%dl
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x30(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x30(%rbp)
movslq %ecx,%rcx
movb   $0x3d,(%rax,%rcx,1)
jmp    14e3 <Base64Encode+0x3b3>
mov    -0x14(%rbp),%eax
sub    -0x2c(%rbp),%eax
cmp    $0x1,%eax
jne    14de <Base64Encode+0x3ae>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
sar    $0x2,%eax
movzbl %al,%edi
call   1030 <base64char@plt>
mov    %al,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0x3,%eax
movzbl %al,%edi
call   1040 <base64b8@plt>
mov    %al,-0x3d(%rbp)
mov    -0x3c(%rbp),%dl
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x30(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x3d(%rbp),%dl
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x30(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x30(%rbp)
movslq %ecx,%rcx
movb   $0x3d,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x30(%rbp)
movslq %ecx,%rcx
movb   $0x3d,(%rax,%rcx,1)
jmp    14e3 <Base64Encode+0x3b3>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x30(%rbp)
movslq %ecx,%rcx
movb   $0xd,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x30(%rbp)
movslq %ecx,%rcx
movb   $0xa,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Base64Encode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     134d <Base64Encode+0x21d>
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r15
test   %esi,%esi
je     117b <Base64Encode+0x4b>
lea    -0x1(%rbp),%edx
movslq %edx,%rdx
imul   $0x55555556,%rdx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
shr    $0x20,%rdx
add    %esi,%edx
lea    0x4(,%rdx,4),%edx
jmp    117d <Base64Encode+0x4d>
xor    %edx,%edx
lea    0x3f(%rdx),%esi
lea    0x7e(%rdx),%edi
test   %esi,%esi
cmovns %esi,%edi
sar    $0x6,%edi
lea    (%rdx,%rdi,2),%edx
test   %rbx,%rbx
je     1297 <Base64Encode+0x167>
cmp    %ecx,%edx
jg     134d <Base64Encode+0x21d>
xor    %r13d,%r13d
cmp    $0x3,%ebp
jl     129e <Base64Encode+0x16e>
mov    %rbx,0x10(%rsp)
xor    %r14d,%r14d
xor    %eax,%eax
mov    %rax,0x8(%rsp)
movl   $0x0,0x4(%rsp)
jmp    11ec <Base64Encode+0xbc>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rsi,0x8(%rsp)
add    $0x1,%eax
mov    %eax,0x4(%rsp)
add    $0xfffffffd,%ebp
add    $0x3,%r14
cmp    $0x2,%ebp
jle    12f2 <Base64Encode+0x1c2>
movzbl (%r15,%r14,1),%eax
shr    $0x2,%al
movzbl %al,%edi
call   1030 <base64char@plt>
mov    %eax,%r13d
movzbl (%r15,%r14,1),%eax
movzbl 0x1(%r15,%r14,1),%ecx
shr    $0x4,%cl
shl    $0x4,%al
or     %cl,%al
and    $0x3f,%al
movzbl %al,%edi
call   1030 <base64char@plt>
mov    %eax,%r12d
movzbl 0x1(%r15,%r14,1),%eax
movzbl 0x2(%r15,%r14,1),%ecx
shr    $0x6,%cl
shl    $0x2,%al
or     %cl,%al
and    $0x3f,%al
movzbl %al,%edi
call   1030 <base64char@plt>
mov    %eax,%ebx
movzbl 0x2(%r15,%r14,1),%edi
and    $0x3f,%edi
call   1030 <base64char@plt>
movslq 0x8(%rsp),%rcx
mov    0x10(%rsp),%rdx
mov    %r13b,(%rdx,%rcx,1)
mov    %r12b,0x1(%rdx,%rcx,1)
mov    %bl,0x2(%rdx,%rcx,1)
lea    0x4(%rcx),%rsi
mov    %al,0x3(%rdx,%rcx,1)
mov    0x4(%rsp),%eax
cmp    $0xf,%eax
jl     11d0 <Base64Encode+0xa0>
movb   $0xd,(%rdx,%rsi,1)
lea    0x6(%rcx),%eax
mov    %rax,0x8(%rsp)
movb   $0xa,0x5(%rcx,%rdx,1)
movl   $0x0,0x4(%rsp)
jmp    11dc <Base64Encode+0xac>
mov    %edx,%eax
jmp    134d <Base64Encode+0x21d>
xor    %r14d,%r14d
cmp    $0x1,%ebp
je     1301 <Base64Encode+0x1d1>
cmp    $0x2,%ebp
jne    1341 <Base64Encode+0x211>
mov    %r14d,%ebp
mov    (%r15,%rbp,1),%al
shr    $0x2,%al
movzbl %al,%edi
call   1030 <base64char@plt>
mov    %eax,%r14d
mov    (%r15,%rbp,1),%al
mov    0x1(%r15,%rbp,1),%cl
shr    $0x4,%cl
shl    $0x4,%al
or     %cl,%al
and    $0x3f,%al
movzbl %al,%edi
call   1030 <base64char@plt>
mov    %eax,%r12d
movzbl 0x1(%r15,%rbp,1),%edi
and    $0xf,%edi
call   1050 <base64b16@plt>
jmp    1328 <Base64Encode+0x1f8>
mov    0x10(%rsp),%rbx
mov    0x8(%rsp),%r13
cmp    $0x1,%ebp
jne    12a6 <Base64Encode+0x176>
mov    %r14d,%ebp
mov    (%r15,%rbp,1),%al
shr    $0x2,%al
movzbl %al,%edi
call   1030 <base64char@plt>
mov    %eax,%r14d
movzbl (%r15,%rbp,1),%edi
and    $0x3,%edi
call   1040 <base64b8@plt>
mov    %eax,%r12d
mov    $0x3d,%al
movslq %r13d,%rcx
mov    %r14b,(%rbx,%rcx,1)
mov    %r12b,0x1(%rbx,%rcx,1)
mov    %al,0x2(%rbx,%rcx,1)
lea    0x4(%rcx),%r13d
movb   $0x3d,0x3(%rbx,%rcx,1)
movslq %r13d,%rax
movw   $0xa0d,(%rbx,%rax,1)
add    $0x2,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @Base64Encode(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8
%15 = alloca i8
%16 = alloca i8
%17 = alloca i8
%18 = alloca i8
%19 = alloca i8
%20 = alloca i8
%21 = alloca i8
%22 = alloca i8
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
%23 = load i8*, i8** %6
%24 = icmp ne i8* %23, null
br i1 %24, label %26, label %25
25: ; preds = %4
store i32 -1, i32* %5
br label %289
26: ; preds = %4
%27 = load i32, i32* %7
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
br label %36
30: ; preds = %26
%31 = load i32, i32* %7
%32 = sub nsw i32 %31, 1
%33 = sdiv i32 %32, 3
%34 = add nsw i32 %33, 1
%35 = mul nsw i32 %34, 4
br label %36
36: ; preds = %30, %29
%37 = phi i32 [ 0, %29 ], [ %35, %30 ]
store i32 %37, i32* %10
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 63
%40 = sdiv i32 %39, 64
%41 = mul nsw i32 %40, 2
%42 = load i32, i32* %10
%43 = add nsw i32 %42, %41
store i32 %43, i32* %10
%44 = load i8*, i8** %8
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %48
46: ; preds = %36
%47 = load i32, i32* %10
store i32 %47, i32* %5
br label %289
48: ; preds = %36
%49 = load i32, i32* %9
%50 = load i32, i32* %10
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %53
52: ; preds = %48
store i32 -1, i32* %5
br label %289
53: ; preds = %48
br label %54
54: ; preds = %53
br label %55
55: ; preds = %162, %54
%56 = load i32, i32* %7
%57 = load i32, i32* %11
%58 = sub nsw i32 %56, %57
%59 = icmp sge i32 %58, 3
br i1 %59, label %60, label %163
60: ; preds = %55
%61 = load i8*, i8** %6
%62 = load i32, i32* %11
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = load i8, i8* %64
%66 = zext i8 %65 to i32
%67 = ashr i32 %66, 2
%68 = trunc i32 %67 to i8
%69 = call signext i8 @base64char(i8 zeroext %68)
store i8 %69, i8* %14
%70 = load i8*, i8** %6
%71 = load i32, i32* %11
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %70, i64 %72
%74 = load i8, i8* %73
%75 = zext i8 %74 to i32
%76 = and i32 %75, 3
%77 = shl i32 %76, 4
%78 = load i8*, i8** %6
%79 = load i32, i32* %11
%80 = add nsw i32 %79, 1
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8, i8* %78, i64 %81
%83 = load i8, i8* %82
%84 = zext i8 %83 to i32
%85 = ashr i32 %84, 4
%86 = or i32 %77, %85
%87 = trunc i32 %86 to i8
%88 = call signext i8 @base64char(i8 zeroext %87)
store i8 %88, i8* %15
%89 = load i8*, i8** %6
%90 = load i32, i32* %11
%91 = add nsw i32 %90, 1
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i8, i8* %89, i64 %92
%94 = load i8, i8* %93
%95 = zext i8 %94 to i32
%96 = and i32 %95, 15
%97 = shl i32 %96, 2
%98 = load i8*, i8** %6
%99 = load i32, i32* %11
%100 = add nsw i32 %99, 2
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i8, i8* %98, i64 %101
%103 = load i8, i8* %102
%104 = zext i8 %103 to i32
%105 = ashr i32 %104, 6
%106 = and i32 %105, 3
%107 = or i32 %97, %106
%108 = trunc i32 %107 to i8
%109 = call signext i8 @base64char(i8 zeroext %108)
store i8 %109, i8* %16
%110 = load i8*, i8** %6
%111 = load i32, i32* %11
%112 = add nsw i32 %111, 2
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds i8, i8* %110, i64 %113
%115 = load i8, i8* %114
%116 = zext i8 %115 to i32
%117 = and i32 %116, 63
%118 = trunc i32 %117 to i8
%119 = call signext i8 @base64char(i8 zeroext %118)
store i8 %119, i8* %17
%120 = load i32, i32* %11
%121 = add nsw i32 %120, 3
store i32 %121, i32* %11
%122 = load i8, i8* %14
%123 = load i8*, i8** %8
%124 = load i32, i32* %12
%125 = add nsw i32 %124, 1
store i32 %125, i32* %12
%126 = sext i32 %124 to i64
%127 = getelementptr inbounds i8, i8* %123, i64 %126
store i8 %122, i8* %127
%128 = load i8, i8* %15
%129 = load i8*, i8** %8
%130 = load i32, i32* %12
%131 = add nsw i32 %130, 1
store i32 %131, i32* %12
%132 = sext i32 %130 to i64
%133 = getelementptr inbounds i8, i8* %129, i64 %132
store i8 %128, i8* %133
%134 = load i8, i8* %16
%135 = load i8*, i8** %8
%136 = load i32, i32* %12
%137 = add nsw i32 %136, 1
store i32 %137, i32* %12
%138 = sext i32 %136 to i64
%139 = getelementptr inbounds i8, i8* %135, i64 %138
store i8 %134, i8* %139
%140 = load i8, i8* %17
%141 = load i8*, i8** %8
%142 = load i32, i32* %12
%143 = add nsw i32 %142, 1
store i32 %143, i32* %12
%144 = sext i32 %142 to i64
%145 = getelementptr inbounds i8, i8* %141, i64 %144
store i8 %140, i8* %145
%146 = load i32, i32* %13
%147 = icmp sge i32 %146, 15
br i1 %147, label %148, label %159
148: ; preds = %60
store i32 0, i32* %13
%149 = load i8*, i8** %8
%150 = load i32, i32* %12
%151 = add nsw i32 %150, 1
store i32 %151, i32* %12
%152 = sext i32 %150 to i64
%153 = getelementptr inbounds i8, i8* %149, i64 %152
store i8 13, i8* %153
%154 = load i8*, i8** %8
%155 = load i32, i32* %12
%156 = add nsw i32 %155, 1
store i32 %156, i32* %12
%157 = sext i32 %155 to i64
%158 = getelementptr inbounds i8, i8* %154, i64 %157
store i8 10, i8* %158
br label %162
159: ; preds = %60
%160 = load i32, i32* %13
%161 = add nsw i32 %160, 1
store i32 %161, i32* %13
br label %162
162: ; preds = %159, %148
br label %55
163: ; preds = %55
%164 = load i32, i32* %7
%165 = load i32, i32* %11
%166 = sub nsw i32 %164, %165
%167 = icmp eq i32 %166, 2
br i1 %167, label %168, label %230
168: ; preds = %163
%169 = load i8*, i8** %6
%170 = load i32, i32* %11
%171 = sext i32 %170 to i64
%172 = getelementptr inbounds i8, i8* %169, i64 %171
%173 = load i8, i8* %172
%174 = zext i8 %173 to i32
%175 = ashr i32 %174, 2
%176 = trunc i32 %175 to i8
%177 = call signext i8 @base64char(i8 zeroext %176)
store i8 %177, i8* %18
%178 = load i8*, i8** %6
%179 = load i32, i32* %11
%180 = sext i32 %179 to i64
%181 = getelementptr inbounds i8, i8* %178, i64 %180
%182 = load i8, i8* %181
%183 = zext i8 %182 to i32
%184 = and i32 %183, 3
%185 = shl i32 %184, 4
%186 = load i8*, i8** %6
%187 = load i32, i32* %11
%188 = add nsw i32 %187, 1
%189 = sext i32 %188 to i64
%190 = getelementptr inbounds i8, i8* %186, i64 %189
%191 = load i8, i8* %190
%192 = zext i8 %191 to i32
%193 = ashr i32 %192, 4
%194 = or i32 %185, %193
%195 = trunc i32 %194 to i8
%196 = call signext i8 @base64char(i8 zeroext %195)
store i8 %196, i8* %19
%197 = load i8*, i8** %6
%198 = load i32, i32* %11
%199 = add nsw i32 %198, 1
%200 = sext i32 %199 to i64
%201 = getelementptr inbounds i8, i8* %197, i64 %200
%202 = load i8, i8* %201
%203 = zext i8 %202 to i32
%204 = and i32 %203, 15
%205 = trunc i32 %204 to i8
%206 = call signext i8 @base64b16(i8 zeroext %205)
store i8 %206, i8* %20
%207 = load i8, i8* %18
%208 = load i8*, i8** %8
%209 = load i32, i32* %12
%210 = add nsw i32 %209, 1
store i32 %210, i32* %12
%211 = sext i32 %209 to i64
%212 = getelementptr inbounds i8, i8* %208, i64 %211
store i8 %207, i8* %212
%213 = load i8, i8* %19
%214 = load i8*, i8** %8
%215 = load i32, i32* %12
%216 = add nsw i32 %215, 1
store i32 %216, i32* %12
%217 = sext i32 %215 to i64
%218 = getelementptr inbounds i8, i8* %214, i64 %217
store i8 %213, i8* %218
%219 = load i8, i8* %20
%220 = load i8*, i8** %8
%221 = load i32, i32* %12
%222 = add nsw i32 %221, 1
store i32 %222, i32* %12
%223 = sext i32 %221 to i64
%224 = getelementptr inbounds i8, i8* %220, i64 %223
store i8 %219, i8* %224
%225 = load i8*, i8** %8
%226 = load i32, i32* %12
%227 = add nsw i32 %226, 1
store i32 %227, i32* %12
%228 = sext i32 %226 to i64
%229 = getelementptr inbounds i8, i8* %225, i64 %228
store i8 61, i8* %229
br label %277
230: ; preds = %163
%231 = load i32, i32* %7
%232 = load i32, i32* %11
%233 = sub nsw i32 %231, %232
%234 = icmp eq i32 %233, 1
br i1 %234, label %235, label %276
235: ; preds = %230
%236 = load i8*, i8** %6
%237 = load i32, i32* %11
%238 = sext i32 %237 to i64
%239 = getelementptr inbounds i8, i8* %236, i64 %238
%240 = load i8, i8* %239
%241 = zext i8 %240 to i32
%242 = ashr i32 %241, 2
%243 = trunc i32 %242 to i8
%244 = call signext i8 @base64char(i8 zeroext %243)
store i8 %244, i8* %21
%245 = load i8*, i8** %6
%246 = load i32, i32* %11
%247 = sext i32 %246 to i64
%248 = getelementptr inbounds i8, i8* %245, i64 %247
%249 = load i8, i8* %248
%250 = zext i8 %249 to i32
%251 = and i32 %250, 3
%252 = trunc i32 %251 to i8
%253 = call signext i8 @base64b8(i8 zeroext %252)
store i8 %253, i8* %22
%254 = load i8, i8* %21
%255 = load i8*, i8** %8
%256 = load i32, i32* %12
%257 = add nsw i32 %256, 1
store i32 %257, i32* %12
%258 = sext i32 %256 to i64
%259 = getelementptr inbounds i8, i8* %255, i64 %258
store i8 %254, i8* %259
%260 = load i8, i8* %22
%261 = load i8*, i8** %8
%262 = load i32, i32* %12
%263 = add nsw i32 %262, 1
store i32 %263, i32* %12
%264 = sext i32 %262 to i64
%265 = getelementptr inbounds i8, i8* %261, i64 %264
store i8 %260, i8* %265
%266 = load i8*, i8** %8
%267 = load i32, i32* %12
%268 = add nsw i32 %267, 1
store i32 %268, i32* %12
%269 = sext i32 %267 to i64
%270 = getelementptr inbounds i8, i8* %266, i64 %269
store i8 61, i8* %270
%271 = load i8*, i8** %8
%272 = load i32, i32* %12
%273 = add nsw i32 %272, 1
store i32 %273, i32* %12
%274 = sext i32 %272 to i64
%275 = getelementptr inbounds i8, i8* %271, i64 %274
store i8 61, i8* %275
br label %276
276: ; preds = %235, %230
br label %277
277: ; preds = %276, %168
%278 = load i8*, i8** %8
%279 = load i32, i32* %12
%280 = add nsw i32 %279, 1
store i32 %280, i32* %12
%281 = sext i32 %279 to i64
%282 = getelementptr inbounds i8, i8* %278, i64 %281
store i8 13, i8* %282
%283 = load i8*, i8** %8
%284 = load i32, i32* %12
%285 = add nsw i32 %284, 1
store i32 %285, i32* %12
%286 = sext i32 %284 to i64
%287 = getelementptr inbounds i8, i8* %283, i64 %286
store i8 10, i8* %287
%288 = load i32, i32* %12
store i32 %288, i32* %5
br label %289
289: ; preds = %277, %52, %46, %25
%290 = load i32, i32* %5
ret i32 %290
}

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