#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 */
unsigned long wby_base64_bufsize(unsigned long);
int wby_base64_encode(char *output, unsigned long output_size,
                      const unsigned char *input, unsigned long input_size) {
  unsigned long i = 0;
  int line_out = 0;
  static const char enc[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                            "abcdefghijklmnopqrstuvwxyz"
                            "0123456789+/=";
  if (output_size < wby_base64_bufsize(input_size))
    return 1;
  while (i < input_size) {
    unsigned int idx_0, idx_1, idx_2, idx_3;
    unsigned int i0;
    i0 = (unsigned int)(input[i]) << 16;
    i++;
    i0 |= (unsigned int)(i < input_size ? input[i] : 0) << 8;
    i++;
    i0 |= (i < input_size ? input[i] : 0);
    i++;
    idx_0 = (i0 & 0xfc0000) >> 18;
    i0 <<= 6;
    idx_1 = (i0 & 0xfc0000) >> 18;
    i0 <<= 6;
    idx_2 = (i0 & 0xfc0000) >> 18;
    i0 <<= 6;
    idx_3 = (i0 & 0xfc0000) >> 18;
    if (i - 1 > input_size)
      idx_2 = 64;
    if (i > input_size)
      idx_3 = 64;
    *output++ = enc[idx_0];
    *output++ = enc[idx_1];
    *output++ = enc[idx_2];
    *output++ = enc[idx_3];
    if (++line_out == 19) {
      *output++ = '\r';
      *output++ = '\n';
    }
  }
  *output = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<wby_base64_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <wby_base64_bufsize@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
cmp    %rcx,%rax
jae    1164 <wby_base64_encode+0x54>
movl   $0x1,-0x4(%rbp)
jmp    1364 <wby_base64_encode+0x254>
jmp    1169 <wby_base64_encode+0x59>
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1356 <wby_base64_encode+0x246>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
shl    $0x10,%eax
mov    %eax,-0x48(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11b7 <wby_base64_encode+0xa7>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x54(%rbp)
jmp    11c1 <wby_base64_encode+0xb1>
xor    %eax,%eax
mov    %eax,-0x54(%rbp)
jmp    11c1 <wby_base64_encode+0xb1>
mov    -0x54(%rbp),%eax
shl    $0x8,%eax
or     -0x48(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11fb <wby_base64_encode+0xeb>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x58(%rbp)
jmp    1205 <wby_base64_encode+0xf5>
xor    %eax,%eax
mov    %eax,-0x58(%rbp)
jmp    1205 <wby_base64_encode+0xf5>
mov    -0x58(%rbp),%eax
or     -0x48(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x48(%rbp),%eax
and    $0xfc0000,%eax
shr    $0x12,%eax
mov    %eax,-0x38(%rbp)
mov    -0x48(%rbp),%eax
shl    $0x6,%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
and    $0xfc0000,%eax
shr    $0x12,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x48(%rbp),%eax
shl    $0x6,%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
and    $0xfc0000,%eax
shr    $0x12,%eax
mov    %eax,-0x40(%rbp)
mov    -0x48(%rbp),%eax
shl    $0x6,%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
and    $0xfc0000,%eax
shr    $0x12,%eax
mov    %eax,-0x44(%rbp)
mov    -0x30(%rbp),%rax
sub    $0x1,%rax
cmp    -0x28(%rbp),%rax
jbe    1286 <wby_base64_encode+0x176>
movl   $0x40,-0x40(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    129b <wby_base64_encode+0x18b>
movl   $0x40,-0x44(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,%ecx
lea    0xd59(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x3c(%rbp),%eax
mov    %eax,%ecx
lea    0xd39(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x40(%rbp),%eax
mov    %eax,%ecx
lea    0xd19(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x44(%rbp),%eax
mov    %eax,%ecx
lea    0xcf9(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
cmp    $0x13,%eax
jne    1351 <wby_base64_encode+0x241>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0xd,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0xa,(%rax)
jmp    1169 <wby_base64_encode+0x59>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wby_base64_encode>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
mov    %rcx,%rdi
call   1030 <wby_base64_bufsize@plt>
mov    %rax,%rcx
mov    $0x1,%eax
cmp    %r12,%rcx
ja     1223 <wby_base64_encode+0x113>
test   %r14,%r14
je     121c <wby_base64_encode+0x10c>
mov    $0x12,%r9d
mov    $0x1,%ecx
mov    $0x40,%r8d
lea    0xea1(%rip),%r10
jmp    1188 <wby_base64_encode+0x78>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movw   $0xa0d,0x4(%r13)
add    $0x6,%r13
add    $0x3,%rcx
cmp    %r14,%r11
jae    121c <wby_base64_encode+0x10c>
movzbl -0x1(%r15,%rcx,1),%eax
mov    %rax,%rdx
shl    $0x10,%rdx
xor    %edi,%edi
mov    $0x0,%esi
cmp    %r14,%rcx
jae    11a6 <wby_base64_encode+0x96>
movzbl (%r15,%rcx,1),%esi
mov    %esi,%esi
shl    $0x8,%rsi
or     %rsi,%rdx
lea    0x1(%rcx),%rbx
cmp    %r14,%rbx
jae    11be <wby_base64_encode+0xae>
movzbl 0x1(%r15,%rcx,1),%edi
or     %edi,%esi
lea    0x2(%rcx),%r11
shr    $0x2,%rax
shr    $0xc,%edx
and    $0x3f,%edx
shr    $0x6,%esi
and    $0x3f,%esi
and    $0x3f,%edi
cmp    %r14,%rbx
cmova  %r8,%rsi
cmp    %r14,%r11
movzbl (%rax,%r10,1),%eax
mov    %al,0x0(%r13)
movzbl (%rdx,%r10,1),%eax
mov    %al,0x1(%r13)
movzbl (%rsi,%r10,1),%eax
cmova  %r8,%rdi
mov    %al,0x2(%r13)
movzbl (%rdi,%r10,1),%eax
mov    %al,0x3(%r13)
sub    $0x1,%r9d
jb     1170 <wby_base64_encode+0x60>
add    $0x4,%r13
jmp    117b <wby_base64_encode+0x6b>
movb   $0x0,0x0(%r13)
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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