#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 /*<<< orphan*/);
int /*<<< orphan*/ _mm_srli_si128(int /*<<< orphan*/, int);
int /*<<< orphan*/ _mm_storel_epi64(int /*<<< orphan*/ *, int /*<<< orphan*/);
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_enc_aut_msg_partial(__m128i *key, const unsigned char *plaintextblk,
                               unsigned char *ciphertextblk, __m128i *stateS,
                               __m128i *stateR, unsigned long len) {
  __m128i msgtmp;
  __m128i tmp;
  unsigned char p[8];
  memcpy(p, plaintextblk, 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);
  tmp = _mm_srli_si128(msgtmp, 8);
  aes_enc_128(stateS, key);
  *stateS = _mm_xor_si128(*stateS, _mm_srli_si128(*stateR, 8));
  *stateS = _mm_xor_si128(*stateS, msgtmp);
  tmp = _mm_xor_si128(tmp, *stateS);
  _mm_storel_epi64((__m128i *)ciphertextblk, tmp);
  *stateR = _mm_xor_si128(*stateS, *stateR);
}


x86 assembly (clang, -O0):
<jambu_enc_aut_msg_partial>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1070 <memcpy@plt>
mov    -0x30(%rbp),%rax
movb   $0x80,-0x40(%rbp,%rax,1)
cmpq   $0x7,-0x30(%rbp)
jae    11d9 <jambu_enc_aut_msg_partial+0x69>
lea    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rax
add    $0x1,%rax
add    %rax,%rdi
mov    $0x7,%eax
sub    -0x30(%rbp),%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x39(%rbp),%dil
mov    -0x3a(%rbp),%sil
mov    -0x3b(%rbp),%dl
mov    -0x3c(%rbp),%cl
mov    -0x3d(%rbp),%r8b
mov    -0x3e(%rbp),%r9b
mov    -0x3f(%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 -0x40(%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,-0x34(%rbp)
mov    -0x34(%rbp),%edi
mov    $0x8,%esi
call   1050 <_mm_srli_si128@plt>
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <aes_enc_128@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
mov    $0x8,%esi
call   1050 <_mm_srli_si128@plt>
mov    -0x44(%rbp),%edi
mov    %eax,%esi
call   1090 <_mm_xor_si128@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    -0x34(%rbp),%esi
call   1090 <_mm_xor_si128@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
call   1090 <_mm_xor_si128@plt>
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%esi
call   1080 <_mm_storel_epi64@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
call   1090 <_mm_xor_si128@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jambu_enc_aut_msg_partial>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%rbx
mov    %r8,%r14
mov    %rcx,%r13
mov    %rdx,0x10(%rsp)
mov    %rdi,%r12
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    %r9,%rdx
call   1070 <memcpy@plt>
movb   $0x80,0x8(%rsp,%rbx,1)
cmp    $0x6,%rbx
ja     11c0 <jambu_enc_aut_msg_partial+0x50>
lea    (%rbx,%rbp,1),%rdi
add    $0x1,%rdi
mov    $0x7,%edx
sub    %ebx,%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,%ebx
mov    %eax,%edi
mov    $0x8,%esi
call   1050 <_mm_srli_si128@plt>
mov    %eax,%r15d
mov    %r13,%rdi
mov    %r12,%rsi
call   1030 <aes_enc_128@plt>
mov    0x0(%r13),%ebp
mov    (%r14),%edi
mov    $0x8,%esi
call   1050 <_mm_srli_si128@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1090 <_mm_xor_si128@plt>
mov    %eax,0x0(%r13)
mov    %eax,%edi
mov    %ebx,%esi
call   1090 <_mm_xor_si128@plt>
mov    %eax,0x0(%r13)
mov    %r15d,%edi
mov    %eax,%esi
call   1090 <_mm_xor_si128@plt>
mov    0x10(%rsp),%rdi
mov    %eax,%esi
call   1080 <_mm_storel_epi64@plt>
mov    0x0(%r13),%edi
mov    (%r14),%esi
call   1090 <_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_enc_aut_msg_partial(i32* %0, i8* %1, i8* %2, i32* %3, i32* %4, i64 %5) {
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
%15 = alloca [8 x i8]
store i32* %0, i32** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32* %3, i32** %10
store i32* %4, i32** %11
store i64 %5, i64* %12
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %15, i64 0, i64 0
%17 = load i8*, i8** %8
%18 = load i64, i64* %12
%19 = call i32 @memcpy(i8* %16, i8* %17, i64 %18)
%20 = load i64, i64* %12
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %15, i64 0, i64 %20
store i8 -128, i8* %21
%22 = load i64, i64* %12
%23 = icmp ult i64 %22, 7
br i1 %23, label %24, label %33
24: ; preds = %6
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %15, i64 0, i64 0
%26 = load i64, i64* %12
%27 = add i64 %26, 1
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i64, i64* %12
%30 = sub i64 7, %29
%31 = trunc i64 %30 to i32
%32 = call i32 @memset(i8* %28, i32 0, i32 %31)
br label %33
33: ; preds = %24, %6
%34 = getelementptr inbounds [8 x i8], [8 x i8]* %15, i64 0, i64 7
%35 = load i8, i8* %34
%36 = getelementptr inbounds [8 x i8], [8 x i8]* %15, i64 0, i64 6
%37 = load i8, i8* %36
%38 = getelementptr inbounds [8 x i8], [8 x i8]* %15, i64 0, i64 5
%39 = load i8, i8* %38
%40 = getelementptr inbounds [8 x i8], [8 x i8]* %15, i64 0, i64 4
%41 = load i8, i8* %40
%42 = getelementptr inbounds [8 x i8], [8 x i8]* %15, i64 0, i64 3
%43 = load i8, i8* %42
%44 = getelementptr inbounds [8 x i8], [8 x i8]* %15, i64 0, i64 2
%45 = load i8, i8* %44
%46 = getelementptr inbounds [8 x i8], [8 x i8]* %15, i64 0, i64 1
%47 = load i8, i8* %46
%48 = getelementptr inbounds [8 x i8], [8 x i8]* %15, i64 0, i64 0
%49 = load i8, i8* %48
%50 = call i32 @_mm_set_epi8(i8 zeroext %35, i8 zeroext %37, i8 zeroext %39, i8 zeroext %41, i8 zeroext %43, i8 zeroext %45, i8 zeroext %47, i8 zeroext %49, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0)
store i32 %50, i32* %13
%51 = load i32, i32* %13
%52 = call i32 @_mm_srli_si128(i32 %51, i32 8)
store i32 %52, i32* %14
%53 = load i32*, i32** %10
%54 = load i32*, i32** %7
%55 = call i32 @aes_enc_128(i32* %53, i32* %54)
%56 = load i32*, i32** %10
%57 = load i32, i32* %56
%58 = load i32*, i32** %11
%59 = load i32, i32* %58
%60 = call i32 @_mm_srli_si128(i32 %59, i32 8)
%61 = call i32 @_mm_xor_si128(i32 %57, i32 %60)
%62 = load i32*, i32** %10
store i32 %61, i32* %62
%63 = load i32*, i32** %10
%64 = load i32, i32* %63
%65 = load i32, i32* %13
%66 = call i32 @_mm_xor_si128(i32 %64, i32 %65)
%67 = load i32*, i32** %10
store i32 %66, i32* %67
%68 = load i32, i32* %14
%69 = load i32*, i32** %10
%70 = load i32, i32* %69
%71 = call i32 @_mm_xor_si128(i32 %68, i32 %70)
store i32 %71, i32* %14
%72 = load i8*, i8** %9
%73 = bitcast i8* %72 to i32*
%74 = load i32, i32* %14
%75 = call i32 @_mm_storel_epi64(i32* %73, i32 %74)
%76 = load i32*, i32** %10
%77 = load i32, i32* %76
%78 = load i32*, i32** %11
%79 = load i32, i32* %78
%80 = call i32 @_mm_xor_si128(i32 %77, i32 %79)
%81 = load i32*, i32** %11
store i32 %80, i32* %81
ret void
}

LLVM IR (-O2):
define void @jambu_enc_aut_msg_partial(i32* %0, i8* %1, i8* %2, i32* %3, i32* nocapture %4, i64 %5) {
%7 = alloca [8 x i8]
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%9 = call i32 @memcpy(i8* %8, i8* %1, i64 %5)
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 %5
store i8 -128, i8* %10
%11 = icmp ult i64 %5, 7
br i1 %11, label %12, label %18
12: ; preds = %6
%13 = add nuw nsw i64 %5, 1
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 %13
%15 = trunc i64 %5 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, %6
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 7
%20 = load i8, i8* %19
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 6
%22 = load i8, i8* %21
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 5
%24 = load i8, i8* %23
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 4
%26 = load i8, i8* %25
%27 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 3
%28 = load i8, i8* %27
%29 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 2
%30 = load i8, i8* %29
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %7, 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 @_mm_srli_si128(i32 %34, i32 8)
%36 = call i32 @aes_enc_128(i32* %3, i32* %0)
%37 = load i32, i32* %3
%38 = load i32, i32* %4
%39 = call i32 @_mm_srli_si128(i32 %38, i32 8)
%40 = call i32 @_mm_xor_si128(i32 %37, i32 %39)
store i32 %40, i32* %3
%41 = call i32 @_mm_xor_si128(i32 %40, i32 %34)
store i32 %41, i32* %3
%42 = call i32 @_mm_xor_si128(i32 %35, i32 %41)
%43 = bitcast i8* %2 to i32*
%44 = call i32 @_mm_storel_epi64(i32* %43, i32 %42)
%45 = load i32, i32* %3
%46 = load i32, i32* %4
%47 = call i32 @_mm_xor_si128(i32 %45, i32 %46)
store i32 %47, i32* %4
ret void
}