#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(unsigned char, unsigned char, unsigned char,
                                unsigned char, unsigned char, unsigned char,
                                unsigned char, unsigned char,
                                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_xor_si128(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ aes_enc_128(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *,
                          unsigned long);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
void jambu_aut_ad_partial(__m128i *key, const unsigned char *adblock,
                          __m128i *stateS, __m128i *stateR, unsigned long len) {
  __m128i msgtmp;
  __m128i c1 = _mm_set_epi8(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
  unsigned char p[8];
  memcpy(p, adblock, len);
  p[len] = 0x80;
  if (len < 7)
    memset(p + (len + 1), 0, 7 - len);
  msgtmp = _mm_set_epi8(p[7], p[6], p[5], p[4], p[3], p[2], p[1], p[0], 0, 0, 0,
                        0, 0, 0, 0, 0);
  aes_enc_128(stateS, key);
  *stateS = _mm_xor_si128(*stateS, _mm_srli_si128(*stateR, 8));
  *stateS = _mm_xor_si128(*stateS, c1);
  *stateS = _mm_xor_si128(*stateS, msgtmp);
  *stateR = _mm_xor_si128(*stateS, *stateR);
  return;
}


x86 assembly (clang, -O0):
<jambu_aut_ad_partial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%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   $0x1,0x48(%rsp)
call   1060 <_mm_set_epi8@plt>
mov    %eax,-0x30(%rbp)
lea    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1070 <memcpy@plt>
mov    -0x28(%rbp),%rax
movb   $0x80,-0x38(%rbp,%rax,1)
cmpq   $0x7,-0x28(%rbp)
jae    122e <jambu_aut_ad_partial+0xce>
lea    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rax
add    $0x1,%rax
add    %rax,%rdi
mov    $0x7,%eax
sub    -0x28(%rbp),%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x31(%rbp),%dil
mov    -0x32(%rbp),%sil
mov    -0x33(%rbp),%dl
mov    -0x34(%rbp),%cl
mov    -0x35(%rbp),%r8b
mov    -0x36(%rbp),%r9b
mov    -0x37(%rbp),%al
xor    %r10d,%r10d
movzbl %dil,%edi
movzbl %sil,%esi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl %r9b,%r9d
movzbl %al,%eax
mov    %eax,(%rsp)
movzbl -0x38(%rbp),%eax
mov    %eax,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   $0x0,0x48(%rsp)
call   1060 <_mm_set_epi8@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <aes_enc_128@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    $0x8,%esi
call   1050 <_mm_srli_si128@plt>
mov    -0x3c(%rbp),%edi
mov    %eax,%esi
call   1080 <_mm_xor_si128@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%esi
call   1080 <_mm_xor_si128@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%esi
call   1080 <_mm_xor_si128@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
call   1080 <_mm_xor_si128@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jambu_aut_ad_partial>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%rbp
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%r13
mov    %rdi,0x10(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   $0x1
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,%r12d
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1070 <memcpy@plt>
movb   $0x80,0x8(%rsp,%rbp,1)
cmp    $0x6,%rbp
ja     11e1 <jambu_aut_ad_partial+0x81>
lea    (%r15,%rbp,1),%rdi
add    $0x1,%rdi
mov    $0x7,%edx
sub    %ebp,%edx
xor    %esi,%esi
call   1040 <memset@plt>
movzbl 0xf(%rsp),%edi
movzbl 0xe(%rsp),%esi
movzbl 0xd(%rsp),%edx
movzbl 0xc(%rsp),%ecx
movzbl 0xb(%rsp),%r8d
movzbl 0xa(%rsp),%r9d
movzbl 0x9(%rsp),%eax
movzbl 0x8(%rsp),%ebp
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   %rbp
push   %rax
call   1060 <_mm_set_epi8@plt>
add    $0x50,%rsp
mov    %eax,%r15d
mov    %rbx,%rdi
mov    0x10(%rsp),%rsi
call   1030 <aes_enc_128@plt>
mov    (%rbx),%ebp
mov    (%r14),%edi
mov    $0x8,%esi
call   1050 <_mm_srli_si128@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1080 <_mm_xor_si128@plt>
mov    %eax,(%rbx)
mov    %eax,%edi
mov    %r12d,%esi
call   1080 <_mm_xor_si128@plt>
mov    %eax,(%rbx)
mov    %eax,%edi
mov    %r15d,%esi
call   1080 <_mm_xor_si128@plt>
mov    %eax,(%rbx)
mov    (%r14),%esi
mov    %eax,%edi
call   1080 <_mm_xor_si128@plt>
mov    %eax,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @jambu_aut_ad_partial(i32* %0, i8* %1, i32* %2, i32* nocapture %3, i64 %4) {
%6 = alloca [8 x i8]
%7 = tail call i32 @_mm_set_epi8(i8 zeroext 0, i8 zeroext 0, i8 zeroext 0, i8 zeroext 0, i8 zeroext 0, i8 zeroext 0, i8 zeroext 0, i8 zeroext 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 1)
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%9 = call i32 @memcpy(i8* %8, i8* %1, i64 %4)
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 %4
store i8 -128, i8* %10
%11 = icmp ult i64 %4, 7
br i1 %11, label %12, label %18
12: ; preds = %5
%13 = add nuw nsw i64 %4, 1
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 %13
%15 = trunc i64 %4 to i32
%16 = sub nuw nsw i32 7, %15
%17 = call i32 @memset(i8* %14, i32 0, i32 %16)
br label %18
18: ; preds = %12, %5
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 7
%20 = load i8, i8* %19
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 6
%22 = load i8, i8* %21
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 5
%24 = load i8, i8* %23
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 4
%26 = load i8, i8* %25
%27 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 3
%28 = load i8, i8* %27
%29 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 2
%30 = load i8, i8* %29
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 1
%32 = load i8, i8* %31
%33 = load i8, i8* %8
%34 = call i32 @_mm_set_epi8(i8 zeroext %20, i8 zeroext %22, i8 zeroext %24, i8 zeroext %26, i8 zeroext %28, i8 zeroext %30, i8 zeroext %32, i8 zeroext %33, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0)
%35 = call i32 @aes_enc_128(i32* %2, i32* %0)
%36 = load i32, i32* %2
%37 = load i32, i32* %3
%38 = call i32 @_mm_srli_si128(i32 %37, i32 8)
%39 = call i32 @_mm_xor_si128(i32 %36, i32 %38)
store i32 %39, i32* %2
%40 = call i32 @_mm_xor_si128(i32 %39, i32 %7)
store i32 %40, i32* %2
%41 = call i32 @_mm_xor_si128(i32 %40, i32 %34)
store i32 %41, i32* %2
%42 = load i32, i32* %3
%43 = call i32 @_mm_xor_si128(i32 %41, i32 %42)
store i32 %43, i32* %3
ret void
}