#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*/ assert(int);
int crack(char *, char *, char **);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
int strcmp(char const *, char *);
void TESTCRACK(const char *enc, const char *kw, const int rc,
               const char *expected) {
  char *msg = NULL;
  int retc = 0;
  int stringCompare = -1;
  int finalResult = 0;
  assert(expected != NULL);
  printf("\n    Test: \"%s\" by searching for %s : \n",
         (enc == NULL ? "NULL" : (*enc == 0 ? "EMPTY" : enc)),
         (kw == NULL ? "NULL" : (*kw == 0 ? "EMPTY" : kw)));
  printf("  Expect: \"%s\" returning %d : \n", expected, rc);
  retc = crack((char *)enc, (char *)kw, &msg);
  printf("Received: \"%s\" and %d : ",
         (msg == NULL ? "NULL" : (*msg == 0 ? "EMPTY" : msg)), retc);
  if (msg) {
    stringCompare = strcmp(expected, msg);
  }
  if ((retc == -1) && (rc == -1)) {
    printf("[OK]");
    finalResult = 1;
  } else if ((retc != -1) && (retc == rc) && (stringCompare == 0)) {
    printf("[OK]");
    finalResult = 1;
  } else {
    printf("[FAILED]");
    finalResult = 0;
  }
  printf("\n");
  {
    if (msg) {
      free(msg);
      msg = NULL;
    }
  };
  assert(finalResult == 1);
}


