#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 *binToStr(short);
char *decrypt(char *, char *);
char *encrypt(char *, char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int strcmp(char *, char *);
void bruteForceKeyGenerator(char **plaintext, char **ciphertext) {
  char *keys[20];
  short i;
  int c = 0;
  char *key = malloc(sizeof(char) * 10);
  for (i = 0; i < 1024; i++) {
    key = binToStr(i);
    char *encryption = encrypt(plaintext[0], key);
    char *decryption = decrypt(ciphertext[0], key);
    if (!strcmp(encryption, ciphertext[0])) {
      int j;
      for (j = 0; j < 245; j++) {
        char *encryptionCheck = encrypt(plaintext[j], key);
        char *decryptionCheck = decrypt(ciphertext[j], key);
        int v1 = strcmp(encryptionCheck, ciphertext[j]);
        int v2 = strcmp(decryptionCheck, plaintext[j]);
        if (v1 || v2) {
          break;
        } else if (j > 100) {
          printf("La llave es %s\n", key);
          return;
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<bruteForceKeyGenerator>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0xb8(%rbp)
mov    $0xa,%edi
call   1070 <malloc@plt>
mov    %rax,-0xc0(%rbp)
movw   $0x0,-0xb2(%rbp)
movswl -0xb2(%rbp),%eax
cmp    $0x400,%eax
jge    132f <bruteForceKeyGenerator+0x1cf>
movswl -0xb2(%rbp),%edi
call   1080 <binToStr@plt>
mov    %rax,-0xc0(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0xc0(%rbp),%rsi
call   1050 <encrypt@plt>
mov    %rax,-0xc8(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0xc0(%rbp),%rsi
call   1030 <decrypt@plt>
mov    %rax,-0xd0(%rbp)
mov    -0xc8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1313 <bruteForceKeyGenerator+0x1b3>
movl   $0x0,-0xd4(%rbp)
cmpl   $0xf5,-0xd4(%rbp)
jge    130e <bruteForceKeyGenerator+0x1ae>
mov    -0x8(%rbp),%rax
movslq -0xd4(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0xc0(%rbp),%rsi
call   1050 <encrypt@plt>
mov    %rax,-0xe0(%rbp)
mov    -0x10(%rbp),%rax
movslq -0xd4(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0xc0(%rbp),%rsi
call   1030 <decrypt@plt>
mov    %rax,-0xe8(%rbp)
mov    -0xe0(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0xd4(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcmp@plt>
mov    %eax,-0xec(%rbp)
mov    -0xe8(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0xd4(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcmp@plt>
mov    %eax,-0xf0(%rbp)
cmpl   $0x0,-0xec(%rbp)
jne    12c6 <bruteForceKeyGenerator+0x166>
cmpl   $0x0,-0xf0(%rbp)
je     12cb <bruteForceKeyGenerator+0x16b>
jmp    130e <bruteForceKeyGenerator+0x1ae>
cmpl   $0x64,-0xd4(%rbp)
jle    12f0 <bruteForceKeyGenerator+0x190>
mov    -0xc0(%rbp),%rsi
lea    0xd1a(%rip),%rdi
call   1040 <printf@plt>
jmp    132f <bruteForceKeyGenerator+0x1cf>
jmp    12f5 <bruteForceKeyGenerator+0x195>
jmp    12fa <bruteForceKeyGenerator+0x19a>
mov    -0xd4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd4(%rbp)
jmp    1216 <bruteForceKeyGenerator+0xb6>
jmp    1313 <bruteForceKeyGenerator+0x1b3>
jmp    1318 <bruteForceKeyGenerator+0x1b8>
mov    -0xb2(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0xb2(%rbp)
jmp    1197 <bruteForceKeyGenerator+0x37>
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bruteForceKeyGenerator>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ecx,%ecx
jmp    1185 <bruteForceKeyGenerator+0x35>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rsp),%rcx
add    $0x1,%ecx
movzwl %cx,%eax
cmp    $0x400,%eax
je     1227 <bruteForceKeyGenerator+0xd7>
mov    %rcx,(%rsp)
movswl %cx,%edi
call   1070 <binToStr@plt>
mov    %rax,%r13
mov    (%r14),%rdi
mov    %rax,%rsi
call   1050 <encrypt@plt>
mov    %rax,%r12
mov    (%r15),%rdi
mov    %r13,%rsi
call   1030 <decrypt@plt>
mov    (%r15),%rsi
mov    %r12,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    1170 <bruteForceKeyGenerator+0x20>
xor    %ebp,%ebp
xchg   %ax,%ax
mov    (%r14,%rbp,8),%rdi
mov    %r13,%rsi
call   1050 <encrypt@plt>
mov    %rax,%rbx
mov    (%r15,%rbp,8),%rdi
mov    %r13,%rsi
call   1030 <decrypt@plt>
mov    %rax,%r12
mov    (%r15,%rbp,8),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
mov    %eax,%ebx
mov    (%r14,%rbp,8),%rsi
mov    %r12,%rdi
call   1060 <strcmp@plt>
or     %ebx,%eax
jne    1170 <bruteForceKeyGenerator+0x20>
add    $0x1,%rbp
cmp    $0x66,%rbp
jne    11c0 <bruteForceKeyGenerator+0x70>
lea    0xdef(%rip),%rdi
mov    %r13,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"La llave es %s\0A\00"
define void @bruteForceKeyGenerator(i8** %0, i8** %1) {
%3 = alloca i8**
%4 = alloca i8**
%5 = alloca [20 x i8*]
%6 = alloca i16
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
store i8** %0, i8*** %3
store i8** %1, i8*** %4
store i32 0, i32* %7
%16 = call i8* @malloc(i32 10)
store i8* %16, i8** %8
store i16 0, i16* %6
br label %17
17: ; preds = %92, %2
%18 = load i16, i16* %6
%19 = sext i16 %18 to i32
%20 = icmp slt i32 %19, 1024
br i1 %20, label %21, label %95
21: ; preds = %17
%22 = load i16, i16* %6
%23 = call i8* @binToStr(i16 signext %22)
store i8* %23, i8** %8
%24 = load i8**, i8*** %3
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = load i8*, i8** %8
%28 = call i8* @encrypt(i8* %26, i8* %27)
store i8* %28, i8** %9
%29 = load i8**, i8*** %4
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = load i8*, i8** %8
%33 = call i8* @decrypt(i8* %31, i8* %32)
store i8* %33, i8** %10
%34 = load i8*, i8** %9
%35 = load i8**, i8*** %4
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = call i32 @strcmp(i8* %34, i8* %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %91, label %40
40: ; preds = %21
store i32 0, i32* %11
br label %41
41: ; preds = %87, %40
%42 = load i32, i32* %11
%43 = icmp slt i32 %42, 245
br i1 %43, label %44, label %90
44: ; preds = %41
%45 = load i8**, i8*** %3
%46 = load i32, i32* %11
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
%50 = load i8*, i8** %8
%51 = call i8* @encrypt(i8* %49, i8* %50)
store i8* %51, i8** %12
%52 = load i8**, i8*** %4
%53 = load i32, i32* %11
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
%56 = load i8*, i8** %55
%57 = load i8*, i8** %8
%58 = call i8* @decrypt(i8* %56, i8* %57)
store i8* %58, i8** %13
%59 = load i8*, i8** %12
%60 = load i8**, i8*** %4
%61 = load i32, i32* %11
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8*, i8** %60, i64 %62
%64 = load i8*, i8** %63
%65 = call i32 @strcmp(i8* %59, i8* %64)
store i32 %65, i32* %14
%66 = load i8*, i8** %13
%67 = load i8**, i8*** %3
%68 = load i32, i32* %11
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8*, i8** %67, i64 %69
%71 = load i8*, i8** %70
%72 = call i32 @strcmp(i8* %66, i8* %71)
store i32 %72, i32* %15
%73 = load i32, i32* %14
%74 = icmp ne i32 %73, 0
br i1 %74, label %78, label %75
75: ; preds = %44
%76 = load i32, i32* %15
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %79
78: ; preds = %75, %44
br label %90
79: ; preds = %75
%80 = load i32, i32* %11
%81 = icmp sgt i32 %80, 100
br i1 %81, label %82, label %85
82: ; preds = %79
%83 = load i8*, i8** %8
%84 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %83)
br label %95
85: ; preds = %79
br label %86
86: ; preds = %85
br label %87
87: ; preds = %86
%88 = load i32, i32* %11
%89 = add nsw i32 %88, 1
store i32 %89, i32* %11
br label %41
90: ; preds = %78, %41
br label %91
91: ; preds = %90, %21
br label %92
92: ; preds = %91
%93 = load i16, i16* %6
%94 = add i16 %93, 1
store i16 %94, i16* %6
br label %17
95: ; preds = %82, %17
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"La llave es %s\0A\00"
define void @bruteForceKeyGenerator(i8** nocapture %0, i8** nocapture %1) {
br label %3
3: ; preds = %2, %33
%4 = phi i16 [ 0, %2 ], [ %34, %33 ]
%5 = tail call i8* @binToStr(i16 signext %4)
%6 = load i8*, i8** %0
%7 = tail call i8* @encrypt(i8* %6, i8* %5)
%8 = load i8*, i8** %1
%9 = tail call i8* @decrypt(i8* %8, i8* %5)
%10 = load i8*, i8** %1
%11 = tail call i32 @strcmp(i8* dereferenceable(1) %7, i8* dereferenceable(1) %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %33
13: ; preds = %3, %28
%14 = phi i64 [ %30, %28 ], [ 0, %3 ]
%15 = getelementptr inbounds i8*, i8** %0, i64 %14
%16 = load i8*, i8** %15
%17 = tail call i8* @encrypt(i8* %16, i8* %5)
%18 = getelementptr inbounds i8*, i8** %1, i64 %14
%19 = load i8*, i8** %18
%20 = tail call i8* @decrypt(i8* %19, i8* %5)
%21 = load i8*, i8** %18
%22 = tail call i32 @strcmp(i8* dereferenceable(1) %17, i8* dereferenceable(1) %21)
%23 = load i8*, i8** %15
%24 = tail call i32 @strcmp(i8* dereferenceable(1) %20, i8* dereferenceable(1) %23)
%25 = icmp ne i32 %22, 0
%26 = icmp ne i32 %24, 0
%27 = select i1 %25, i1 true, i1 %26
br i1 %27, label %33, label %28
28: ; preds = %13
%29 = icmp eq i64 %14, 101
%30 = add nuw nsw i64 %14, 1
br i1 %29, label %31, label %13
31: ; preds = %28
%32 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %36
33: ; preds = %13, %3
%34 = add nuw nsw i16 %4, 1
%35 = icmp eq i16 %34, 1024
br i1 %35, label %36, label %3
36: ; preds = %33, %31
ret void
}