#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 uint8_t;

/* Variables and functions */
scalar_t__ _testBruteforce();
scalar_t__ _testHash1();
scalar_t__ _test_iclass_key_permutation();
int /*<<< orphan*/ hash2(int *, int *);
int /*<<< orphan*/ printarr_human_readable(char *, int *, int);
int /*<<< orphan*/ prnlog(char *);
int testElite() {
  prnlog("[+] Testing iClass Elite functinality...");
  prnlog("[+] Testing hash2");
  uint8_t k_cus[8] = {0x5B, 0x7C, 0x62, 0xC4, 0x91, 0xC1, 0x1B, 0x39};
  uint8_t keytable[128] = {0};
  hash2(k_cus, keytable);
  printarr_human_readable("Hash2", keytable, 128);
  if (keytable[3] == 0xA1 && keytable[0x30] == 0xA3 && keytable[0x6F] == 0x95) {
    prnlog("[+] Hash2 looks fine...");
  }
  int errors = 0;
  prnlog("[+] Testing hash1...");
  errors += _testHash1();
  prnlog("[+] Testing key diversification ...");
  errors += _test_iclass_key_permutation();
  errors += _testBruteforce();
  return errors;
}


x86 assembly (clang, -O0):
<testElite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
lea    0xe7e(%rip),%rdi
call   1030 <prnlog@plt>
lea    0xe9b(%rip),%rdi
call   1030 <prnlog@plt>
mov    0xf06(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xf03(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xf00(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xefd(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
lea    -0x20(%rbp),%rdi
lea    -0x220(%rbp),%rsi
call   1040 <hash2@plt>
lea    -0x220(%rbp),%rsi
lea    0xe4b(%rip),%rdi
mov    $0x80,%edx
call   1050 <printarr_human_readable@plt>
cmpl   $0xa1,-0x214(%rbp)
jne    1233 <testElite+0xc3>
cmpl   $0xa3,-0x160(%rbp)
jne    1233 <testElite+0xc3>
cmpl   $0x95,-0x64(%rbp)
jne    1233 <testElite+0xc3>
lea    0xe13(%rip),%rdi
call   1030 <prnlog@plt>
movl   $0x0,-0x224(%rbp)
lea    0xe15(%rip),%rdi
call   1030 <prnlog@plt>
mov    $0x0,%al
call   1080 <_testHash1@plt>
mov    %rax,%rcx
movslq -0x224(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x224(%rbp)
lea    0xe04(%rip),%rdi
call   1030 <prnlog@plt>
mov    $0x0,%al
call   1070 <_test_iclass_key_permutation@plt>
mov    %rax,%rcx
movslq -0x224(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x224(%rbp)
mov    $0x0,%al
call   1090 <_testBruteforce@plt>
mov    %rax,%rcx
movslq -0x224(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x224(%rbp)
mov    -0x224(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testElite>:
push   %r14
push   %rbx
sub    $0x228,%rsp
lea    0xe7f(%rip),%rdi
call   1030 <prnlog@plt>
lea    0xe9c(%rip),%rdi
call   1030 <prnlog@plt>
movaps 0xf17(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xefb(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x20(%rsp),%rbx
mov    $0x200,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1040 <hash2@plt>
lea    0xe6c(%rip),%rdi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1050 <printarr_human_readable@plt>
cmpl   $0xa1,0x2c(%rsp)
jne    120c <testElite+0x9c>
cmpl   $0xa3,0xe0(%rsp)
jne    120c <testElite+0x9c>
cmpl   $0x95,0x1dc(%rsp)
jne    120c <testElite+0x9c>
lea    0xe3a(%rip),%rdi
call   1030 <prnlog@plt>
lea    0xe46(%rip),%rdi
call   1030 <prnlog@plt>
xor    %eax,%eax
call   1080 <_testHash1@plt>
mov    %rax,%r14
lea    0xe45(%rip),%rdi
call   1030 <prnlog@plt>
xor    %eax,%eax
call   1070 <_test_iclass_key_permutation@plt>
mov    %rax,%rbx
add    %r14d,%ebx
xor    %eax,%eax
call   1090 <_testBruteforce@plt>
add    %ebx,%eax
add    $0x228,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [41 x i8] c"[+] Testing iClass Elite functinality...\00"
@.str.1 = [18 x i8] c"[+] Testing hash2\00"
@__const.testElite.k_cus = [8 x i32] [i32 91, i32 124, i32 98, i32 196, i32 145, i32 193, i32 27, i32 57]
@.str.2 = [6 x i8] c"Hash2\00"
@.str.3 = [24 x i8] c"[+] Hash2 looks fine...\00"
@.str.4 = [21 x i8] c"[+] Testing hash1...\00"
@.str.5 = [36 x i8] c"[+] Testing key diversification ...\00"
define i32 @testElite() {
%1 = alloca [8 x i32]
%2 = alloca [128 x i32]
%3 = alloca i32
%4 = call i32 @prnlog(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @prnlog(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%6 = bitcast [8 x i32]* %1 to i8*
%7 = bitcast [128 x i32]* %2 to i8*
%8 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 0, i64 0
%9 = getelementptr inbounds [128 x i32], [128 x i32]* %2, i64 0, i64 0
%10 = call i32 @hash2(i32* %8, i32* %9)
%11 = getelementptr inbounds [128 x i32], [128 x i32]* %2, i64 0, i64 0
%12 = call i32 @printarr_human_readable(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %11, i32 128)
%13 = getelementptr inbounds [128 x i32], [128 x i32]* %2, i64 0, i64 3
%14 = load i32, i32* %13
%15 = icmp eq i32 %14, 161
br i1 %15, label %16, label %26
16: ; preds = %0
%17 = getelementptr inbounds [128 x i32], [128 x i32]* %2, i64 0, i64 48
%18 = load i32, i32* %17
%19 = icmp eq i32 %18, 163
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = getelementptr inbounds [128 x i32], [128 x i32]* %2, i64 0, i64 111
%22 = load i32, i32* %21
%23 = icmp eq i32 %22, 149
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @prnlog(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %24, %20, %16, %0
store i32 0, i32* %3
%27 = call i32 @prnlog(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%28 = call i64 (...) @_testHash1()
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = add nsw i64 %30, %28
%32 = trunc i64 %31 to i32
store i32 %32, i32* %3
%33 = call i32 @prnlog(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%34 = call i64 (...) @_test_iclass_key_permutation()
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = add nsw i64 %36, %34
%38 = trunc i64 %37 to i32
store i32 %38, i32* %3
%39 = call i64 (...) @_testBruteforce()
%40 = load i32, i32* %3
%41 = sext i32 %40 to i64
%42 = add nsw i64 %41, %39
%43 = trunc i64 %42 to i32
store i32 %43, i32* %3
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [41 x i8] c"[+] Testing iClass Elite functinality...\00"
@.str.1 = [18 x i8] c"[+] Testing hash2\00"
@__const.testElite.k_cus = [8 x i32] [i32 91, i32 124, i32 98, i32 196, i32 145, i32 193, i32 27, i32 57]
@.str.2 = [6 x i8] c"Hash2\00"
@.str.3 = [24 x i8] c"[+] Hash2 looks fine...\00"
@.str.4 = [21 x i8] c"[+] Testing hash1...\00"
@.str.5 = [36 x i8] c"[+] Testing key diversification ...\00"
define i32 @testElite() {
%1 = alloca [8 x i32]
%2 = alloca [128 x i32]
%3 = tail call i32 @prnlog(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @prnlog(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%5 = bitcast [8 x i32]* %1 to i8*
%6 = bitcast [128 x i32]* %2 to i8*
%7 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 0, i64 0
%8 = getelementptr inbounds [128 x i32], [128 x i32]* %2, i64 0, i64 0
%9 = call i32 @hash2(i32* %7, i32* %8)
%10 = call i32 @printarr_human_readable(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %8, i32 128)
%11 = getelementptr inbounds [128 x i32], [128 x i32]* %2, i64 0, i64 3
%12 = load i32, i32* %11
%13 = icmp eq i32 %12, 161
%14 = getelementptr inbounds [128 x i32], [128 x i32]* %2, i64 0, i64 48
%15 = load i32, i32* %14
%16 = icmp eq i32 %15, 163
%17 = select i1 %13, i1 %16, i1 false
%18 = getelementptr inbounds [128 x i32], [128 x i32]* %2, i64 0, i64 111
%19 = load i32, i32* %18
%20 = icmp eq i32 %19, 149
%21 = select i1 %17, i1 %20, i1 false
br i1 %21, label %22, label %24
22: ; preds = %0
%23 = call i32 @prnlog(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %0
%25 = call i32 @prnlog(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%26 = call i64 (...) @_testHash1()
%27 = call i32 @prnlog(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%28 = call i64 (...) @_test_iclass_key_permutation()
%29 = add i64 %28, %26
%30 = call i64 (...) @_testBruteforce()
%31 = add i64 %29, %30
%32 = trunc i64 %31 to i32
ret i32 %32
}