#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 asciiToHex(char const);
char binToBase64(char);
int /*<<< orphan*/ reverseString(char *);
size_t strlen(char const *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ threeHexTo2Base64(char *, char *);
void hexArrayToBase64Array(char *dest, const char *src) {
  char threeHex[3];
  char val = 0;
  char tmp;
  size_t srcLen = strlen(src);
  while (srcLen > 2) {
    threeHex[0] = *(src + srcLen - 1);
    threeHex[1] = *(src + srcLen - 2);
    threeHex[2] = *(src + srcLen - 3);
    threeHexTo2Base64(dest, threeHex);
    srcLen -= 3;
  }
  if (srcLen == 1) {
    val = (asciiToHex(*(src)) & 0x0f);
    tmp = binToBase64(val);
    strncat(dest, &tmp, 1);
  } else if (srcLen == 2) {
    threeHex[0] = *(src + srcLen - 1);
    threeHex[1] = *(src + srcLen - 2);
    threeHex[2] = '0';
    threeHexTo2Base64(dest, threeHex);
  }
  reverseString(dest);
}


x86 assembly (clang, -O0):
<hexArrayToBase64Array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x2,-0x20(%rbp)
jbe    11d7 <hexArrayToBase64Array+0x77>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x1(%rax,%rcx,1),%al
mov    %al,-0x13(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x2(%rax,%rcx,1),%al
mov    %al,-0x12(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x3(%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x13(%rbp),%rsi
call   1030 <threeHexTo2Base64@plt>
mov    -0x20(%rbp),%rax
sub    $0x3,%rax
mov    %rax,-0x20(%rbp)
jmp    1181 <hexArrayToBase64Array+0x21>
cmpq   $0x1,-0x20(%rbp)
jne    1217 <hexArrayToBase64Array+0xb7>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1070 <asciiToHex@plt>
and    $0xf,%eax
mov    %al,-0x14(%rbp)
movsbl -0x14(%rbp),%edi
call   1060 <binToBase64@plt>
mov    %al,-0x15(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1050 <strncat@plt>
jmp    1256 <hexArrayToBase64Array+0xf6>
cmpq   $0x2,-0x20(%rbp)
jne    1251 <hexArrayToBase64Array+0xf1>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x1(%rax,%rcx,1),%al
mov    %al,-0x13(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x2(%rax,%rcx,1),%al
mov    %al,-0x12(%rbp)
movb   $0x30,-0x11(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x13(%rbp),%rsi
call   1030 <threeHexTo2Base64@plt>
jmp    1256 <hexArrayToBase64Array+0xf6>
mov    -0x8(%rbp),%rdi
call   1080 <reverseString@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexArrayToBase64Array>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
cmp    $0x3,%rax
jb     11c3 <hexArrayToBase64Array+0x63>
lea    0x4(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl -0x1(%r15,%rbx,1),%eax
mov    %al,0x4(%rsp)
movzbl -0x2(%r15,%rbx,1),%eax
mov    %al,0x5(%rsp)
movzbl -0x3(%r15,%rbx,1),%eax
mov    %al,0x6(%rsp)
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <threeHexTo2Base64@plt>
add    $0xfffffffffffffffd,%rbx
cmp    $0x2,%rbx
ja     1190 <hexArrayToBase64Array+0x30>
cmp    $0x2,%rbx
je     11fa <hexArrayToBase64Array+0x9a>
cmp    $0x1,%rbx
jne    121b <hexArrayToBase64Array+0xbb>
movsbl (%r15),%edi
call   1070 <asciiToHex@plt>
and    $0xf,%eax
mov    %eax,%edi
call   1060 <binToBase64@plt>
mov    %al,0x7(%rsp)
lea    0x7(%rsp),%rsi
mov    %r14,%rdi
mov    $0x1,%edx
call   1050 <strncat@plt>
jmp    121b <hexArrayToBase64Array+0xbb>
mov    0x1(%r15),%al
mov    %al,0x4(%rsp)
mov    (%r15),%al
mov    %al,0x5(%rsp)
movb   $0x30,0x6(%rsp)
lea    0x4(%rsp),%rsi
mov    %r14,%rdi
call   1030 <threeHexTo2Base64@plt>
mov    %r14,%rdi
call   1080 <reverseString@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @hexArrayToBase64Array(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [3 x i8]
%6 = alloca i8
%7 = alloca i8
%8 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8 0, i8* %6
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %8
br label %11
11: ; preds = %14, %2
%12 = load i64, i64* %8
%13 = icmp ugt i64 %12, 2
br i1 %13, label %14, label %38
14: ; preds = %11
%15 = load i8*, i8** %4
%16 = load i64, i64* %8
%17 = getelementptr inbounds i8, i8* %15, i64 %16
%18 = getelementptr inbounds i8, i8* %17, i64 -1
%19 = load i8, i8* %18
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
store i8 %19, i8* %20
%21 = load i8*, i8** %4
%22 = load i64, i64* %8
%23 = getelementptr inbounds i8, i8* %21, i64 %22
%24 = getelementptr inbounds i8, i8* %23, i64 -2
%25 = load i8, i8* %24
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
store i8 %25, i8* %26
%27 = load i8*, i8** %4
%28 = load i64, i64* %8
%29 = getelementptr inbounds i8, i8* %27, i64 %28
%30 = getelementptr inbounds i8, i8* %29, i64 -3
%31 = load i8, i8* %30
%32 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 2
store i8 %31, i8* %32
%33 = load i8*, i8** %3
%34 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%35 = call i32 @threeHexTo2Base64(i8* %33, i8* %34)
%36 = load i64, i64* %8
%37 = sub i64 %36, 3
store i64 %37, i64* %8
br label %11
38: ; preds = %11
%39 = load i64, i64* %8
%40 = icmp eq i64 %39, 1
br i1 %40, label %41, label %51
41: ; preds = %38
%42 = load i8*, i8** %4
%43 = load i8, i8* %42
%44 = call i32 @asciiToHex(i8 signext %43)
%45 = and i32 %44, 15
%46 = trunc i32 %45 to i8
store i8 %46, i8* %6
%47 = load i8, i8* %6
%48 = call signext i8 @binToBase64(i8 signext %47)
store i8 %48, i8* %7
%49 = load i8*, i8** %3
%50 = call i32 @strncat(i8* %49, i8* %7, i32 1)
br label %72
51: ; preds = %38
%52 = load i64, i64* %8
%53 = icmp eq i64 %52, 2
br i1 %53, label %54, label %71
54: ; preds = %51
%55 = load i8*, i8** %4
%56 = load i64, i64* %8
%57 = getelementptr inbounds i8, i8* %55, i64 %56
%58 = getelementptr inbounds i8, i8* %57, i64 -1
%59 = load i8, i8* %58
%60 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
store i8 %59, i8* %60
%61 = load i8*, i8** %4
%62 = load i64, i64* %8
%63 = getelementptr inbounds i8, i8* %61, i64 %62
%64 = getelementptr inbounds i8, i8* %63, i64 -2
%65 = load i8, i8* %64
%66 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
store i8 %65, i8* %66
%67 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 2
store i8 48, i8* %67
%68 = load i8*, i8** %3
%69 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%70 = call i32 @threeHexTo2Base64(i8* %68, i8* %69)
br label %71
71: ; preds = %54, %51
br label %72
72: ; preds = %71, %41
%73 = load i8*, i8** %3
%74 = call i32 @reverseString(i8* %73)
ret void
}

LLVM IR (-O2):
define void @hexArrayToBase64Array(i8* %0, i8* nocapture %1) {
%3 = alloca [3 x i8]
%4 = alloca i8
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = icmp ugt i64 %6, 2
br i1 %7, label %8, label %23
8: ; preds = %2
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
br label %11
11: ; preds = %8, %11
%12 = phi i64 [ %6, %8 ], [ %21, %11 ]
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = getelementptr inbounds i8, i8* %13, i64 -1
%15 = load i8, i8* %14
store i8 %15, i8* %5
%16 = getelementptr inbounds i8, i8* %13, i64 -2
%17 = load i8, i8* %16
store i8 %17, i8* %9
%18 = getelementptr inbounds i8, i8* %13, i64 -3
%19 = load i8, i8* %18
store i8 %19, i8* %10
%20 = call i32 @threeHexTo2Base64(i8* %0, i8* %5)
%21 = add i64 %12, -3
%22 = icmp ugt i64 %21, 2
br i1 %22, label %11, label %23
23: ; preds = %11, %2
%24 = phi i64 [ %6, %2 ], [ %21, %11 ]
switch i64 %24, label %39 [
i64 1, label %25
i64 2, label %32
]
25: ; preds = %23
%26 = load i8, i8* %1
%27 = call i32 @asciiToHex(i8 signext %26)
%28 = trunc i32 %27 to i8
%29 = and i8 %28, 15
%30 = call signext i8 @binToBase64(i8 signext %29)
store i8 %30, i8* %4
%31 = call i32 @strncat(i8* %0, i8* %4, i32 1)
br label %39
32: ; preds = %23
%33 = getelementptr inbounds i8, i8* %1, i64 1
%34 = load i8, i8* %33
store i8 %34, i8* %5
%35 = load i8, i8* %1
%36 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
store i8 %35, i8* %36
%37 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
store i8 48, i8* %37
%38 = call i32 @threeHexTo2Base64(i8* %0, i8* %5)
br label %39
39: ; preds = %23, %32, %25
%40 = call i32 @reverseString(i8* %0)
ret void
}