#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_block(unsigned char *, unsigned char const *,
                                       int);
void base64_encode_binary(char *out, const unsigned char *in, size_t len) {
  int size;
  size_t i = 0;
  while (i < len) {
    size = (len - i < 4) ? len - i : 4;
    base64_encode_block((unsigned char *)out, in, size);
    out += 4;
    in += 3;
    i += 3;
  }
  *out = '\0';
}


x86 assembly (clang, -O0):
<base64_encode_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11ab <base64_encode_binary+0x9b>
mov    -0x18(%rbp),%rax
sub    -0x28(%rbp),%rax
cmp    $0x4,%rax
jae    115d <base64_encode_binary+0x4d>
mov    -0x18(%rbp),%rax
sub    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    116b <base64_encode_binary+0x5b>
mov    $0x4,%eax
mov    %rax,-0x30(%rbp)
jmp    116b <base64_encode_binary+0x5b>
mov    -0x30(%rbp),%rax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <base64_encode_block@plt>
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x28(%rbp)
jmp    112c <base64_encode_binary+0x1c>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64_encode_binary>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r12
test   %rdx,%rdx
je     1159 <base64_encode_binary+0x49>
mov    %rdx,%r14
mov    %rsi,%r15
xor    %r13d,%r13d
mov    %rdx,%rbx
nopl   (%rax)
lea    (%r15,%r13,1),%rsi
cmp    $0x4,%rbx
mov    $0x4,%edx
cmovb  %ebx,%edx
mov    %r12,%rdi
call   1030 <base64_encode_block@plt>
add    $0x4,%r12
add    $0x3,%r13
add    $0xfffffffffffffffd,%rbx
cmp    %r14,%r13
jb     1130 <base64_encode_binary+0x20>
movb   $0x0,(%r12)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @base64_encode_binary(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i64 0, i64* %8
br label %9
9: ; preds = %23, %3
%10 = load i64, i64* %8
%11 = load i64, i64* %6
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %36
13: ; preds = %9
%14 = load i64, i64* %6
%15 = load i64, i64* %8
%16 = sub i64 %14, %15
%17 = icmp ult i64 %16, 4
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i64, i64* %6
%20 = load i64, i64* %8
%21 = sub i64 %19, %20
br label %23
22: ; preds = %13
br label %23
23: ; preds = %22, %18
%24 = phi i64 [ %21, %18 ], [ 4, %22 ]
%25 = trunc i64 %24 to i32
store i32 %25, i32* %7
%26 = load i8*, i8** %4
%27 = load i8*, i8** %5
%28 = load i32, i32* %7
%29 = call i32 @base64_encode_block(i8* %26, i8* %27, i32 %28)
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i64 4
store i8* %31, i8** %4
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i64 3
store i8* %33, i8** %5
%34 = load i64, i64* %8
%35 = add i64 %34, 3
store i64 %35, i64* %8
br label %9
36: ; preds = %9
%37 = load i8*, i8** %4
store i8 0, i8* %37
ret void
}

LLVM IR (-O2):
define void @base64_encode_binary(i8* %0, i8* %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %18, label %5
5: ; preds = %3, %5
%6 = phi i64 [ %16, %5 ], [ 0, %3 ]
%7 = phi i8* [ %14, %5 ], [ %0, %3 ]
%8 = phi i8* [ %15, %5 ], [ %1, %3 ]
%9 = sub i64 %2, %6
%10 = icmp ult i64 %9, 4
%11 = select i1 %10, i64 %9, i64 4
%12 = trunc i64 %11 to i32
%13 = tail call i32 @base64_encode_block(i8* %7, i8* %8, i32 %12)
%14 = getelementptr inbounds i8, i8* %7, i64 4
%15 = getelementptr inbounds i8, i8* %8, i64 3
%16 = add i64 %6, 3
%17 = icmp ult i64 %16, %2
br i1 %17, label %5, label %18
18: ; preds = %5, %3
%19 = phi i8* [ %0, %3 ], [ %14, %5 ]
store i8 0, i8* %19
ret void
}