#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
double INFINITY;
char *breakSingleXOR(int /*<<< orphan*/ *, int);
char *malloc(int);
int /*<<< orphan*/ *parseHexString(char *, int);
int /*<<< orphan*/ printf(char *, int, double, char *);
int /*<<< orphan*/ scanf(char *, char *);
double scoreSingleXOR(int /*<<< orphan*/ *, int);
int main(int argc, char const *argv[]) {
  uint8_t *possibleMessages[327];
  char *string = malloc(60);
  double bestScore = -INFINITY;
  int bestMessage = 0;
  for (int i = 0; i < 327; ++i) {
    scanf("%s", string);
    possibleMessages[i] = parseHexString(string, 60);
    double score = scoreSingleXOR(possibleMessages[i], 60 / 2);
    if (score > bestScore) {
      bestScore = score;
      bestMessage = i;
    }
  }
  char *message = breakSingleXOR(possibleMessages[bestMessage], 60 / 2);
  printf("Best message: %d, Score: %f, Message: %s\n", bestMessage, bestScore,
         message);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x3c,%edi
call   1040 <malloc@plt>
mov    %rax,-0xa58(%rbp)
mov    0x2e57(%rip),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0xa60(%rbp)
ff
movl   $0x0,-0xa64(%rbp)
movl   $0x0,-0xa68(%rbp)
cmpl   $0x147,-0xa68(%rbp)
jge    127a <main+0x11a>
mov    -0xa58(%rbp),%rsi
lea    0xe1a(%rip),%rdi
call   1060 <scanf@plt>
mov    -0xa58(%rbp),%rdi
mov    $0x3c,%esi
call   1050 <parseHexString@plt>
mov    %rax,%rcx
movslq -0xa68(%rbp),%rax
mov    %rcx,-0xa50(%rbp,%rax,8)
ff
movslq -0xa68(%rbp),%rax
mov    -0xa50(%rbp,%rax,8),%rdi
ff
mov    $0x1e,%esi
call   1080 <scoreSingleXOR@plt>
movsd  %xmm0,-0xa70(%rbp)
ff
movsd  -0xa70(%rbp),%xmm0
ff
ucomisd -0xa60(%rbp),%xmm0
ff
jbe    1261 <main+0x101>
movsd  -0xa70(%rbp),%xmm0
ff
movsd  %xmm0,-0xa60(%rbp)
ff
mov    -0xa68(%rbp),%eax
mov    %eax,-0xa64(%rbp)
jmp    1266 <main+0x106>
mov    -0xa68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa68(%rbp)
jmp    11c8 <main+0x68>
movslq -0xa64(%rbp),%rax
mov    -0xa50(%rbp,%rax,8),%rdi
ff
mov    $0x1e,%esi
call   1070 <breakSingleXOR@plt>
mov    %rax,-0xa78(%rbp)
mov    -0xa64(%rbp),%esi
movsd  -0xa60(%rbp),%xmm0
ff
mov    -0xa78(%rbp),%rdx
lea    0xd4d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xa80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xa48,%rsp
mov    $0x3c,%edi
call   1040 <malloc@plt>
mov    0x2e6a(%rip),%rcx
movsd  (%rcx),%xmm0
xorpd  0xe76(%rip),%xmm0
mov    %rax,%r15
xor    %ebx,%ebx
lea    0xe7a(%rip),%r14
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
mov    %r15,%rdi
mov    $0x3c,%esi
call   1050 <parseHexString@plt>
mov    %rax,0x10(%rsp,%rbx,8)
mov    %rax,%rdi
mov    $0x1e,%esi
call   1080 <scoreSingleXOR@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm1,%xmm0
cmova  %ebx,%ebp
maxsd  %xmm1,%xmm0
add    $0x1,%rbx
cmp    $0x147,%rbx
jne    11a0 <main+0x40>
movslq %ebp,%rbx
mov    0x10(%rsp,%rbx,8),%rdi
mov    $0x1e,%esi
movapd %xmm0,(%rsp)
call   1070 <breakSingleXOR@plt>
lea    0xe09(%rip),%rdi
mov    %ebx,%esi
movaps (%rsp),%xmm0
mov    %rax,%rdx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xa48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@INFINITY = global double 0.000000e+00
@.str = [3 x i8] c"%s\00"
@.str.1 = [42 x i8] c"Best message: %d, Score: %f, Message: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [327 x i32*]
%7 = alloca i8*
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i8* @malloc(i32 60)
store i8* %13, i8** %7
%14 = load double, double* @INFINITY
%15 = fneg double %14
store double %15, double* %8
store i32 0, i32* %9
store i32 0, i32* %10
br label %16
16: ; preds = %39, %2
%17 = load i32, i32* %10
%18 = icmp slt i32 %17, 327
br i1 %18, label %19, label %42
19: ; preds = %16
%20 = load i8*, i8** %7
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i8*, i8** %7
%23 = call i32* @parseHexString(i8* %22, i32 60)
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [327 x i32*], [327 x i32*]* %6, i64 0, i64 %25
store i32* %23, i32** %26
%27 = load i32, i32* %10
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [327 x i32*], [327 x i32*]* %6, i64 0, i64 %28
%30 = load i32*, i32** %29
%31 = call double @scoreSingleXOR(i32* %30, i32 30)
store double %31, double* %11
%32 = load double, double* %11
%33 = load double, double* %8
%34 = fcmp ogt double %32, %33
br i1 %34, label %35, label %38
35: ; preds = %19
%36 = load double, double* %11
store double %36, double* %8
%37 = load i32, i32* %10
store i32 %37, i32* %9
br label %38
38: ; preds = %35, %19
br label %39
39: ; preds = %38
%40 = load i32, i32* %10
%41 = add nsw i32 %40, 1
store i32 %41, i32* %10
br label %16
42: ; preds = %16
%43 = load i32, i32* %9
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [327 x i32*], [327 x i32*]* %6, i64 0, i64 %44
%46 = load i32*, i32** %45
%47 = call i8* @breakSingleXOR(i32* %46, i32 30)
store i8* %47, i8** %12
%48 = load i32, i32* %9
%49 = load double, double* %8
%50 = load i8*, i8** %12
%51 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %48, double %49, i8* %50)
ret i32 0
}

