#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__ memcmp(int *, int *, int);
int /*<<< orphan*/ permutekey(int *, int *);
int /*<<< orphan*/ permutekey_rev(int *, int *);
int /*<<< orphan*/ printarr(char *, int *, int);
int /*<<< orphan*/ prnlog(char *);
int _test_iclass_key_permutation() {
  uint8_t testcase[8] = {0x6c, 0x8d, 0x44, 0xf9, 0x2a, 0x2d, 0x01, 0xbf};
  uint8_t testcase_output[8] = {0};
  uint8_t testcase_output_correct[8] = {0x8a, 0x0d, 0xb9, 0x88,
                                        0xbb, 0xa7, 0x90, 0xea};
  uint8_t testcase_output_rev[8] = {0};
  permutekey(testcase, testcase_output);
  permutekey_rev(testcase_output, testcase_output_rev);
  if (memcmp(testcase_output, testcase_output_correct, 8) != 0) {
    prnlog("Error with iclass key permute!");
    printarr("testcase_output", testcase_output, 8);
    printarr("testcase_output_correct", testcase_output_correct, 8);
    return 1;
  }
  if (memcmp(testcase, testcase_output_rev, 8) != 0) {
    prnlog("Error with reverse iclass key permute");
    printarr("testcase", testcase, 8);
    printarr("testcase_output_rev", testcase_output_rev, 8);
    return 1;
  }
  prnlog("[+] Iclass key permutation OK!");
  return 0;
}


