#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 */
double findaKey(char *, int, char *);
char *malloc(int);
int /*<<< orphan*/ shuffleKey(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *simpleSubCrack(char *text, int N) {
  char key[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  char *bestKey = malloc(sizeof(char) * 27);
  int i, len = strlen(text);
  double score, maxscore = -99e99;
  for (i = 0; i < N; i++) {
    shuffleKey(key);
    score = findaKey(text, len, key);
    if (score > maxscore) {
      maxscore = score;
      strcpy(bestKey, key);
    }
  }
  return bestKey;
}


x86 assembly (clang, -O0):
<simpleSubCrack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xea7(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xea4(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xea1(%rip),%ax
mov    %ax,-0x18(%rbp)
mov    0xe99(%rip),%al
mov    %al,-0x16(%rbp)
mov    $0x1b,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x40(%rbp)
movsd  0xe4a(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1226 <simpleSubCrack+0xd6>
lea    -0x30(%rbp),%rdi
call   1070 <shuffleKey@plt>
mov    -0x8(%rbp),%rdi
mov    -0x40(%rbp),%esi
lea    -0x30(%rbp),%rdx
call   1060 <findaKey@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
ucomisd -0x50(%rbp),%xmm0
jbe    1213 <simpleSubCrack+0xc3>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    1218 <simpleSubCrack+0xc8>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11c2 <simpleSubCrack+0x72>
mov    -0x38(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simpleSubCrack>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
movups 0xeb3(%rip),%xmm0
movups %xmm0,0x1b(%rsp)
movapd 0xe9b(%rip),%xmm0
movapd %xmm0,0x10(%rsp)
mov    $0x1b,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %ebx,%ebx
jle    11e6 <simpleSubCrack+0x96>
mov    %eax,%r12d
movsd  0xe61(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0x10(%rsp),%rbp
jmp    11b5 <simpleSubCrack+0x65>
nopl   0x0(%rax)
add    $0xffffffff,%ebx
je     11e6 <simpleSubCrack+0x96>
mov    %rbp,%rdi
call   1070 <shuffleKey@plt>
mov    %r14,%rdi
mov    %r12d,%esi
mov    %rbp,%rdx
call   1060 <findaKey@plt>
ucomisd 0x8(%rsp),%xmm0
jbe    11b0 <simpleSubCrack+0x60>
mov    %r15,%rdi
mov    %rbp,%rsi
movsd  %xmm0,0x8(%rsp)
call   1030 <strcpy@plt>
jmp    11b0 <simpleSubCrack+0x60>
mov    %r15,%rax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.simpleSubCrack.key = [27 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
define i8* @simpleSubCrack(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [27 x i8]
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
store i8* %0, i8** %3
store i32 %1, i32* %4
%11 = bitcast [27 x i8]* %5 to i8*
%12 = call i8* @malloc(i32 27)
store i8* %12, i8** %6
%13 = load i8*, i8** %3
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %8
store double -9.900000e+100, double* %10
store i32 0, i32* %7
br label %15
15: ; preds = %35, %2
%16 = load i32, i32* %7
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %38
19: ; preds = %15
%20 = getelementptr inbounds [27 x i8], [27 x i8]* %5, i64 0, i64 0
%21 = call i32 @shuffleKey(i8* %20)
%22 = load i8*, i8** %3
%23 = load i32, i32* %8
%24 = getelementptr inbounds [27 x i8], [27 x i8]* %5, i64 0, i64 0
%25 = call double @findaKey(i8* %22, i32 %23, i8* %24)
store double %25, double* %9
%26 = load double, double* %9
%27 = load double, double* %10
%28 = fcmp ogt double %26, %27
br i1 %28, label %29, label %34
29: ; preds = %19
%30 = load double, double* %9
store double %30, double* %10
%31 = load i8*, i8** %6
%32 = getelementptr inbounds [27 x i8], [27 x i8]* %5, i64 0, i64 0
%33 = call i32 @strcpy(i8* %31, i8* %32)
br label %34
34: ; preds = %29, %19
br label %35
35: ; preds = %34
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
store i32 %37, i32* %7
br label %15
38: ; preds = %15
%39 = load i8*, i8** %6
ret i8* %39
}

LLVM IR (-O2):
@__const.simpleSubCrack.key = [27 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
define i8* @simpleSubCrack(i8* %0, i32 %1) {
%3 = alloca [27 x i8]
%4 = getelementptr inbounds [27 x i8], [27 x i8]* %3, i64 0, i64 0
%5 = tail call dereferenceable_or_null(27) i8* @malloc(i32 27)
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %20
8: ; preds = %2, %16
%9 = phi double [ %17, %16 ], [ -9.900000e+100, %2 ]
%10 = phi i32 [ %18, %16 ], [ 0, %2 ]
%11 = call i32 @shuffleKey(i8* %4)
%12 = call double @findaKey(i8* %0, i32 %6, i8* %4)
%13 = fcmp ogt double %12, %9
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = call i32 @strcpy(i8* %5, i8* %4)
br label %16
16: ; preds = %8, %14
%17 = phi double [ %12, %14 ], [ %9, %8 ]
%18 = add nuw nsw i32 %10, 1
%19 = icmp eq i32 %18, %1
br i1 %19, label %20, label %8
20: ; preds = %16, %2
ret i8* %5
}