#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*/ bits_to_hexchar(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ separate();
int strlen(char *);
char *xcalloc(int, int);
int /*<<< orphan*/ xfree(char *);
int /*<<< orphan*/ xor_bytes_to_string(char **, char *, int, char *, int);
void s1c5() {
  separate();
  printf("Challenge 5\nXOR this text with the 3 character key:\n");
  char *STRING4 = "Burning 'em, if you ain't quick and nimble\nI go crazy when "
                  "I hear a cymbal";
  puts(STRING4);
  printf("\n");
  char *STR_KEY5 = "ICE";
  printf("Key: %s\n", STR_KEY5);
  char *xor_string2 = xcalloc(strlen(STRING4) + 1, 1);
  char *xor_hexstring = xcalloc(strlen(STRING4) * 2 + 1, 1);
  xor_bytes_to_string(&xor_string2, STRING4, strlen(STRING4), STR_KEY5, 3);
  bits_to_hexchar(xor_hexstring, xor_string2);
  puts("Solution:");
  puts(xor_hexstring);
  xfree(xor_hexstring);
  xfree(xor_string2);
  separate();
}


x86 assembly (clang, -O0):
<s1c5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1070 <separate@plt>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe91(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <puts@plt>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xeba(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   10a0 <xcalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
shl    $0x1,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   10a0 <xcalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
lea    -0x18(%rbp),%rdi
mov    $0x3,%r8d
call   1080 <xor_bytes_to_string@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <bits_to_hexchar@plt>
lea    0xe38(%rip),%rdi
call   1030 <puts@plt>
mov    -0x20(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x20(%rbp),%rdi
call   1060 <xfree@plt>
mov    -0x18(%rbp),%rdi
call   1060 <xfree@plt>
mov    $0x0,%al
call   1070 <separate@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s1c5>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1080 <separate@plt>
lea    0xebb(%rip),%rdi
call   1040 <puts@plt>
lea    0xe4d(%rip),%r15
mov    %r15,%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe83(%rip),%rdi
lea    0xe78(%rip),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
mov    $0x1,%esi
call   10b0 <xcalloc@plt>
mov    %rax,0x8(%rsp)
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    (%rax,%rax,1),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   10b0 <xcalloc@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0x8(%rsp),%rdi
mov    %r15,%rsi
mov    %eax,%edx
mov    %r14,%rcx
mov    $0x3,%r8d
call   1090 <xor_bytes_to_string@plt>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   10a0 <bits_to_hexchar@plt>
lea    0xe12(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1070 <xfree@plt>
mov    0x8(%rsp),%rdi
call   1070 <xfree@plt>
xor    %eax,%eax
call   1080 <separate@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [53 x i8] c"Challenge 5\0AXOR this text with the 3 character key:\0A\00"
@.str.1 = [75 x i8] c"Burning 'em, if you ain't quick and nimble\0AI go crazy when I hear a cymbal\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [4 x i8] c"ICE\00"
@.str.4 = [9 x i8] c"Key: %s\0A\00"
@.str.5 = [10 x i8] c"Solution:\00"
define void @s1c5() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = call i32 (...) @separate()
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
store i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0), i8** %1
%7 = load i8*, i8** %1
%8 = call i32 @puts(i8* %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %2
%10 = load i8*, i8** %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %1
%13 = call i32 @strlen(i8* %12)
%14 = add nsw i32 %13, 1
%15 = call i8* @xcalloc(i32 %14, i32 1)
store i8* %15, i8** %3
%16 = load i8*, i8** %1
%17 = call i32 @strlen(i8* %16)
%18 = mul nsw i32 %17, 2
%19 = add nsw i32 %18, 1
%20 = call i8* @xcalloc(i32 %19, i32 1)
store i8* %20, i8** %4
%21 = load i8*, i8** %1
%22 = load i8*, i8** %1
%23 = call i32 @strlen(i8* %22)
%24 = load i8*, i8** %2
%25 = call i32 @xor_bytes_to_string(i8** %3, i8* %21, i32 %23, i8* %24, i32 3)
%26 = load i8*, i8** %4
%27 = load i8*, i8** %3
%28 = call i32 @bits_to_hexchar(i8* %26, i8* %27)
%29 = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%30 = load i8*, i8** %4
%31 = call i32 @puts(i8* %30)
%32 = load i8*, i8** %4
%33 = call i32 @xfree(i8* %32)
%34 = load i8*, i8** %3
%35 = call i32 @xfree(i8* %34)
%36 = call i32 (...) @separate()
ret void
}

LLVM IR (-O2):
@.str.1 = [75 x i8] c"Burning 'em, if you ain't quick and nimble\0AI go crazy when I hear a cymbal\00"
@.str.3 = [4 x i8] c"ICE\00"
@.str.4 = [9 x i8] c"Key: %s\0A\00"
@.str.5 = [10 x i8] c"Solution:\00"
@str = [52 x i8] c"Challenge 5\0AXOR this text with the 3 character key:\00"
define void @s1c5() {
%1 = alloca i8*
%2 = tail call i32 (...) @separate()
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @putchar(i32 10)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%7 = bitcast i8** %1 to i8*
%8 = tail call i32 @strlen(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0))
%9 = add nsw i32 %8, 1
%10 = tail call i8* @xcalloc(i32 %9, i32 1)
store i8* %10, i8** %1
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0))
%12 = shl nsw i32 %11, 1
%13 = or i32 %12, 1
%14 = tail call i8* @xcalloc(i32 %13, i32 1)
%15 = tail call i32 @strlen(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @xor_bytes_to_string(i8** %1, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0), i32 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%17 = load i8*, i8** %1
%18 = call i32 @bits_to_hexchar(i8* %14, i8* %17)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%20 = call i32 @puts(i8* dereferenceable(1) %14)
%21 = call i32 @xfree(i8* %14)
%22 = load i8*, i8** %1
%23 = call i32 @xfree(i8* %22)
%24 = call i32 (...) @separate()
ret void
}