#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 /*<<< orphan*/ b64_decode_string(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ b64length(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ separate();
int /*<<< orphan*/ strlen(char *);
char *xcalloc(int /*<<< orphan*/, int);
int /*<<< orphan*/ xfree(char *);
int /*<<< orphan*/ xor_hexstrings(char *, char *, char *);
void s1c2() {
  separate();
  char *HEXSTRING1 = "1c0111001f010100061a024b53535009181c";
  char *HEXSTRING2 = "686974207468652062756C6C277320657965";
  puts("Challenge 2\nXOR these two hex strings & base64 decode it:");
  puts(HEXSTRING1);
  puts(HEXSTRING2);
  puts("\nXOR'd:");
  char *xor_b64 = xcalloc(b64length(HEXSTRING1), 1);
  xor_hexstrings(xor_b64, HEXSTRING1, HEXSTRING2);
  puts(xor_b64);
  puts("\nBase64 decoded:");
  char *xor_string = xcalloc(strlen(xor_b64), 1);
  b64_decode_string(xor_string, xor_b64, strlen(xor_b64));
  puts(xor_string);
  xfree(xor_b64);
  xfree(xor_string);
}


x86 assembly (clang, -O0):
<s1c2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1070 <separate@plt>
lea    0xe6a(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    0xe84(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe9e(%rip),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%rdi
call   1030 <puts@plt>
lea    0xeba(%rip),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%rdi
call   1060 <b64length@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   10a0 <xcalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1080 <xor_hexstrings@plt>
mov    -0x18(%rbp),%rdi
call   1030 <puts@plt>
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   10a0 <xcalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1090 <b64_decode_string@plt>
mov    -0x20(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1050 <xfree@plt>
mov    -0x20(%rbp),%rdi
call   1050 <xfree@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s1c2>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1070 <separate@plt>
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
lea    0xe61(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
lea    0xe77(%rip),%r15
mov    %r15,%rdi
call   1030 <puts@plt>
lea    0xec7(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1060 <b64length@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   10a0 <xcalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1080 <xor_hexstrings@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   10a0 <xcalloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1090 <b64_decode_string@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <xfree@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <xfree@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"1c0111001f010100061a024b53535009181c\00"
@.str.1 = [37 x i8] c"686974207468652062756C6C277320657965\00"
@.str.2 = [58 x i8] c"Challenge 2\0AXOR these two hex strings & base64 decode it:\00"
@.str.3 = [8 x i8] c"\0AXOR'd:\00"
@.str.4 = [17 x i8] c"\0ABase64 decoded:\00"
define void @s1c2() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = call i32 (...) @separate()
store i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8** %1
store i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8** %2
%6 = call i32 @puts(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0))
%7 = load i8*, i8** %1
%8 = call i32 @puts(i8* %7)
%9 = load i8*, i8** %2
%10 = call i32 @puts(i8* %9)
%11 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%12 = load i8*, i8** %1
%13 = call i32 @b64length(i8* %12)
%14 = call i8* @xcalloc(i32 %13, i32 1)
store i8* %14, i8** %3
%15 = load i8*, i8** %3
%16 = load i8*, i8** %1
%17 = load i8*, i8** %2
%18 = call i32 @xor_hexstrings(i8* %15, i8* %16, i8* %17)
%19 = load i8*, i8** %3
%20 = call i32 @puts(i8* %19)
%21 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%22 = load i8*, i8** %3
%23 = call i32 @strlen(i8* %22)
%24 = call i8* @xcalloc(i32 %23, i32 1)
store i8* %24, i8** %4
%25 = load i8*, i8** %4
%26 = load i8*, i8** %3
%27 = load i8*, i8** %3
%28 = call i32 @strlen(i8* %27)
%29 = call i32 @b64_decode_string(i8* %25, i8* %26, i32 %28)
%30 = load i8*, i8** %4
%31 = call i32 @puts(i8* %30)
%32 = load i8*, i8** %3
%33 = call i32 @xfree(i8* %32)
%34 = load i8*, i8** %4
%35 = call i32 @xfree(i8* %34)
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"1c0111001f010100061a024b53535009181c\00"
@.str.1 = [37 x i8] c"686974207468652062756C6C277320657965\00"
@.str.2 = [58 x i8] c"Challenge 2\0AXOR these two hex strings & base64 decode it:\00"
@.str.3 = [8 x i8] c"\0AXOR'd:\00"
@.str.4 = [17 x i8] c"\0ABase64 decoded:\00"
define void @s1c2() {
%1 = tail call i32 (...) @separate()
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%6 = tail call i32 @b64length(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%7 = tail call i8* @xcalloc(i32 %6, i32 1)
%8 = tail call i32 @xor_hexstrings(i8* %7, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) %7)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%11 = tail call i32 @strlen(i8* %7)
%12 = tail call i8* @xcalloc(i32 %11, i32 1)
%13 = tail call i32 @strlen(i8* %7)
%14 = tail call i32 @b64_decode_string(i8* %12, i8* %7, i32 %13)
%15 = tail call i32 @puts(i8* dereferenceable(1) %12)
%16 = tail call i32 @xfree(i8* %7)
%17 = tail call i32 @xfree(i8* %12)
ret void
}