#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 */
int /*<<< orphan*/ doMAC(int *, int, int *, int *);
scalar_t__ memcmp(int *, int *, int);
int /*<<< orphan*/ printarr(char *, int *, int);
int /*<<< orphan*/ prnlog(char *);
int testMAC() {
  prnlog("[+] Testing MAC calculation...");
  uint8_t cc_nr[] = {0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
                     0xFF, 0xFF, 0,    0,    0,    0};
  uint8_t div_key[8] = {0xE0, 0x33, 0xCA, 0x41, 0x9A, 0xEE, 0x43, 0xF9};
  uint8_t correct_MAC[4] = {0x1d, 0x49, 0xC9, 0xDA};
  uint8_t calculated_mac[4] = {0};
  doMAC(cc_nr, 12, div_key, calculated_mac);
  if (memcmp(calculated_mac, correct_MAC, 4) == 0) {
    prnlog("[+] MAC calculation OK!");
  } else {
    prnlog("[+] FAILED: MAC calculation failed:");
    printarr("    Calculated_MAC", calculated_mac, 4);
    printarr("    Correct_MAC   ", correct_MAC, 4);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<testMAC>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    0xe8e(%rip),%rdi
call   1040 <prnlog@plt>
lea    -0x40(%rbp),%rdi
lea    0xf0e(%rip),%rsi
mov    $0x30,%edx
call   1070 <memcpy@plt>
mov    0xf2d(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xf2a(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0xf27(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xf24(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xf21(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    0xf1e(%rip),%rax
mov    %rax,-0x68(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    -0x80(%rbp),%rcx
mov    $0xc,%esi
call   1030 <doMAC@plt>
lea    -0x80(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x4,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
jne    1221 <testMAC+0xc1>
lea    0xe08(%rip),%rdi
call   1040 <prnlog@plt>
jmp    1263 <testMAC+0x103>
lea    0xe0f(%rip),%rdi
call   1040 <prnlog@plt>
lea    -0x80(%rbp),%rsi
lea    0xe23(%rip),%rdi
mov    $0x4,%edx
call   1080 <printarr@plt>
lea    -0x70(%rbp),%rsi
lea    0xe21(%rip),%rdi
mov    $0x4,%edx
call   1080 <printarr@plt>
movl   $0x1,-0x4(%rbp)
jmp    126a <testMAC+0x10a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testMAC>:
push   %rbx
sub    $0x70,%rsp
lea    0xeb4(%rip),%rdi
call   1040 <prnlog@plt>
movaps 0xf58(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xf3c(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xf20(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xf54(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xf38(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xf4c(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
lea    0x40(%rsp),%rdi
lea    0x20(%rsp),%rdx
mov    %rsp,%rbx
mov    $0xc,%esi
mov    %rbx,%rcx
call   1030 <doMAC@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     120e <testMAC+0xce>
lea    0xe5f(%rip),%rdi
call   1040 <prnlog@plt>
lea    0xe77(%rip),%rdi
mov    %rsp,%rsi
mov    $0x4,%edx
call   1060 <printarr@plt>
lea    0xe76(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    $0x4,%edx
call   1060 <printarr@plt>
mov    $0x1,%eax
jmp    121c <testMAC+0xdc>
lea    0xe0a(%rip),%rdi
call   1040 <prnlog@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [31 x i8] c"[+] Testing MAC calculation...\00"
@__const.testMAC.cc_nr = [12 x i32] [i32 254, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 0, i32 0, i32 0, i32 0]
@__const.testMAC.div_key = [8 x i32] [i32 224, i32 51, i32 202, i32 65, i32 154, i32 238, i32 67, i32 249]
@__const.testMAC.correct_MAC = [4 x i32] [i32 29, i32 73, i32 201, i32 218]
@.str.1 = [24 x i8] c"[+] MAC calculation OK!\00"
@.str.2 = [36 x i8] c"[+] FAILED: MAC calculation failed:\00"
@.str.3 = [19 x i8] c" Calculated_MAC\00"
@.str.4 = [19 x i8] c" Correct_MAC \00"
define i32 @testMAC() {
%1 = alloca i32
%2 = alloca [12 x i32]
%3 = alloca [8 x i32]
%4 = alloca [4 x i32]
%5 = alloca [4 x i32]
%6 = call i32 @prnlog(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%7 = bitcast [12 x i32]* %2 to i8*
%8 = bitcast [8 x i32]* %3 to i8*
%9 = bitcast [4 x i32]* %4 to i8*
%10 = bitcast [4 x i32]* %5 to i8*
%11 = getelementptr inbounds [12 x i32], [12 x i32]* %2, i64 0, i64 0
%12 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%13 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
%14 = call i32 @doMAC(i32* %11, i32 12, i32* %12, i32* %13)
%15 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
%16 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%17 = call i64 @memcmp(i32* %15, i32* %16, i32 4)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %0
%20 = call i32 @prnlog(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %27
21: ; preds = %0
%22 = call i32 @prnlog(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%23 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
%24 = call i32 @printarr(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32* %23, i32 4)
%25 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%26 = call i32 @printarr(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32* %25, i32 4)
store i32 1, i32* %1
br label %28
27: ; preds = %19
store i32 0, i32* %1
br label %28
28: ; preds = %27, %21
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@.str = [31 x i8] c"[+] Testing MAC calculation...\00"
@__const.testMAC.cc_nr = [12 x i32] [i32 254, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 0, i32 0, i32 0, i32 0]
@__const.testMAC.div_key = [8 x i32] [i32 224, i32 51, i32 202, i32 65, i32 154, i32 238, i32 67, i32 249]
@__const.testMAC.correct_MAC = [4 x i32] [i32 29, i32 73, i32 201, i32 218]
@.str.1 = [24 x i8] c"[+] MAC calculation OK!\00"
@.str.2 = [36 x i8] c"[+] FAILED: MAC calculation failed:\00"
@.str.3 = [19 x i8] c" Calculated_MAC\00"
@.str.4 = [19 x i8] c" Correct_MAC \00"
define i32 @testMAC() {
%1 = alloca [12 x i32]
%2 = alloca [8 x i32]
%3 = alloca [4 x i32]
%4 = alloca [4 x i32]
%5 = tail call i32 @prnlog(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%6 = bitcast [12 x i32]* %1 to i8*
%7 = bitcast [8 x i32]* %2 to i8*
%8 = bitcast [4 x i32]* %3 to i8*
%9 = bitcast [4 x i32]* %4 to i8*
%10 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 0
%11 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 0
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%13 = call i32 @doMAC(i32* %10, i32 12, i32* %11, i32* %12)
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%15 = call i64 @memcmp(i32* %12, i32* %14, i32 4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %0
%18 = call i32 @prnlog(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %23
19: ; preds = %0
%20 = call i32 @prnlog(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @printarr(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32* %12, i32 4)
%22 = call i32 @printarr(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32* %14, i32 4)
br label %23
23: ; preds = %17, %19
%24 = phi i32 [ 0, %17 ], [ 1, %19 ]
ret i32 %24
}