#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 base64length(int);
int counthex(char *);
int /*<<< orphan*/ hex2base64(unsigned char *, int, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ printhex(unsigned char *, int);
int /*<<< orphan*/ str2hex(char *, unsigned char *);
void challenge1() {
  printf("challenge 1:\n");
  char in[] = "49276d206b696c6c696e6720796f757220627261696e206c"
              "696b65206120706f69736f6e6f7573206d757368726f6f6d";
  int size = counthex(in);
  unsigned char hexarray[size];
  str2hex(in, hexarray);
  printhex(hexarray, size);
  char base64[base64length(size)];
  hex2base64(hexarray, size, base64);
  printf("base64 = '%s'\n", base64);
}


x86 assembly (clang, -O0):
<challenge1>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movaps 0xef0(%rip),%xmm0
movaps %xmm0,-0x20(%rbp)
movaps 0xed5(%rip),%xmm0
movaps %xmm0,-0x30(%rbp)
movaps 0xeba(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
movaps 0xe9f(%rip),%xmm0
movaps %xmm0,-0x50(%rbp)
movaps 0xe84(%rip),%xmm0
movaps %xmm0,-0x60(%rbp)
movaps 0xe69(%rip),%xmm0
movaps %xmm0,-0x70(%rbp)
movb   $0x0,-0x10(%rbp)
lea    -0x70(%rbp),%rdi
mov    %rdi,-0xa8(%rbp)
call   1040 <counthex@plt>
mov    -0xa8(%rbp),%rdi
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x80(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0xa0(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x88(%rbp)
call   1060 <str2hex@plt>
mov    -0xa0(%rbp),%rdi
mov    -0x74(%rbp),%esi
call   1070 <printhex@plt>
mov    -0x74(%rbp),%edi
call   1050 <base64length@plt>
mov    -0xa0(%rbp),%rdi
mov    %eax,%eax
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x98(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x90(%rbp)
mov    -0x74(%rbp),%esi
call   1080 <hex2base64@plt>
mov    -0x98(%rbp),%rsi
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x80(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<challenge1>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xee8(%rip),%rdi
call   1030 <puts@plt>
movaps 0xebc(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
movaps 0xea1(%rip),%xmm0
movaps %xmm0,-0x50(%rbp)
movaps 0xe86(%rip),%xmm0
movaps %xmm0,-0x60(%rbp)
movaps 0xe6b(%rip),%xmm0
movaps %xmm0,-0x70(%rbp)
movaps 0xe50(%rip),%xmm0
movaps %xmm0,-0x80(%rbp)
movaps 0xe35(%rip),%xmm0
movaps %xmm0,-0x90(%rbp)
movb   $0x0,-0x30(%rbp)
lea    -0x90(%rbp),%r15
mov    %r15,%rdi
call   1050 <counthex@plt>
mov    %eax,%r14d
mov    %rsp,%r13
mov    %eax,%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <str2hex@plt>
mov    %r12,%rdi
mov    %r14d,%esi
call   1080 <printhex@plt>
mov    %r14d,%edi
call   1060 <base64length@plt>
mov    %eax,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r12,%rdi
mov    %r14d,%esi
mov    %rbx,%rdx
call   1090 <hex2base64@plt>
lea    0xe1d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"challenge 1:\0A\00"
@__const.challenge1.in = [97 x i8] c"49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d\00"
@.str.1 = [15 x i8] c"base64 = '%s'\0A\00"
define void @challenge1() {
%1 = alloca [97 x i8]
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%7 = bitcast [97 x i8]* %1 to i8*
%8 = getelementptr inbounds [97 x i8], [97 x i8]* %1, i64 0, i64 0
%9 = call i32 @counthex(i8* %8)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %3
%13 = alloca i8, i64 %11
store i64 %11, i64* %4
%14 = getelementptr inbounds [97 x i8], [97 x i8]* %1, i64 0, i64 0
%15 = call i32 @str2hex(i8* %14, i8* %13)
%16 = load i32, i32* %2
%17 = call i32 @printhex(i8* %13, i32 %16)
%18 = load i32, i32* %2
%19 = call i32 @base64length(i32 %18)
%20 = zext i32 %19 to i64
%21 = alloca i8, i64 %20
store i64 %20, i64* %5
%22 = load i32, i32* %2
%23 = call i32 @hex2base64(i8* %13, i32 %22, i8* %21)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%25 = load i8*, i8** %3
ret void
}

LLVM IR (-O2):
@__const.challenge1.in = [97 x i8] c"49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d\00"
@.str.1 = [15 x i8] c"base64 = '%s'\0A\00"
@str = [13 x i8] c"challenge 1:\00"
define void @challenge1() {
%1 = alloca [97 x i8]
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%3 = getelementptr inbounds [97 x i8], [97 x i8]* %1, i64 0, i64 0
%4 = call i32 @counthex(i8* %3)
%5 = zext i32 %4 to i64
%6 = call i8* @llvm.stacksave()
%7 = alloca i8, i64 %5
%8 = call i32 @str2hex(i8* %3, i8* %7)
%9 = call i32 @printhex(i8* %7, i32 %4)
%10 = call i32 @base64length(i32 %4)
%11 = zext i32 %10 to i64
%12 = alloca i8, i64 %11
%13 = call i32 @hex2base64(i8* %7, i32 %4, i8* %12)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %12)
ret void
}