#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 encodeblock(unsigned char *, char *, int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int Base64Encode(unsigned char *input, char *output, int inputlen, int oplen,
                 int debug) {
  int rc = 0, del = 0;
  int index = 0, ipindex = 0, iplen = 0;
  unsigned char encoderinput[3 + 1] = "";
  iplen = inputlen;
  while (ipindex < iplen) {
    for (index = 0; index < 3; index++) {
      if (ipindex < iplen) {
        encoderinput[index] = input[ipindex];
      } else {
        encoderinput[index] = 0;
      }
      ipindex++;
    }
    del = ipindex - iplen;
    if (debug) {
      printf("iplen = %i ,", iplen);
      printf("ipindex = %i ,", ipindex);
      printf("delta = %i ,", del);
      printf("%02x ", encoderinput[0]);
      printf("%02x ", encoderinput[1]);
      printf("%02x ", encoderinput[2]);
      printf(" => ");
    }
    rc = encodeblock(encoderinput, output, oplen, del, debug);
  }
  return rc;
}


x86 assembly (clang, -O0):
<Base64Encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
lea    -0x34(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    128d <Base64Encode+0x15d>
movl   $0x0,-0x28(%rbp)
cmpl   $0x3,-0x28(%rbp)
jge    11e4 <Base64Encode+0xb4>
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    11c4 <Base64Encode+0x94>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x28(%rbp),%rax
mov    %cl,-0x34(%rbp,%rax,1)
jmp    11cd <Base64Encode+0x9d>
movslq -0x28(%rbp),%rax
movb   $0x0,-0x34(%rbp,%rax,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1196 <Base64Encode+0x66>
mov    -0x2c(%rbp),%eax
sub    -0x30(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     126e <Base64Encode+0x13e>
mov    -0x30(%rbp),%esi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%esi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzbl -0x34(%rbp),%esi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzbl -0x33(%rbp),%esi
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzbl -0x32(%rbp),%esi
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x34(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1050 <encodeblock@plt>
mov    %eax,-0x20(%rbp)
jmp    1183 <Base64Encode+0x53>
mov    -0x20(%rbp),%eax
add    $0x40,%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    %ecx,0x4(%rsp)
mov    %rsi,0x10(%rsp)
movl   $0x0,(%rsp)
test   %edx,%edx
jle    1272 <Base64Encode+0x152>
mov    %r8d,%ebp
mov    %edx,%r12d
mov    %rdi,%rbx
mov    %edx,%r15d
xor    %r14d,%r14d
mov    %rdi,0x8(%rsp)
jmp    1180 <Base64Encode+0x60>
nopl   0x0(%rax)
mov    %rsp,%rdi
mov    0x10(%rsp),%rsi
mov    0x4(%rsp),%edx
mov    %r13d,%ecx
mov    %ebp,%r8d
call   1040 <encodeblock@plt>
cmp    %r12d,%r14d
jge    1274 <Base64Encode+0x154>
movslq %r14d,%r14
cmp    %r15,%r14
jge    1190 <Base64Encode+0x70>
movzbl (%rbx,%r14,1),%eax
jmp    1192 <Base64Encode+0x72>
nop
xor    %eax,%eax
mov    %al,(%rsp)
lea    0x1(%r14),%rax
cmp    %r15,%rax
jge    11b0 <Base64Encode+0x90>
movzbl (%rbx,%rax,1),%eax
jmp    11b2 <Base64Encode+0x92>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
mov    %al,0x1(%rsp)
lea    0x2(%r14),%rax
cmp    %r15,%rax
jge    11d0 <Base64Encode+0xb0>
movzbl (%rbx,%rax,1),%eax
jmp    11d2 <Base64Encode+0xb2>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
add    $0x3,%r14
mov    %r14d,%r13d
sub    %r12d,%r13d
mov    %al,0x2(%rsp)
test   %ebp,%ebp
je     1160 <Base64Encode+0x40>
lea    0xe11(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe0d(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe0b(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl (%rsp),%esi
mov    %r15,%rbx
mov    %r12d,%r15d
lea    0xdfd(%rip),%r12
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl 0x1(%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl 0x2(%rsp),%esi
mov    %r12,%rdi
mov    %r15d,%r12d
mov    %rbx,%r15
mov    0x8(%rsp),%rbx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xdc9(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1160 <Base64Encode+0x40>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"iplen = %i ,\00"
@.str.1 = [15 x i8] c"ipindex = %i ,\00"
@.str.2 = [13 x i8] c"delta = %i ,\00"
@.str.3 = [6 x i8] c"%02x \00"
@.str.4 = [5 x i8] c" => \00"
define i32 @Base64Encode(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca [4 x i8]
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
%17 = bitcast [4 x i8]* %16 to i8*
%18 = load i32, i32* %8
store i32 %18, i32* %15
br label %19
19: ; preds = %76, %5
%20 = load i32, i32* %14
%21 = load i32, i32* %15
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %83
23: ; preds = %19
store i32 0, i32* %13
br label %24
24: ; preds = %47, %23
%25 = load i32, i32* %13
%26 = icmp slt i32 %25, 3
br i1 %26, label %27, label %50
27: ; preds = %24
%28 = load i32, i32* %14
%29 = load i32, i32* %15
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %40
31: ; preds = %27
%32 = load i8*, i8** %6
%33 = load i32, i32* %14
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = load i32, i32* %13
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 %38
store i8 %36, i8* %39
br label %44
40: ; preds = %27
%41 = load i32, i32* %13
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 %42
store i8 0, i8* %43
br label %44
44: ; preds = %40, %31
%45 = load i32, i32* %14
%46 = add nsw i32 %45, 1
store i32 %46, i32* %14
br label %47
47: ; preds = %44
%48 = load i32, i32* %13
%49 = add nsw i32 %48, 1
store i32 %49, i32* %13
br label %24
50: ; preds = %24
%51 = load i32, i32* %14
%52 = load i32, i32* %15
%53 = sub nsw i32 %51, %52
store i32 %53, i32* %12
%54 = load i32, i32* %10
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %76
56: ; preds = %50
%57 = load i32, i32* %15
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %57)
%59 = load i32, i32* %14
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %59)
%61 = load i32, i32* %12
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %61)
%63 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 0
%64 = load i8, i8* %63
%65 = zext i8 %64 to i32
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %65)
%67 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 1
%68 = load i8, i8* %67
%69 = zext i8 %68 to i32
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %69)
%71 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 2
%72 = load i8, i8* %71
%73 = zext i8 %72 to i32
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %73)
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %76
76: ; preds = %56, %50
%77 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 0
%78 = load i8*, i8** %7
%79 = load i32, i32* %9
%80 = load i32, i32* %12
%81 = load i32, i32* %10
%82 = call i32 @encodeblock(i8* %77, i8* %78, i32 %79, i32 %80, i32 %81)
store i32 %82, i32* %11
br label %19
83: ; preds = %19
%84 = load i32, i32* %11
ret i32 %84
}

LLVM IR (-O2):
@.str = [13 x i8] c"iplen = %i ,\00"
@.str.1 = [15 x i8] c"ipindex = %i ,\00"
@.str.2 = [13 x i8] c"delta = %i ,\00"
@.str.3 = [6 x i8] c"%02x \00"
@.str.4 = [5 x i8] c" => \00"
define i32 @Base64Encode(i8* nocapture %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to [4 x i8]*
%8 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%9 = icmp sgt i32 %2, 0
br i1 %9, label %10, label %60
10: ; preds = %5
%11 = icmp eq i32 %4, 0
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 1
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 2
%14 = zext i32 %2 to i64
%15 = bitcast i32* %6 to i8*
br label %16
16: ; preds = %10, %57
%17 = phi i64 [ 0, %10 ], [ %40, %57 ]
%18 = shl i64 %17, 32
%19 = ashr exact i64 %18, 32
%20 = icmp slt i64 %19, %14
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = getelementptr inbounds i8, i8* %0, i64 %19
%23 = load i8, i8* %22
br label %24
24: ; preds = %16, %21
%25 = phi i8 [ %23, %21 ], [ 0, %16 ]
store i8 %25, i8* %15
%26 = add nsw i64 %19, 1
%27 = icmp slt i64 %26, %14
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = getelementptr inbounds i8, i8* %0, i64 %26
%30 = load i8, i8* %29
br label %31
31: ; preds = %24, %28
%32 = phi i8 [ %30, %28 ], [ 0, %24 ]
store i8 %32, i8* %12
%33 = add nsw i64 %19, 2
%34 = icmp slt i64 %33, %14
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = getelementptr inbounds i8, i8* %0, i64 %33
%37 = load i8, i8* %36
br label %38
38: ; preds = %31, %35
%39 = phi i8 [ %37, %35 ], [ 0, %31 ]
store i8 %39, i8* %13
%40 = add nsw i64 %19, 3
%41 = trunc i64 %40 to i32
%42 = sub nsw i32 %41, %2
br i1 %11, label %57, label %43
43: ; preds = %38
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %2)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %41)
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%47 = load i8, i8* %8
%48 = zext i8 %47 to i32
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %48)
%50 = load i8, i8* %12
%51 = zext i8 %50 to i32
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %51)
%53 = load i8, i8* %13
%54 = zext i8 %53 to i32
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %54)
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %57
57: ; preds = %43, %38
%58 = call i32 @encodeblock(i8* %8, i8* %1, i32 %3, i32 %42, i32 %4)
%59 = icmp slt i32 %41, %2
br i1 %59, label %16, label %60
60: ; preds = %57, %5
%61 = phi i32 [ 0, %5 ], [ %58, %57 ]
ret i32 %61
}