#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 *fixed_xor(char *, char *);
char *hex_to_base64(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ single_byte_xor(char *);
int main() {
  printf("1. Hex to Base64\n");
  char *test = "49276d206b696c6c696e6720796f757220627261696e206c696b65206120706"
               "f69736f6e6f7573206d757368726f6f6d";
  printf("%s\n", test);
  char *res = hex_to_base64(test);
  printf("%s\n\n", res);
  printf("2. Fixed XOR\n");
  char *buffer1 = "1c0111001f010100061a024b53535009181c";
  char *buffer2 = "686974207468652062756c6c277320657965";
  printf("buffer 1: %s\nbuffer 2: %s\n", buffer1, buffer2);
  printf("%s\n", fixed_xor(buffer1, buffer2));
  printf("3. Single Byte XOR Cipher\n");
  char *hexString =
      "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736";
  single_byte_xor(hexString);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeae(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xf74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <hex_to_base64@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xee1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xed8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xed8(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xef2(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xf04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <fixed_xor@plt>
mov    %rax,%rsi
lea    0xefd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xef3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf00(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <single_byte_xor@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xfb5(%rip),%rdi
call   1030 <puts@plt>
lea    0xe99(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1070 <hex_to_base64@plt>
lea    0xee3(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf92(%rip),%rdi
call   1030 <puts@plt>
lea    0xf15(%rip),%rdi
lea    0xec4(%rip),%rbx
lea    0xee2(%rip),%r14
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <fixed_xor@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
lea    0xf5e(%rip),%rdi
call   1030 <puts@plt>
lea    0xeef(%rip),%rdi
call   1040 <single_byte_xor@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c"1. Hex to Base64\0A\00"
@.str.1 = [97 x i8] c"49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [5 x i8] c"%s\0A\0A\00"
@.str.4 = [14 x i8] c"2. Fixed XOR\0A\00"
@.str.5 = [37 x i8] c"1c0111001f010100061a024b53535009181c\00"
@.str.6 = [37 x i8] c"686974207468652062756c6c277320657965\00"
@.str.7 = [27 x i8] c"buffer 1: %s\0Abuffer 2: %s\0A\00"
@.str.8 = [27 x i8] c"3. Single Byte XOR Cipher\0A\00"
@.str.9 = [69 x i8] c"1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str.1, i64 0, i64 0), i8** %2
%8 = load i8*, i8** %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%10 = load i8*, i8** %2
%11 = call i8* @hex_to_base64(i8* %10)
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
store i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0), i8** %5
%15 = load i8*, i8** %4
%16 = load i8*, i8** %5
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %15, i8* %16)
%18 = load i8*, i8** %4
%19 = load i8*, i8** %5
%20 = call i8* @fixed_xor(i8* %18, i8* %19)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
store i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.9, i64 0, i64 0), i8** %6
%23 = load i8*, i8** %6
%24 = call i32 @single_byte_xor(i8* %23)
ret i32 1
}

LLVM IR (-O2):
@.str.1 = [97 x i8] c"49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d\00"
@.str.3 = [5 x i8] c"%s\0A\0A\00"
@.str.5 = [37 x i8] c"1c0111001f010100061a024b53535009181c\00"
@.str.6 = [37 x i8] c"686974207468652062756c6c277320657965\00"
@.str.7 = [27 x i8] c"buffer 1: %s\0Abuffer 2: %s\0A\00"
@.str.9 = [69 x i8] c"1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736\00"
@str = [17 x i8] c"1. Hex to Base64\00"
@str.10 = [13 x i8] c"2. Fixed XOR\00"
@str.11 = [26 x i8] c"3. Single Byte XOR Cipher\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([97 x i8], [97 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i8* @hex_to_base64(i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.10, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0))
%7 = tail call i8* @fixed_xor(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) %7)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.11, i64 0, i64 0))
%10 = tail call i32 @single_byte_xor(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.9, i64 0, i64 0))
ret i32 1
}