#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 */
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_FLAGS_BASE64_NO_NL;
int /*<<< orphan*/ BIO_f_base64();
int /*<<< orphan*/ BIO_flush(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_read(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ BIO_s_mem();
int /*<<< orphan*/ BIO_set_flags(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ BIO_write(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
char *_hex_to_base64(char *input_string) {
  BIO *bio, *b64;
  char output_string[1024];
  bio = BIO_new(BIO_s_mem());
  b64 = BIO_new(BIO_f_base64());
  BIO_push(b64, bio);
  BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
  BIO_write(b64, input_string, strlen(input_string));
  BIO_flush(b64);
  BIO_read(bio, output_string, strlen(input_string));
  BIO_free(bio);
  BIO_free(b64);
  return (char *)output_string;
}


x86 assembly (clang, -O0):
<_hex_to_base64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   10b0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1060 <BIO_f_base64@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <BIO_push@plt>
mov    -0x18(%rbp),%rdi
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
call   1070 <BIO_set_flags@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x440(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x440(%rbp),%rdi
mov    -0x438(%rbp),%rsi
mov    %eax,%edx
call   10a0 <BIO_write@plt>
mov    -0x18(%rbp),%rdi
call   10c0 <BIO_flush@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x430(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x428(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x430(%rbp),%rdi
mov    -0x428(%rbp),%rsi
mov    %eax,%edx
call   1040 <BIO_read@plt>
mov    -0x10(%rbp),%rdi
call   1090 <BIO_free@plt>
mov    -0x18(%rbp),%rdi
call   1090 <BIO_free@plt>
lea    -0x420(%rbp),%rax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_hex_to_base64>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r15
xor    %eax,%eax
call   10b0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1060 <BIO_f_base64@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <BIO_push@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <BIO_set_flags@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   10a0 <BIO_write@plt>
mov    %rbx,%rdi
call   10c0 <BIO_flush@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rsp,%r15
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <BIO_read@plt>
mov    %r14,%rdi
call   1090 <BIO_free@plt>
mov    %rbx,%rdi
call   1090 <BIO_free@plt>
mov    %r15,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i8* @_hex_to_base64(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [1024 x i8]
store i8* %0, i8** %2
%6 = call i32 (...) @BIO_s_mem()
%7 = call i32* @BIO_new(i32 %6)
store i32* %7, i32** %3
%8 = call i32 (...) @BIO_f_base64()
%9 = call i32* @BIO_new(i32 %8)
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = load i32*, i32** %3
%12 = call i32 @BIO_push(i32* %10, i32* %11)
%13 = load i32*, i32** %4
%14 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%15 = call i32 @BIO_set_flags(i32* %13, i32 %14)
%16 = load i32*, i32** %4
%17 = load i8*, i8** %2
%18 = load i8*, i8** %2
%19 = call i32 @strlen(i8* %18)
%20 = call i32 @BIO_write(i32* %16, i8* %17, i32 %19)
%21 = load i32*, i32** %4
%22 = call i32 @BIO_flush(i32* %21)
%23 = load i32*, i32** %3
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%25 = load i8*, i8** %2
%26 = call i32 @strlen(i8* %25)
%27 = call i32 @BIO_read(i32* %23, i8* %24, i32 %26)
%28 = load i32*, i32** %3
%29 = call i32 @BIO_free(i32* %28)
%30 = load i32*, i32** %4
%31 = call i32 @BIO_free(i32* %30)
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
ret i8* %32
}

LLVM IR (-O2):
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i8* @_hex_to_base64(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (...) @BIO_s_mem()
%5 = tail call i32* @BIO_new(i32 %4)
%6 = tail call i32 (...) @BIO_f_base64()
%7 = tail call i32* @BIO_new(i32 %6)
%8 = tail call i32 @BIO_push(i32* %7, i32* %5)
%9 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%10 = tail call i32 @BIO_set_flags(i32* %7, i32 %9)
%11 = tail call i32 @strlen(i8* %0)
%12 = tail call i32 @BIO_write(i32* %7, i8* %0, i32 %11)
%13 = tail call i32 @BIO_flush(i32* %7)
%14 = tail call i32 @strlen(i8* %0)
%15 = call i32 @BIO_read(i32* %5, i8* %3, i32 %14)
%16 = call i32 @BIO_free(i32* %5)
%17 = call i32 @BIO_free(i32* %7)
ret i8* %3
}