#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 int Base64_EncodeLength(unsigned int);
int /*<<< orphan*/ encodeblock(unsigned char *, unsigned char *);
int Base64_Encode(const char *data, unsigned int length, char *base64,
                  unsigned int base64len) {
  unsigned char *r = (unsigned char *)data;
  unsigned char *w = (unsigned char *)base64;
  if (!r || !w || base64len < Base64_EncodeLength(length)) {
    return 0;
  }
  for (;;) {
    if (length > 3) {
      encodeblock(r, w);
      r += 3;
      w += 4;
      length -= 3;
    } else {
      encodeblock(r, w);
      switch (length) {
      case 1:
        w[2] = '=';
      case 2:
        w[3] = '=';
      }
      w += 4;
      break;
    }
  }
  *w = 0;
  return 1;
}


x86 assembly (clang, -O0):
<Base64_Encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1177 <Base64_Encode+0x57>
cmpq   $0x0,-0x38(%rbp)
je     1177 <Base64_Encode+0x57>
mov    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <Base64_EncodeLength@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cmp    %ecx,%eax
jae    1183 <Base64_Encode+0x63>
movl   $0x0,-0x4(%rbp)
jmp    122b <Base64_Encode+0x10b>
jmp    1188 <Base64_Encode+0x68>
cmpl   $0x3,-0x14(%rbp)
jbe    11c5 <Base64_Encode+0xa5>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <encodeblock@plt>
mov    -0x30(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
mov    %eax,-0x14(%rbp)
jmp    1218 <Base64_Encode+0xf8>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <encodeblock@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x40(%rbp)
sub    $0x1,%eax
je     11f7 <Base64_Encode+0xd7>
jmp    11e6 <Base64_Encode+0xc6>
mov    -0x40(%rbp),%eax
sub    $0x2,%eax
je     11ff <Base64_Encode+0xdf>
jmp    1207 <Base64_Encode+0xe7>
mov    -0x38(%rbp),%rax
movb   $0x3d,0x2(%rax)
mov    -0x38(%rbp),%rax
movb   $0x3d,0x3(%rax)
mov    -0x38(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x38(%rbp)
jmp    121d <Base64_Encode+0xfd>
jmp    1188 <Base64_Encode+0x68>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Base64_Encode>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %r15d,%r15d
test   %rdi,%rdi
je     11a5 <Base64_Encode+0x85>
mov    %rdx,%r14
test   %rdx,%rdx
je     11a5 <Base64_Encode+0x85>
mov    %ecx,%r12d
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,%edi
call   1030 <Base64_EncodeLength@plt>
cmp    %r12d,%eax
ja     11a5 <Base64_Encode+0x85>
cmp    $0x4,%ebp
jb     117b <Base64_Encode+0x5b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <encodeblock@plt>
add    $0x3,%rbx
add    $0x4,%r14
add    $0xfffffffd,%ebp
cmp    $0x3,%ebp
ja     1160 <Base64_Encode+0x40>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <encodeblock@plt>
cmp    $0x2,%ebp
je     1195 <Base64_Encode+0x75>
cmp    $0x1,%ebp
jne    119a <Base64_Encode+0x7a>
movb   $0x3d,0x2(%r14)
movb   $0x3d,0x3(%r14)
movb   $0x0,0x4(%r14)
mov    $0x1,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @Base64_Encode(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 i8*
%11 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%12 = load i8*, i8** %6
store i8* %12, i8** %10
%13 = load i8*, i8** %8
store i8* %13, i8** %11
%14 = load i8*, i8** %10
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %24
16: ; preds = %4
%17 = load i8*, i8** %11
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i32, i32* %9
%21 = load i32, i32* %7
%22 = call i32 @Base64_EncodeLength(i32 %21)
%23 = icmp ult i32 %20, %22
br i1 %23, label %24, label %25
24: ; preds = %19, %16, %4
store i32 0, i32* %5
br label %56
25: ; preds = %19
br label %26
26: ; preds = %53, %25
%27 = load i32, i32* %7
%28 = icmp ugt i32 %27, 3
br i1 %28, label %29, label %39
29: ; preds = %26
%30 = load i8*, i8** %10
%31 = load i8*, i8** %11
%32 = call i32 @encodeblock(i8* %30, i8* %31)
%33 = load i8*, i8** %10
%34 = getelementptr inbounds i8, i8* %33, i64 3
store i8* %34, i8** %10
%35 = load i8*, i8** %11
%36 = getelementptr inbounds i8, i8* %35, i64 4
store i8* %36, i8** %11
%37 = load i32, i32* %7
%38 = sub i32 %37, 3
store i32 %38, i32* %7
br label %53
39: ; preds = %26
%40 = load i8*, i8** %10
%41 = load i8*, i8** %11
%42 = call i32 @encodeblock(i8* %40, i8* %41)
%43 = load i32, i32* %7
switch i32 %43, label %50 [
i32 1, label %44
i32 2, label %47
]
44: ; preds = %39
%45 = load i8*, i8** %11
%46 = getelementptr inbounds i8, i8* %45, i64 2
store i8 61, i8* %46
br label %47
47: ; preds = %39, %44
%48 = load i8*, i8** %11
%49 = getelementptr inbounds i8, i8* %48, i64 3
store i8 61, i8* %49
br label %50
50: ; preds = %47, %39
%51 = load i8*, i8** %11
%52 = getelementptr inbounds i8, i8* %51, i64 4
store i8* %52, i8** %11
br label %54
53: ; preds = %29
br label %26
54: ; preds = %50
%55 = load i8*, i8** %11
store i8 0, i8* %55
store i32 1, i32* %5
br label %56
56: ; preds = %54, %24
%57 = load i32, i32* %5
ret i32 %57
}

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