x86 assembly (clang, -O0):
<TESTCRACK>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0xffffffff,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpq   $0x0,-0x8(%rbp)
jne    11b1 <TESTCRACK+0x61>
lea    0xe80(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    11e1 <TESTCRACK+0x91>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11d1 <TESTCRACK+0x81>
lea    0xe65(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    11d9 <TESTCRACK+0x89>
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1204 <TESTCRACK+0xb4>
lea    0xe2d(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    1234 <TESTCRACK+0xe4>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1224 <TESTCRACK+0xd4>
lea    0xe12(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    122c <TESTCRACK+0xdc>
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rsi
mov    -0x58(%rbp),%rdx
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1070 <crack@plt>
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    128e <TESTCRACK+0x13e>
lea    0xda3(%rip),%rax
mov    %rax,-0x68(%rbp)
jmp    12be <TESTCRACK+0x16e>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    12ae <TESTCRACK+0x15e>
lea    0xd88(%rip),%rax
mov    %rax,-0x70(%rbp)
jmp    12b6 <TESTCRACK+0x166>
mov    -0x28(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rsi
mov    -0x2c(%rbp),%edx
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x28(%rbp)
je     12ee <TESTCRACK+0x19e>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <strcmp@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    131c <TESTCRACK+0x1cc>
cmpl   $0xffffffff,-0x14(%rbp)
jne    131c <TESTCRACK+0x1cc>
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x34(%rbp)
jmp    1370 <TESTCRACK+0x220>
cmpl   $0xffffffff,-0x2c(%rbp)
je     1356 <TESTCRACK+0x206>
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1356 <TESTCRACK+0x206>
cmpl   $0x0,-0x30(%rbp)
jne    1356 <TESTCRACK+0x206>
lea    0xd29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x34(%rbp)
jmp    136b <TESTCRACK+0x21b>
lea    0xd14(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x34(%rbp)
jmp    1370 <TESTCRACK+0x220>
lea    0xcda(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x28(%rbp)
je     139a <TESTCRACK+0x24a>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
cmpl   $0x1,-0x34(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TESTCRACK>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r15
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
xor    %edi,%edi
test   %rcx,%rcx
setne  %dil
call   1070 <assert@plt>
lea    0xe92(%rip),%rbp
mov    %rbp,%rsi
test   %rbx,%rbx
je     11ac <TESTCRACK+0x4c>
cmpb   $0x0,(%rbx)
lea    0xe85(%rip),%rsi
cmovne %rbx,%rsi
mov    %rbp,%rdx
test   %r12,%r12
je     11c4 <TESTCRACK+0x64>
cmpb   $0x0,(%r12)
lea    0xe6d(%rip),%rdx
cmovne %r12,%rdx
lea    0xe35(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe5a(%rip),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <crack@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rax
test   %rax,%rax
je     1210 <TESTCRACK+0xb0>
cmpb   $0x0,(%rax)
lea    0xe21(%rip),%rbp
cmovne %rax,%rbp
lea    0xe3c(%rip),%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rsi
test   %rsi,%rsi
je     1237 <TESTCRACK+0xd7>
mov    %r15,%rdi
call   1060 <strcmp@plt>
jmp    123c <TESTCRACK+0xdc>
mov    $0xffffffff,%eax
mov    %ebx,%ecx
and    %r14d,%ecx
mov    $0x1,%ebp
lea    0xe1f(%rip),%rdi
cmp    $0xffffffff,%ecx
je     1269 <TESTCRACK+0x109>
cmp    $0xffffffff,%ebx
je     1260 <TESTCRACK+0x100>
cmp    %r14d,%ebx
jne    1260 <TESTCRACK+0x100>
test   %eax,%eax
je     1269 <TESTCRACK+0x109>
xor    %ebp,%ebp
lea    0xe08(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     1292 <TESTCRACK+0x132>
call   1030 <free@plt>
movq   $0x0,0x8(%rsp)
mov    %ebp,%edi
call   1070 <assert@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"\0A Test: \22%s\22 by searching for %s : \0A\00"
@.str.1 = [5 x i8] c"NULL\00"
@.str.2 = [6 x i8] c"EMPTY\00"
@.str.3 = [32 x i8] c" Expect: \22%s\22 returning %d : \0A\00"
@.str.4 = [25 x i8] c"Received: \22%s\22 and %d : \00"
@.str.5 = [5 x i8] c"[OK]\00"
@.str.6 = [9 x i8] c"[FAILED]\00"
@.str.7 = [2 x i8] c"\0A\00"
define void @TESTCRACK(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
store i8* null, i8** %9
store i32 0, i32* %10
store i32 -1, i32* %11
store i32 0, i32* %12
%13 = load i8*, i8** %8
%14 = icmp ne i8* %13, null
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i8*, i8** %5
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %4
br label %30
20: ; preds = %4
%21 = load i8*, i8** %5
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
br label %28
26: ; preds = %20
%27 = load i8*, i8** %5
br label %28
28: ; preds = %26, %25
%29 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %25 ], [ %27, %26 ]
br label %30
30: ; preds = %28, %19
%31 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %19 ], [ %29, %28 ]
%32 = load i8*, i8** %6
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %35
34: ; preds = %30
br label %45
35: ; preds = %30
%36 = load i8*, i8** %6
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %35
br label %43
41: ; preds = %35
%42 = load i8*, i8** %6
br label %43
43: ; preds = %41, %40
%44 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %40 ], [ %42, %41 ]
br label %45
45: ; preds = %43, %34
%46 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %34 ], [ %44, %43 ]
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %31, i8* %46)
%48 = load i8*, i8** %8
%49 = load i32, i32* %7
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %48, i32 %49)
%51 = load i8*, i8** %5
%52 = load i8*, i8** %6
%53 = call i32 @crack(i8* %51, i8* %52, i8** %9)
store i32 %53, i32* %10
%54 = load i8*, i8** %9
%55 = icmp eq i8* %54, null
br i1 %55, label %56, label %57
56: ; preds = %45
br label %67
57: ; preds = %45
%58 = load i8*, i8** %9
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %57
br label %65
63: ; preds = %57
%64 = load i8*, i8** %9
br label %65
65: ; preds = %63, %62
%66 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %62 ], [ %64, %63 ]
br label %67
67: ; preds = %65, %56
%68 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %56 ], [ %66, %65 ]
%69 = load i32, i32* %10
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %68, i32 %69)
%71 = load i8*, i8** %9
%72 = icmp ne i8* %71, null
br i1 %72, label %73, label %77
73: ; preds = %67
%74 = load i8*, i8** %8
%75 = load i8*, i8** %9
%76 = call i32 @strcmp(i8* %74, i8* %75)
store i32 %76, i32* %11
br label %77
77: ; preds = %73, %67
%78 = load i32, i32* %10
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %85
80: ; preds = %77
%81 = load i32, i32* %7
%82 = icmp eq i32 %81, -1
br i1 %82, label %83, label %85
83: ; preds = %80
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %12
br label %100
85: ; preds = %80, %77
%86 = load i32, i32* %10
%87 = icmp ne i32 %86, -1
br i1 %87, label %88, label %97
88: ; preds = %85
%89 = load i32, i32* %10
%90 = load i32, i32* %7
%91 = icmp eq i32 %89, %90
br i1 %91, label %92, label %97
92: ; preds = %88
%93 = load i32, i32* %11
%94 = icmp eq i32 %93, 0
br i1 %94, label %95, label %97
95: ; preds = %92
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %12
br label %99
97: ; preds = %92, %88, %85
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %12
br label %99
99: ; preds = %97, %95
br label %100
100: ; preds = %99, %83
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%102 = load i8*, i8** %9
%103 = icmp ne i8* %102, null
br i1 %103, label %104, label %107
104: ; preds = %100
%105 = load i8*, i8** %9
%106 = call i32 @free(i8* %105)
store i8* null, i8** %9
br label %107
107: ; preds = %104, %100
%108 = load i32, i32* %12
%109 = icmp eq i32 %108, 1
%110 = zext i1 %109 to i32
%111 = call i32 @assert(i32 %110)
ret void
}

LLVM IR (-O2):
@.str = [40 x i8] c"\0A Test: \22%s\22 by searching for %s : \0A\00"
@.str.1 = [5 x i8] c"NULL\00"
@.str.2 = [6 x i8] c"EMPTY\00"
@.str.3 = [32 x i8] c" Expect: \22%s\22 returning %d : \0A\00"
@.str.4 = [25 x i8] c"Received: \22%s\22 and %d : \00"
@.str.5 = [5 x i8] c"[OK]\00"
@.str.6 = [9 x i8] c"[FAILED]\00"
define void @TESTCRACK(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%7 = icmp ne i8* %3, null
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = icmp eq i8* %0, null
br i1 %10, label %15, label %11
11: ; preds = %4
%12 = load i8, i8* %0
%13 = icmp eq i8 %12, 0
%14 = select i1 %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0
br label %15
15: ; preds = %4, %11
%16 = phi i8* [ %14, %11 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %4 ]
%17 = icmp eq i8* %1, null
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = load i8, i8* %1
%20 = icmp eq i8 %19, 0
%21 = select i1 %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %1
br label %22
22: ; preds = %15, %18
%23 = phi i8* [ %21, %18 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %15 ]
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %23)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %3, i32 %2)
%26 = call i32 @crack(i8* %0, i8* %1, i8** %5)
%27 = load i8*, i8** %5
%28 = icmp eq i8* %27, null
br i1 %28, label %33, label %29
29: ; preds = %22
%30 = load i8, i8* %27
%31 = icmp eq i8 %30, 0
%32 = select i1 %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %27
br label %33
33: ; preds = %22, %29
%34 = phi i8* [ %32, %29 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %22 ]
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %34, i32 %26)
%36 = load i8*, i8** %5
%37 = icmp eq i8* %36, null
br i1 %37, label %40, label %38
38: ; preds = %33
%39 = call i32 @strcmp(i8* dereferenceable(1) %3, i8* %36)
br label %40
40: ; preds = %38, %33
%41 = phi i32 [ %39, %38 ], [ -1, %33 ]
%42 = and i32 %26, %2
%43 = icmp eq i32 %42, -1
br i1 %43, label %51, label %44
44: ; preds = %40
%45 = icmp eq i32 %26, -1
br i1 %45, label %50, label %46
46: ; preds = %44
%47 = icmp eq i32 %26, %2
%48 = icmp eq i32 %41, 0
%49 = select i1 %47, i1 %48, i1 false
br i1 %49, label %51, label %50
50: ; preds = %46, %44
br label %51
51: ; preds = %46, %40, %50
%52 = phi i8* [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), %50 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), %40 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), %46 ]
%53 = phi i32 [ 0, %50 ], [ 1, %40 ], [ 1, %46 ]
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %52)
%55 = call i32 @putchar(i32 10)
%56 = load i8*, i8** %5
%57 = icmp eq i8* %56, null
br i1 %57, label %60, label %58
58: ; preds = %51
%59 = call i32 @free(i8* %56)
store i8* null, i8** %5
br label %60
60: ; preds = %58, %51
%61 = call i32 @assert(i32 %53)
ret void
}