#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 uint32_t;

/* Variables and functions */
unsigned char *asciihex2hexbytes(int *, unsigned char *);
char *b64dec(int *, unsigned char *);
unsigned char *b64enc(int *, unsigned char *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(unsigned char *);
int main(int argc, char *argv[]) {
  unsigned char input[] = "49276d206b696c6c696e6720796f757220627261696e206c696b"
                          "65206120706f69736f6e6f7573206d757368726f6f6d";
  unsigned char *hexbytes = NULL;
  unsigned char *plainstring = NULL;
  uint32_t inlen = strlen(input);
  printf("inlen raw: %d\n", inlen);
  hexbytes = asciihex2hexbytes(&inlen, input);
  printf("inlen hexbytes: %d\n", inlen);
  plainstring = b64enc(&inlen, hexbytes);
  printf("Raw Encoding: %s\n", plainstring);
  hexbytes = asciihex2hexbytes(&inlen, plainstring);
  printf("Ascii Encoding: %s\n", hexbytes);
  printf("Re-Decoding: %s\n", b64dec(&inlen, hexbytes));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x61,%edx
call   1060 <memcpy@plt>
movq   $0x0,-0x88(%rbp)
movq   $0x0,-0x90(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x94(%rbp)
mov    -0x94(%rbp),%esi
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rsi
lea    -0x94(%rbp),%rdi
call   1080 <asciihex2hexbytes@plt>
mov    %rax,-0x88(%rbp)
mov    -0x94(%rbp),%esi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x88(%rbp),%rsi
lea    -0x94(%rbp),%rdi
call   1070 <b64enc@plt>
mov    %rax,-0x90(%rbp)
mov    -0x90(%rbp),%rsi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x90(%rbp),%rsi
lea    -0x94(%rbp),%rdi
call   1080 <asciihex2hexbytes@plt>
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rsi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x88(%rbp),%rsi
lea    -0x94(%rbp),%rdi
call   1030 <b64dec@plt>
mov    %rax,%rsi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
movaps 0xeed(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xed1(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xeb5(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe99(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe7d(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe61(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x70(%rsp)
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,0xc(%rsp)
lea    0xea0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc(%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <asciihex2hexbytes@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%esi
lea    0xe88(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <b64enc@plt>
mov    %rax,%rbx
lea    0xe80(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <asciihex2hexbytes@plt>
mov    %rax,%rbx
lea    0xe73(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <b64dec@plt>
lea    0xe6b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.input = [97 x i8] c"49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d\00"
@.str = [15 x i8] c"inlen raw: %d\0A\00"
@.str.1 = [20 x i8] c"inlen hexbytes: %d\0A\00"
@.str.2 = [18 x i8] c"Raw Encoding: %s\0A\00"
@.str.3 = [20 x i8] c"Ascii Encoding: %s\0A\00"
@.str.4 = [17 x i8] c"Re-Decoding: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [97 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [97 x i8]* %6 to i8*
store i8* null, i8** %7
store i8* null, i8** %8
%11 = getelementptr inbounds [97 x i8], [97 x i8]* %6, i64 0, i64 0
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [97 x i8], [97 x i8]* %6, i64 0, i64 0
%16 = call i8* @asciihex2hexbytes(i32* %9, i8* %15)
store i8* %16, i8** %7
%17 = load i32, i32* %9
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = load i8*, i8** %7
%20 = call i8* @b64enc(i32* %9, i8* %19)
store i8* %20, i8** %8
%21 = load i8*, i8** %8
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %8
%24 = call i8* @asciihex2hexbytes(i32* %9, i8* %23)
store i8* %24, i8** %7
%25 = load i8*, i8** %7
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %7
%28 = call i8* @b64dec(i32* %9, i8* %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %28)
ret i32 0
}

LLVM IR (-O2):
@__const.main.input = [97 x i8] c"49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d\00"
@.str = [15 x i8] c"inlen raw: %d\0A\00"
@.str.1 = [20 x i8] c"inlen hexbytes: %d\0A\00"
@.str.2 = [18 x i8] c"Raw Encoding: %s\0A\00"
@.str.3 = [20 x i8] c"Ascii Encoding: %s\0A\00"
@.str.4 = [17 x i8] c"Re-Decoding: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [97 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [97 x i8], [97 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = call i32 @strlen(i8* %5)
store i32 %7, i32* %4
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = call i8* @asciihex2hexbytes(i32* %4, i8* %5)
%10 = load i32, i32* %4
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = call i8* @b64enc(i32* %4, i8* %9)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = call i8* @asciihex2hexbytes(i32* %4, i8* %12)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %14)
%16 = call i8* @b64dec(i32* %4, i8* %14)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %16)
ret i32 0
}