LLVM IR (-O2):
@INFINITY = global double 0.000000e+00
@.str = [3 x i8] c"%s\00"
@.str.1 = [42 x i8] c"Best message: %d, Score: %f, Message: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [327 x i32*]
%4 = bitcast [327 x i32*]* %3 to i8*
%5 = tail call dereferenceable_or_null(60) i8* @malloc(i32 60)
%6 = load double, double* @INFINITY
%7 = fneg double %6
br label %14
8: ; preds = %14
%9 = sext i32 %24 to i64
%10 = getelementptr inbounds [327 x i32*], [327 x i32*]* %3, i64 0, i64 %9
%11 = load i32*, i32** %10
%12 = tail call i8* @breakSingleXOR(i32* %11, i32 30)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %24, double %25, i8* %12)
ret i32 0
14: ; preds = %2, %14
%15 = phi i64 [ 0, %2 ], [ %26, %14 ]
%16 = phi double [ %7, %2 ], [ %25, %14 ]
%17 = phi i32 [ 0, %2 ], [ %24, %14 ]
%18 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%19 = tail call i32* @parseHexString(i8* %5, i32 60)
%20 = getelementptr inbounds [327 x i32*], [327 x i32*]* %3, i64 0, i64 %15
store i32* %19, i32** %20
%21 = tail call double @scoreSingleXOR(i32* %19, i32 30)
%22 = fcmp ogt double %21, %16
%23 = trunc i64 %15 to i32
%24 = select i1 %22, i32 %23, i32 %17
%25 = select i1 %22, double %21, double %16
%26 = add nuw nsw i64 %15, 1
%27 = icmp eq i64 %26, 327
br i1 %27, label %8, label %14
}