#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 */
int /*<<< orphan*/ base64_encode(unsigned char *, unsigned char const *);
int /*<<< orphan*/ memcpy(char *, char const *, unsigned int);
void base64(char *target, const char *source, unsigned int source_size) {
  while (source_size >= 3) {
    base64_encode((unsigned char *)target, (const unsigned char *)source);
    source += 3;
    target += 4;
    source_size -= 3;
  }
  if (source_size > 0) {
    char temp[3] = {0};
    memcpy(temp, source, source_size);
    base64_encode((unsigned char *)target, (const unsigned char *)temp);
    target[2] = (source_size == 1) ? '=' : target[2];
    target[3] = '=';
    target += 4;
  }
  *target = '\0';
}


x86 assembly (clang, -O0):
<base64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jb     1180 <base64+0x50>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <base64_encode@plt>
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
mov    %eax,-0x14(%rbp)
jmp    1143 <base64+0x13>
cmpl   $0x0,-0x14(%rbp)
jbe    11f9 <base64+0xc9>
lea    -0x17(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1030 <memset@plt>
lea    -0x17(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rdi
lea    -0x17(%rbp),%rsi
call   1050 <base64_encode@plt>
cmpl   $0x1,-0x14(%rbp)
jne    11ce <base64+0x9e>
mov    $0x3d,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d9 <base64+0xa9>
mov    -0x8(%rbp),%rax
movsbl 0x2(%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x8(%rbp),%rax
movb   $0x3d,0x3(%rax)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
cmp    $0x3,%edx
jb     115b <base64+0x3b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <base64_encode@plt>
add    $0x3,%rbx
add    $0x4,%r14
add    $0xfffffffd,%ebp
cmp    $0x2,%ebp
ja     1140 <base64+0x20>
test   %ebp,%ebp
je     11a0 <base64+0x80>
movb   $0x0,0x6(%rsp)
movw   $0x0,0x4(%rsp)
lea    0x4(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <memcpy@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <base64_encode@plt>
mov    $0x3d,%al
cmp    $0x1,%ebp
je     1193 <base64+0x73>
mov    0x2(%r14),%al
mov    %al,0x2(%r14)
movb   $0x3d,0x3(%r14)
add    $0x4,%r14
movb   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @base64(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [3 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
br label %8
8: ; preds = %11, %3
%9 = load i32, i32* %6
%10 = icmp uge i32 %9, 3
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = load i8*, i8** %4
%13 = load i8*, i8** %5
%14 = call i32 @base64_encode(i8* %12, i8* %13)
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 3
store i8* %16, i8** %5
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i64 4
store i8* %18, i8** %4
%19 = load i32, i32* %6
%20 = sub i32 %19, 3
store i32 %20, i32* %6
br label %8
21: ; preds = %8
%22 = load i32, i32* %6
%23 = icmp ugt i32 %22, 0
br i1 %23, label %24, label %50
24: ; preds = %21
%25 = bitcast [3 x i8]* %7 to i8*
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%27 = load i8*, i8** %5
%28 = load i32, i32* %6
%29 = call i32 @memcpy(i8* %26, i8* %27, i32 %28)
%30 = load i8*, i8** %4
%31 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%32 = call i32 @base64_encode(i8* %30, i8* %31)
%33 = load i32, i32* %6
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %36
35: ; preds = %24
br label %41
36: ; preds = %24
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i64 2
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
br label %41
41: ; preds = %36, %35
%42 = phi i32 [ 61, %35 ], [ %40, %36 ]
%43 = trunc i32 %42 to i8
%44 = load i8*, i8** %4
%45 = getelementptr inbounds i8, i8* %44, i64 2
store i8 %43, i8* %45
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i64 3
store i8 61, i8* %47
%48 = load i8*, i8** %4
%49 = getelementptr inbounds i8, i8* %48, i64 4
store i8* %49, i8** %4
br label %50
50: ; preds = %41, %21
%51 = load i8*, i8** %4
store i8 0, i8* %51
ret void
}

LLVM IR (-O2):
define void @base64(i8* %0, i8* %1, i32 %2) {
%4 = alloca [3 x i8]
%5 = icmp ugt i32 %2, 2
br i1 %5, label %6, label %15
6: ; preds = %3, %6
%7 = phi i32 [ %13, %6 ], [ %2, %3 ]
%8 = phi i8* [ %11, %6 ], [ %1, %3 ]
%9 = phi i8* [ %12, %6 ], [ %0, %3 ]
%10 = tail call i32 @base64_encode(i8* %9, i8* %8)
%11 = getelementptr inbounds i8, i8* %8, i64 3
%12 = getelementptr inbounds i8, i8* %9, i64 4
%13 = add i32 %7, -3
%14 = icmp ugt i32 %13, 2
br i1 %14, label %6, label %15
15: ; preds = %6, %3
%16 = phi i8* [ %0, %3 ], [ %12, %6 ]
%17 = phi i8* [ %1, %3 ], [ %11, %6 ]
%18 = phi i32 [ %2, %3 ], [ %13, %6 ]
%19 = icmp eq i32 %18, 0
br i1 %19, label %33, label %20
20: ; preds = %15
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%22 = call i32 @memcpy(i8* %21, i8* %17, i32 %18)
%23 = call i32 @base64_encode(i8* %16, i8* %21)
%24 = icmp eq i32 %18, 1
br i1 %24, label %28, label %25
25: ; preds = %20
%26 = getelementptr inbounds i8, i8* %16, i64 2
%27 = load i8, i8* %26
br label %28
28: ; preds = %20, %25
%29 = phi i8 [ %27, %25 ], [ 61, %20 ]
%30 = getelementptr inbounds i8, i8* %16, i64 2
store i8 %29, i8* %30
%31 = getelementptr inbounds i8, i8* %16, i64 3
store i8 61, i8* %31
%32 = getelementptr inbounds i8, i8* %16, i64 4
br label %33
33: ; preds = %28, %15
%34 = phi i8* [ %32, %28 ], [ %16, %15 ]
store i8 0, i8* %34
ret void
}