#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 */
char *dec_to_base64(int);
int /*<<< orphan*/ free(char *);
int hex2int(char *);
char *malloc(int);
char *strcat(char *, char *);
int strlen(char *);
char *hex_to_base64(char *hex) {
  char new_str[1];
  int num;
  char *base64;
  char *full;
  int len = strlen(hex);
  int str_len = (len * 4 / 6) + 1;
  full = malloc(sizeof(char) * str_len);
  int i;
  while (hex[0] != '\0') {
    for (i = 0; i < 1; i++) {
      new_str[i] = hex[i];
    }
    hex = hex + 1;
    num = hex2int(new_str);
    base64 = dec_to_base64(num);
    full = strcat(full, base64);
    free(base64);
  }
  return full;
}


x86 assembly (clang, -O0):
<hex_to_base64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
shl    $0x2,%eax
mov    $0x6,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
movslq -0x28(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1224 <hex_to_base64+0xc4>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jge    11e1 <hex_to_base64+0x81>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x2c(%rbp),%rax
mov    %cl,-0x9(%rbp,%rax,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b6 <hex_to_base64+0x56>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
lea    -0x9(%rbp),%rdi
call   1050 <hex2int@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1060 <dec_to_base64@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    119f <hex_to_base64+0x3f>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_to_base64>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
call   1040 <strlen@plt>
shl    $0x2,%eax
cltq
imul   $0x2aaaaaab,%rax,%rax
mov    %rax,%rcx
shr    $0x20,%rcx
shr    $0x3f,%rax
lea    (%rcx,%rax,1),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    (%r12),%al
test   %al,%al
je     11e6 <hex_to_base64+0x86>
add    $0x1,%r12
lea    0x7(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %al,0x7(%rsp)
mov    %r15,%rdi
call   1050 <hex2int@plt>
mov    %eax,%edi
call   1060 <dec_to_base64@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
movzbl (%r12),%eax
add    $0x1,%r12
test   %al,%al
jne    11b0 <hex_to_base64+0x50>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @hex_to_base64(i8* %0) {
%2 = alloca i8*
%3 = alloca [1 x i8]
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %2
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = mul nsw i32 %12, 4
%14 = sdiv i32 %13, 6
%15 = add nsw i32 %14, 1
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = mul i64 1, %17
%19 = trunc i64 %18 to i32
%20 = call i8* @malloc(i32 %19)
store i8* %20, i8** %6
br label %21
21: ; preds = %43, %1
%22 = load i8*, i8** %2
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %55
27: ; preds = %21
store i32 0, i32* %9
br label %28
28: ; preds = %40, %27
%29 = load i32, i32* %9
%30 = icmp slt i32 %29, 1
br i1 %30, label %31, label %43
31: ; preds = %28
%32 = load i8*, i8** %2
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = load i32, i32* %9
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 %38
store i8 %36, i8* %39
br label %40
40: ; preds = %31
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
store i32 %42, i32* %9
br label %28
43: ; preds = %28
%44 = load i8*, i8** %2
%45 = getelementptr inbounds i8, i8* %44, i64 1
store i8* %45, i8** %2
%46 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%47 = call i32 @hex2int(i8* %46)
store i32 %47, i32* %4
%48 = load i32, i32* %4
%49 = call i8* @dec_to_base64(i32 %48)
store i8* %49, i8** %5
%50 = load i8*, i8** %6
%51 = load i8*, i8** %5
%52 = call i8* @strcat(i8* %50, i8* %51)
store i8* %52, i8** %6
%53 = load i8*, i8** %5
%54 = call i32 @free(i8* %53)
br label %21
55: ; preds = %21
%56 = load i8*, i8** %6
ret i8* %56
}

LLVM IR (-O2):
define i8* @hex_to_base64(i8* %0) {
%2 = alloca [1 x i8]
%3 = getelementptr inbounds [1 x i8], [1 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @strlen(i8* %0)
%5 = shl nsw i32 %4, 2
%6 = sdiv i32 %5, 6
%7 = add nsw i32 %6, 1
%8 = tail call i8* @malloc(i32 %7)
%9 = load i8, i8* %0
%10 = icmp eq i8 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %1, %11
%12 = phi i8 [ %19, %11 ], [ %9, %1 ]
%13 = phi i8* [ %14, %11 ], [ %0, %1 ]
store i8 %12, i8* %3
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = call i32 @hex2int(i8* %3)
%16 = call i8* @dec_to_base64(i32 %15)
%17 = call i8* @strcat(i8* dereferenceable(1) %8, i8* dereferenceable(1) %16)
%18 = call i32 @free(i8* %16)
%19 = load i8, i8* %14
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %11
21: ; preds = %11, %1
ret i8* %8
}