x86 assembly (clang, -O0):
<_test_iclass_key_permutation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    0xe8e(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe8b(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe88(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe85(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    0xe72(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    0xe6f(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    0xe6c(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xe69(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1070 <permutekey@plt>
lea    -0x50(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1080 <permutekey_rev@plt>
lea    -0x50(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x8,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     1261 <_test_iclass_key_permutation+0x101>
lea    0xe1a(%rip),%rdi
call   1030 <prnlog@plt>
lea    -0x50(%rbp),%rsi
lea    0xe29(%rip),%rdi
mov    $0x8,%edx
call   1060 <printarr@plt>
lea    -0x70(%rbp),%rsi
lea    0xe24(%rip),%rdi
mov    $0x8,%edx
call   1060 <printarr@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d8 <_test_iclass_key_permutation+0x178>
lea    -0x30(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x8,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     12c5 <_test_iclass_key_permutation+0x165>
lea    0xe00(%rip),%rdi
call   1030 <prnlog@plt>
lea    -0x30(%rbp),%rsi
lea    0xe16(%rip),%rdi
mov    $0x8,%edx
call   1060 <printarr@plt>
lea    -0x90(%rbp),%rsi
lea    0xe07(%rip),%rdi
mov    $0x8,%edx
call   1060 <printarr@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d8 <_test_iclass_key_permutation+0x178>
lea    0xdfe(%rip),%rdi
call   1030 <prnlog@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_test_iclass_key_permutation>:
push   %rbx
sub    $0x80,%rsp
movaps 0xeb1(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe95(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps 0xeac(%rip),%xmm1
movaps %xmm1,0x50(%rsp)
movaps 0xe90(%rip),%xmm1
movaps %xmm1,0x40(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0x20(%rsp),%rdi
lea    0x60(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <permutekey@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1070 <permutekey_rev@plt>
lea    0x40(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
je     1202 <_test_iclass_key_permutation+0xb2>
lea    0xe67(%rip),%rdi
call   1030 <prnlog@plt>
lea    0xe7a(%rip),%rdi
lea    0x60(%rsp),%rsi
mov    $0x8,%edx
call   1050 <printarr@plt>
lea    0xe74(%rip),%rdi
lea    0x40(%rsp),%rsi
jmp    1245 <_test_iclass_key_permutation+0xf5>
lea    0x20(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x8,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
je     125d <_test_iclass_key_permutation+0x10d>
lea    0xe67(%rip),%rdi
call   1030 <prnlog@plt>
lea    0xe81(%rip),%rdi
lea    0x20(%rsp),%rsi
mov    $0x8,%edx
call   1050 <printarr@plt>
lea    0xe74(%rip),%rdi
mov    %rsp,%rsi
mov    $0x8,%edx
call   1050 <printarr@plt>
mov    $0x1,%eax
add    $0x80,%rsp
pop    %rbx
ret
lea    0xe66(%rip),%rdi
call   1030 <prnlog@plt>
xor    %eax,%eax
jmp    1254 <_test_iclass_key_permutation+0x104>

LLVM IR (-O0):
@__const._test_iclass_key_permutation.testcase = [8 x i32] [i32 108, i32 141, i32 68, i32 249, i32 42, i32 45, i32 1, i32 191]
@__const._test_iclass_key_permutation.testcase_output_correct = [8 x i32] [i32 138, i32 13, i32 185, i32 136, i32 187, i32 167, i32 144, i32 234]
@.str = [31 x i8] c"Error with iclass key permute!\00"
@.str.1 = [16 x i8] c"testcase_output\00"
@.str.2 = [24 x i8] c"testcase_output_correct\00"
@.str.3 = [38 x i8] c"Error with reverse iclass key permute\00"
@.str.4 = [9 x i8] c"testcase\00"
@.str.5 = [20 x i8] c"testcase_output_rev\00"
@.str.6 = [31 x i8] c"[+] Iclass key permutation OK!\00"
define i32 @_test_iclass_key_permutation() {
%1 = alloca i32
%2 = alloca [8 x i32]
%3 = alloca [8 x i32]
%4 = alloca [8 x i32]
%5 = alloca [8 x i32]
%6 = bitcast [8 x i32]* %2 to i8*
%7 = bitcast [8 x i32]* %3 to i8*
%8 = bitcast [8 x i32]* %4 to i8*
%9 = bitcast [8 x i32]* %5 to i8*
%10 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 0
%11 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%12 = call i32 @permutekey(i32* %10, i32* %11)
%13 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%14 = getelementptr inbounds [8 x i32], [8 x i32]* %5, i64 0, i64 0
%15 = call i32 @permutekey_rev(i32* %13, i32* %14)
%16 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%17 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 0
%18 = call i64 @memcmp(i32* %16, i32* %17, i32 8)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %0
%21 = call i32 @prnlog(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%22 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%23 = call i32 @printarr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32* %22, i32 8)
%24 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 0
%25 = call i32 @printarr(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32* %24, i32 8)
store i32 1, i32* %1
br label %39
26: ; preds = %0
%27 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 0
%28 = getelementptr inbounds [8 x i32], [8 x i32]* %5, i64 0, i64 0
%29 = call i64 @memcmp(i32* %27, i32* %28, i32 8)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %26
%32 = call i32 @prnlog(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%33 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 0
%34 = call i32 @printarr(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32* %33, i32 8)
%35 = getelementptr inbounds [8 x i32], [8 x i32]* %5, i64 0, i64 0
%36 = call i32 @printarr(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32* %35, i32 8)
store i32 1, i32* %1
br label %39
37: ; preds = %26
%38 = call i32 @prnlog(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %1
br label %39
39: ; preds = %37, %31, %20
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@__const._test_iclass_key_permutation.testcase = [8 x i32] [i32 108, i32 141, i32 68, i32 249, i32 42, i32 45, i32 1, i32 191]
@__const._test_iclass_key_permutation.testcase_output_correct = [8 x i32] [i32 138, i32 13, i32 185, i32 136, i32 187, i32 167, i32 144, i32 234]
@.str = [31 x i8] c"Error with iclass key permute!\00"
@.str.1 = [16 x i8] c"testcase_output\00"
@.str.2 = [24 x i8] c"testcase_output_correct\00"
@.str.3 = [38 x i8] c"Error with reverse iclass key permute\00"
@.str.4 = [9 x i8] c"testcase\00"
@.str.5 = [20 x i8] c"testcase_output_rev\00"
@.str.6 = [31 x i8] c"[+] Iclass key permutation OK!\00"
define i32 @_test_iclass_key_permutation() {
%1 = alloca [8 x i32]
%2 = alloca [8 x i32]
%3 = alloca [8 x i32]
%4 = alloca [8 x i32]
%5 = bitcast [8 x i32]* %1 to i8*
%6 = bitcast [8 x i32]* %2 to i8*
%7 = bitcast [8 x i32]* %3 to i8*
%8 = bitcast [8 x i32]* %4 to i8*
%9 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 0, i64 0
%10 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 0
%11 = call i32 @permutekey(i32* %9, i32* %10)
%12 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 0
%13 = call i32 @permutekey_rev(i32* %10, i32* %12)
%14 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%15 = call i64 @memcmp(i32* %10, i32* %14, i32 8)
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %0
%18 = call i32 @prnlog(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @printarr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32* %10, i32 8)
%20 = call i32 @printarr(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32* %14, i32 8)
br label %30
21: ; preds = %0
%22 = call i64 @memcmp(i32* %9, i32* %12, i32 8)
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = call i32 @prnlog(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 @printarr(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32* %9, i32 8)
%27 = call i32 @printarr(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32* %12, i32 8)
br label %30
28: ; preds = %21
%29 = call i32 @prnlog(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
br label %30
30: ; preds = %28, %24, %17
%31 = phi i32 [ 1, %17 ], [ 1, %24 ], [ 0, %28 ]
ret i32 %31
}