#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__ _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...");
  }
  prnlog("[+] Testing key diversification ...");
  int errors = 0;
  errors += _test_iclass_key_permutation();
  errors += _testBruteforce();
  return errors;
}


x86 assembly (clang, -O0):
<testElite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
lea    0xe8e(%rip),%rdi
call   1030 <prnlog@plt>
lea    0xeab(%rip),%rdi
call   1030 <prnlog@plt>
mov    0xef6(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xef3(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xef0(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xeed(%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    0xe5b(%rip),%rdi
mov    $0x80,%edx
call   1050 <printarr_human_readable@plt>
cmpl   $0xa1,-0x214(%rbp)
jne    1223 <testElite+0xc3>
cmpl   $0xa3,-0x160(%rbp)
jne    1223 <testElite+0xc3>
cmpl   $0x95,-0x64(%rbp)
jne    1223 <testElite+0xc3>
lea    0xe23(%rip),%rdi
call   1030 <prnlog@plt>
lea    0xe2f(%rip),%rdi
call   1030 <prnlog@plt>
movl   $0x0,-0x224(%rbp)
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   1080 <_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   %rbx
sub    $0x220,%rsp
lea    0xe91(%rip),%rdi
call   1030 <prnlog@plt>
lea    0xeae(%rip),%rdi
call   1030 <prnlog@plt>
movaps 0xf09(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeed(%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    0xe7e(%rip),%rdi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1050 <printarr_human_readable@plt>
cmpl   $0xa1,0x2c(%rsp)
jne    11fa <testElite+0x9a>
cmpl   $0xa3,0xe0(%rsp)
jne    11fa <testElite+0x9a>
cmpl   $0x95,0x1dc(%rsp)
jne    11fa <testElite+0x9a>
lea    0xe4c(%rip),%rdi
call   1030 <prnlog@plt>
lea    0xe58(%rip),%rdi
call   1030 <prnlog@plt>
xor    %eax,%eax
call   1070 <_test_iclass_key_permutation@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1080 <_testBruteforce@plt>
add    %ebx,%eax
add    $0x220,%rsp
pop    %rbx
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 = [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
%27 = call i32 @prnlog(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
%28 = call i64 (...) @_test_iclass_key_permutation()
%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 i64 (...) @_testBruteforce()
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = add nsw i64 %35, %33
%37 = trunc i64 %36 to i32
store i32 %37, i32* %3
%38 = load i32, i32* %3
ret i32 %38
}

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 = [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 ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%26 = call i64 (...) @_test_iclass_key_permutation()
%27 = call i64 (...) @_testBruteforce()
%28 = add i64 %27, %26
%29 = trunc i64 %28 to i32
ret i32 %29
}