#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 /*<<< orphan*/ __m128i;

/* Variables and functions */
int /*<<< orphan*/
_mm_set_epi8(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
             int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
             int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
             int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
             int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ _mm_srli_si128(int /*<<< orphan*/, int);
int /*<<< orphan*/ _mm_store_si128(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_xor_si128(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ aes_enc_128(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int jambu_tag_verification(__m128i *key, unsigned long long mlen,
                           const unsigned char *c, __m128i *stateS,
                           __m128i *stateR) {
  unsigned char t[16];
  int check = 0;
  int i;
  __m128i c3 = _mm_set_epi8(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3);
  __m128i tmpT;
  aes_enc_128(stateS, key);
  *stateS = _mm_xor_si128(*stateS, _mm_srli_si128(*stateR, 8));
  *stateS = _mm_xor_si128(*stateS, c3);
  *stateR = _mm_xor_si128(*stateR, *stateS);
  aes_enc_128(stateS, key);
  tmpT = _mm_srli_si128(_mm_xor_si128(*stateS, *stateR), 8);
  tmpT = _mm_xor_si128(tmpT, *stateS);
  _mm_store_si128((__m128i *)t, tmpT);
  for (i = 0; i < 8; i++)
    check |= (c[mlen + i] ^ t[i]);
  if (0 == check)
    return 0;
  else
    return -1;
}


x86 assembly (clang, -O0):
<jambu_tag_verification>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x0,-0x44(%rbp)
xor    %r9d,%r9d
mov    %r9d,%edi
mov    %r9d,%esi
mov    %r9d,%edx
mov    %r9d,%ecx
mov    %r9d,%r8d
movl   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0x18(%rsp)
movl   $0x0,0x20(%rsp)
movl   $0x0,0x28(%rsp)
movl   $0x0,0x30(%rsp)
movl   $0x0,0x38(%rsp)
movl   $0x0,0x40(%rsp)
movl   $0x3,0x48(%rsp)
call   1060 <_mm_set_epi8@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <aes_enc_128@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
mov    $0x8,%esi
call   1040 <_mm_srli_si128@plt>
mov    -0x54(%rbp),%edi
mov    %eax,%esi
call   1070 <_mm_xor_si128@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
mov    -0x4c(%rbp),%esi
call   1070 <_mm_xor_si128@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
call   1070 <_mm_xor_si128@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <aes_enc_128@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
call   1070 <_mm_xor_si128@plt>
mov    %eax,%edi
mov    $0x8,%esi
call   1040 <_mm_srli_si128@plt>
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%edi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
call   1070 <_mm_xor_si128@plt>
mov    %eax,-0x50(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%esi
call   1050 <_mm_store_si128@plt>
movl   $0x0,-0x48(%rbp)
cmpl   $0x8,-0x48(%rbp)
jge    12d3 <jambu_tag_verification+0x183>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq -0x48(%rbp),%rdx
add    %rdx,%rcx
movzbl (%rax,%rcx,1),%eax
movslq -0x48(%rbp),%rcx
movzbl -0x40(%rbp,%rcx,1),%ecx
xor    %ecx,%eax
or     -0x44(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1297 <jambu_tag_verification+0x147>
xor    %eax,%eax
cmp    -0x44(%rbp),%eax
jne    12ea <jambu_tag_verification+0x19a>
movl   $0x0,-0x4(%rbp)
jmp    12f1 <jambu_tag_verification+0x1a1>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jambu_tag_verification>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%r12
mov    %rcx,%rbx
mov    %rdx,0x8(%rsp)
mov    %rsi,%r15
mov    %rdi,%r13
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   $0x3
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   $0x0
call   1060 <_mm_set_epi8@plt>
add    $0x50,%rsp
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <aes_enc_128@plt>
mov    (%rbx),%r14d
mov    (%r12),%edi
mov    $0x8,%esi
call   1040 <_mm_srli_si128@plt>
mov    %r14d,%edi
mov    %eax,%esi
call   1070 <_mm_xor_si128@plt>
mov    %eax,(%rbx)
mov    %eax,%edi
mov    %ebp,%esi
call   1070 <_mm_xor_si128@plt>
mov    %eax,(%rbx)
mov    (%r12),%edi
mov    %eax,%esi
call   1070 <_mm_xor_si128@plt>
mov    %eax,(%r12)
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <aes_enc_128@plt>
mov    (%rbx),%edi
mov    (%r12),%esi
call   1070 <_mm_xor_si128@plt>
mov    %eax,%edi
mov    $0x8,%esi
call   1040 <_mm_srli_si128@plt>
mov    (%rbx),%esi
mov    %eax,%edi
call   1070 <_mm_xor_si128@plt>
lea    0x10(%rsp),%rdi
mov    %eax,%esi
call   1050 <_mm_store_si128@plt>
mov    0x10(%rsp),%rax
mov    0x8(%rsp),%rcx
xor    (%rcx,%r15,1),%rax
neg    %rax
sbb    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @jambu_tag_verification(i32* %0, i64 %1, i8* %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca [16 x i8]
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32* %0, i32** %7
store i64 %1, i64* %8
store i8* %2, i8** %9
store i32* %3, i32** %10
store i32* %4, i32** %11
store i32 0, i32* %13
%17 = call i32 @_mm_set_epi8(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 3)
store i32 %17, i32* %15
%18 = load i32*, i32** %10
%19 = load i32*, i32** %7
%20 = call i32 @aes_enc_128(i32* %18, i32* %19)
%21 = load i32*, i32** %10
%22 = load i32, i32* %21
%23 = load i32*, i32** %11
%24 = load i32, i32* %23
%25 = call i32 @_mm_srli_si128(i32 %24, i32 8)
%26 = call i32 @_mm_xor_si128(i32 %22, i32 %25)
%27 = load i32*, i32** %10
store i32 %26, i32* %27
%28 = load i32*, i32** %10
%29 = load i32, i32* %28
%30 = load i32, i32* %15
%31 = call i32 @_mm_xor_si128(i32 %29, i32 %30)
%32 = load i32*, i32** %10
store i32 %31, i32* %32
%33 = load i32*, i32** %11
%34 = load i32, i32* %33
%35 = load i32*, i32** %10
%36 = load i32, i32* %35
%37 = call i32 @_mm_xor_si128(i32 %34, i32 %36)
%38 = load i32*, i32** %11
store i32 %37, i32* %38
%39 = load i32*, i32** %10
%40 = load i32*, i32** %7
%41 = call i32 @aes_enc_128(i32* %39, i32* %40)
%42 = load i32*, i32** %10
%43 = load i32, i32* %42
%44 = load i32*, i32** %11
%45 = load i32, i32* %44
%46 = call i32 @_mm_xor_si128(i32 %43, i32 %45)
%47 = call i32 @_mm_srli_si128(i32 %46, i32 8)
store i32 %47, i32* %16
%48 = load i32, i32* %16
%49 = load i32*, i32** %10
%50 = load i32, i32* %49
%51 = call i32 @_mm_xor_si128(i32 %48, i32 %50)
store i32 %51, i32* %16
%52 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%53 = bitcast i8* %52 to i32*
%54 = load i32, i32* %16
%55 = call i32 @_mm_store_si128(i32* %53, i32 %54)
store i32 0, i32* %14
br label %56
56: ; preds = %76, %5
%57 = load i32, i32* %14
%58 = icmp slt i32 %57, 8
br i1 %58, label %59, label %79
59: ; preds = %56
%60 = load i8*, i8** %9
%61 = load i64, i64* %8
%62 = load i32, i32* %14
%63 = sext i32 %62 to i64
%64 = add i64 %61, %63
%65 = getelementptr inbounds i8, i8* %60, i64 %64
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = load i32, i32* %14
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 %69
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = xor i32 %67, %72
%74 = load i32, i32* %13
%75 = or i32 %74, %73
store i32 %75, i32* %13
br label %76
76: ; preds = %59
%77 = load i32, i32* %14
%78 = add nsw i32 %77, 1
store i32 %78, i32* %14
br label %56
79: ; preds = %56
%80 = load i32, i32* %13
%81 = icmp eq i32 0, %80
br i1 %81, label %82, label %83
82: ; preds = %79
store i32 0, i32* %6
br label %84
83: ; preds = %79
store i32 -1, i32* %6
br label %84
84: ; preds = %83, %82
%85 = load i32, i32* %6
ret i32 %85
}

LLVM IR (-O2):
define i32 @jambu_tag_verification(i32* %0, i64 %1, i8* nocapture %2, i32* %3, i32* nocapture %4) {
%6 = alloca [16 x i8]
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%8 = tail call i32 @_mm_set_epi8(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 3)
%9 = tail call i32 @aes_enc_128(i32* %3, i32* %0)
%10 = load i32, i32* %3
%11 = load i32, i32* %4
%12 = tail call i32 @_mm_srli_si128(i32 %11, i32 8)
%13 = tail call i32 @_mm_xor_si128(i32 %10, i32 %12)
store i32 %13, i32* %3
%14 = tail call i32 @_mm_xor_si128(i32 %13, i32 %8)
store i32 %14, i32* %3
%15 = load i32, i32* %4
%16 = tail call i32 @_mm_xor_si128(i32 %15, i32 %14)
store i32 %16, i32* %4
%17 = tail call i32 @aes_enc_128(i32* %3, i32* %0)
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = tail call i32 @_mm_xor_si128(i32 %18, i32 %19)
%21 = tail call i32 @_mm_srli_si128(i32 %20, i32 8)
%22 = load i32, i32* %3
%23 = tail call i32 @_mm_xor_si128(i32 %21, i32 %22)
%24 = bitcast [16 x i8]* %6 to i32*
%25 = call i32 @_mm_store_si128(i32* %24, i32 %23)
%26 = getelementptr inbounds i8, i8* %2, i64 %1
%27 = bitcast i8* %26 to <8 x i8>*
%28 = load <8 x i8>, <8 x i8>* %27
%29 = bitcast [16 x i8]* %6 to <8 x i8>*
%30 = load <8 x i8>, <8 x i8>* %29
%31 = xor <8 x i8> %30, %28
%32 = call i8 @llvm.vector.reduce.or.v8i8(<8 x i8> %31)
%33 = icmp ne i8 %32, 0
%34 = sext i1 %33 to i32
ret i32 %34
}