#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*/ destroy_scores();
int /*<<< orphan*/ get_best();
int /*<<< orphan*/ get_score(char *, long, char *, int, float,
                             int /*<<< orphan*/);
long hexstr_to_string(char **, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ separate();
int /*<<< orphan*/ xfree(char *);
char *xmalloc(int);
int /*<<< orphan*/ xor_bytes_to_string(char **, char *, long, char *, int);
void s1c3() {
  separate();
  char HEXSTRING3[] =
      "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736\0";
  char SINGLECHAR[] = "A\0";
  char *STRING3 = xmalloc(1 * sizeof(char));
  int i, c;
  printf("Challenge 3\nfind the single byte to decrypt:\n");
  puts(HEXSTRING3);
  long str_length = hexstr_to_string(&STRING3, HEXSTRING3);
  char *NEWSTRING = xmalloc(1 * sizeof(char));
  for (i = 0; i < 256; i++) {
    SINGLECHAR[0] = (char)i;
    xor_bytes_to_string(&NEWSTRING, STRING3, str_length, SINGLECHAR, 1);
    get_score(NEWSTRING, str_length, SINGLECHAR, -1000, 2.0f, 0);
  }
  get_best();
  destroy_scores();
  xfree(NEWSTRING);
  xfree(STRING3);
}


x86 assembly (clang, -O0):
<s1c3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    $0x0,%al
call   1090 <separate@plt>
lea    -0x50(%rbp),%rdi
lea    0xe43(%rip),%rsi
mov    $0x46,%edx
call   10a0 <memcpy@plt>
mov    0xe78(%rip),%ax
mov    %ax,-0x53(%rbp)
mov    0xe70(%rip),%al
mov    %al,-0x51(%rbp)
mov    $0x1,%edi
call   1080 <xmalloc@plt>
mov    %rax,-0x60(%rbp)
lea    0xe59(%rip),%rdi
call   1050 <printf@plt>
lea    -0x50(%rbp),%rdi
call   1040 <puts@plt>
lea    -0x50(%rbp),%rsi
lea    -0x60(%rbp),%rdi
call   10d0 <hexstr_to_string@plt>
mov    %rax,-0x70(%rbp)
mov    $0x1,%edi
call   1080 <xmalloc@plt>
mov    %rax,-0x78(%rbp)
movl   $0x0,-0x64(%rbp)
cmpl   $0x100,-0x64(%rbp)
jge    1291 <s1c3+0xe1>
mov    -0x64(%rbp),%eax
mov    %al,-0x53(%rbp)
mov    -0x60(%rbp),%rsi
mov    -0x70(%rbp),%rdx
lea    -0x53(%rbp),%rcx
lea    -0x78(%rbp),%rdi
mov    $0x1,%r8d
call   10b0 <xor_bytes_to_string@plt>
mov    -0x78(%rbp),%rdi
mov    -0x70(%rbp),%rsi
lea    -0x53(%rbp),%rdx
mov    $0xfffffc18,%ecx
movss  0xd85(%rip),%xmm0
xor    %r8d,%r8d
call   1060 <get_score@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1234 <s1c3+0x84>
mov    $0x0,%al
call   1030 <get_best@plt>
mov    $0x0,%al
call   10c0 <destroy_scores@plt>
mov    -0x78(%rbp),%rdi
call   1070 <xfree@plt>
mov    -0x60(%rbp),%rdi
call   1070 <xfree@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s1c3>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
xor    %ebp,%ebp
xor    %eax,%eax
call   1080 <separate@plt>
movaps 0xe96(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe7a(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe5e(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe42(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movabs $0x363337336233,%rax
mov    %rax,0x5e(%rsp)
movb   $0x0,0xe(%rsp)
movw   $0x41,0xc(%rsp)
mov    $0x1,%edi
call   1070 <xmalloc@plt>
mov    %rax,0x18(%rsp)
lea    0xe55(%rip),%rdi
call   1040 <puts@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0x18(%rsp),%rdi
mov    %rbx,%rsi
call   10b0 <hexstr_to_string@plt>
mov    %rax,%rbx
mov    $0x1,%edi
call   1070 <xmalloc@plt>
mov    %rax,0x10(%rsp)
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r15
nop
mov    %bpl,0xc(%rsp)
mov    0x18(%rsp),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    $0x1,%r8d
call   1090 <xor_bytes_to_string@plt>
mov    0x10(%rsp),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    $0xfffffc18,%ecx
movss  0xd8a(%rip),%xmm0
xor    %r8d,%r8d
call   1050 <get_score@plt>
add    $0x1,%ebp
cmp    $0x100,%ebp
jne    1240 <s1c3+0xb0>
xor    %eax,%eax
call   1030 <get_best@plt>
xor    %eax,%eax
call   10a0 <destroy_scores@plt>
mov    0x10(%rsp),%rdi
call   1060 <xfree@plt>
mov    0x18(%rsp),%rdi
call   1060 <xfree@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.s1c3.HEXSTRING3 = [70 x i8] c"1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736\00\00"
@__const.s1c3.SINGLECHAR = [3 x i8] c"A\00\00"
@.str = [46 x i8] c"Challenge 3\0Afind the single byte to decrypt:\0A\00"
define void @s1c3() {
%1 = alloca [70 x i8]
%2 = alloca [3 x i8]
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
%8 = call i32 (...) @separate()
%9 = bitcast [70 x i8]* %1 to i8*
%10 = bitcast [3 x i8]* %2 to i8*
%11 = call i8* @xmalloc(i32 1)
store i8* %11, i8** %3
%12 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds [70 x i8], [70 x i8]* %1, i64 0, i64 0
%14 = call i32 @puts(i8* %13)
%15 = getelementptr inbounds [70 x i8], [70 x i8]* %1, i64 0, i64 0
%16 = call i64 @hexstr_to_string(i8** %3, i8* %15)
store i64 %16, i64* %6
%17 = call i8* @xmalloc(i32 1)
store i8* %17, i8** %7
store i32 0, i32* %4
br label %18
18: ; preds = %33, %0
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 256
br i1 %20, label %21, label %36
21: ; preds = %18
%22 = load i32, i32* %4
%23 = trunc i32 %22 to i8
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
store i8 %23, i8* %24
%25 = load i8*, i8** %3
%26 = load i64, i64* %6
%27 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%28 = call i32 @xor_bytes_to_string(i8** %7, i8* %25, i64 %26, i8* %27, i32 1)
%29 = load i8*, i8** %7
%30 = load i64, i64* %6
%31 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%32 = call i32 @get_score(i8* %29, i64 %30, i8* %31, i32 -1000, float 2.000000e+00, i32 0)
br label %33
33: ; preds = %21
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %18
36: ; preds = %18
%37 = call i32 (...) @get_best()
%38 = call i32 (...) @destroy_scores()
%39 = load i8*, i8** %7
%40 = call i32 @xfree(i8* %39)
%41 = load i8*, i8** %3
%42 = call i32 @xfree(i8* %41)
ret void
}

LLVM IR (-O2):
@__const.s1c3.HEXSTRING3 = [70 x i8] c"1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736\00\00"
@__const.s1c3.SINGLECHAR = [3 x i8] c"A\00\00"
@str = [45 x i8] c"Challenge 3\0Afind the single byte to decrypt:\00"
define void @s1c3() {
%1 = alloca [70 x i8]
%2 = alloca [3 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = tail call i32 (...) @separate()
%6 = getelementptr inbounds [70 x i8], [70 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%8 = bitcast i8** %3 to i8*
%9 = tail call i8* @xmalloc(i32 1)
store i8* %9, i8** %3
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%11 = call i32 @puts(i8* %6)
%12 = call i64 @hexstr_to_string(i8** %3, i8* %6)
%13 = bitcast i8** %4 to i8*
%14 = call i8* @xmalloc(i32 1)
store i8* %14, i8** %4
br label %15
15: ; preds = %0, %15
%16 = phi i32 [ 0, %0 ], [ %22, %15 ]
%17 = trunc i32 %16 to i8
store i8 %17, i8* %7
%18 = load i8*, i8** %3
%19 = call i32 @xor_bytes_to_string(i8** %4, i8* %18, i64 %12, i8* %7, i32 1)
%20 = load i8*, i8** %4
%21 = call i32 @get_score(i8* %20, i64 %12, i8* %7, i32 -1000, float 2.000000e+00, i32 0)
%22 = add nuw nsw i32 %16, 1
%23 = icmp eq i32 %22, 256
br i1 %23, label %24, label %15
24: ; preds = %15
%25 = call i32 (...) @get_best()
%26 = call i32 (...) @destroy_scores()
%27 = load i8*, i8** %4
%28 = call i32 @xfree(i8* %27)
%29 = load i8*, i8** %3
%30 = call i32 @xfree(i8* %29)
ret void
}