#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_aesenc_si128(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_and_si128(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_load_si128(int /*<<< orphan*/ *);
int /*<<< orphan*/ _mm_store_si128(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_xor_si128(int /*<<< orphan*/, int /*<<< orphan*/);
void aegis128_enc_aut_step(const unsigned char *plaintextblk,
                           unsigned char *ciphertextblk, __m128i *state) {
  __m128i t, ct;
  __m128i msg = _mm_load_si128((__m128i *)plaintextblk);
  __m128i tmp = state[4];
  t = _mm_and_si128(state[2], state[3]);
  ct = _mm_xor_si128(msg, state[4]);
  ct = _mm_xor_si128(ct, state[1]);
  ct = _mm_xor_si128(ct, t);
  _mm_store_si128((__m128i *)ciphertextblk, ct);
  state[4] = _mm_aesenc_si128(state[3], state[4]);
  state[3] = _mm_aesenc_si128(state[2], state[3]);
  state[2] = _mm_aesenc_si128(state[1], state[2]);
  state[1] = _mm_aesenc_si128(state[0], state[1]);
  state[0] = _mm_aesenc_si128(tmp, state[0]);
  state[0] = _mm_xor_si128(state[0], msg);
}


x86 assembly (clang, -O0):
<aegis128_enc_aut_step>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <_mm_load_si128@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%esi
call   1070 <_mm_and_si128@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%esi
call   1060 <_mm_xor_si128@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%esi
call   1060 <_mm_xor_si128@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1060 <_mm_xor_si128@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1050 <_mm_store_si128@plt>
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%edi
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%esi
call   1040 <_mm_aesenc_si128@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%esi
call   1040 <_mm_aesenc_si128@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%esi
call   1040 <_mm_aesenc_si128@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%esi
call   1040 <_mm_aesenc_si128@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x28(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1040 <_mm_aesenc_si128@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%esi
call   1060 <_mm_xor_si128@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aegis128_enc_aut_step>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r12
call   1030 <_mm_load_si128@plt>
mov    %eax,%r15d
mov    0x10(%rbx),%r14d
mov    0x8(%rbx),%edi
mov    0xc(%rbx),%esi
call   1070 <_mm_and_si128@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%esi
mov    %r15d,%edi
call   1060 <_mm_xor_si128@plt>
mov    0x4(%rbx),%esi
mov    %eax,%edi
call   1060 <_mm_xor_si128@plt>
mov    %eax,%edi
mov    %ebp,%esi
call   1060 <_mm_xor_si128@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   1050 <_mm_store_si128@plt>
mov    0xc(%rbx),%edi
mov    0x10(%rbx),%esi
call   1040 <_mm_aesenc_si128@plt>
mov    %eax,0x10(%rbx)
mov    0x8(%rbx),%edi
mov    0xc(%rbx),%esi
call   1040 <_mm_aesenc_si128@plt>
mov    %eax,0xc(%rbx)
mov    0x4(%rbx),%edi
mov    0x8(%rbx),%esi
call   1040 <_mm_aesenc_si128@plt>
mov    %eax,0x8(%rbx)
mov    (%rbx),%edi
mov    0x4(%rbx),%esi
call   1040 <_mm_aesenc_si128@plt>
mov    %eax,0x4(%rbx)
mov    (%rbx),%esi
mov    %r14d,%edi
call   1040 <_mm_aesenc_si128@plt>
mov    %eax,(%rbx)
mov    %eax,%edi
mov    %r15d,%esi
call   1060 <_mm_xor_si128@plt>
mov    %eax,(%rbx)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @aegis128_enc_aut_step(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
%11 = load i8*, i8** %4
%12 = bitcast i8* %11 to i32*
%13 = call i32 @_mm_load_si128(i32* %12)
store i32 %13, i32* %9
%14 = load i32*, i32** %6
%15 = getelementptr inbounds i32, i32* %14, i64 4
%16 = load i32, i32* %15
store i32 %16, i32* %10
%17 = load i32*, i32** %6
%18 = getelementptr inbounds i32, i32* %17, i64 2
%19 = load i32, i32* %18
%20 = load i32*, i32** %6
%21 = getelementptr inbounds i32, i32* %20, i64 3
%22 = load i32, i32* %21
%23 = call i32 @_mm_and_si128(i32 %19, i32 %22)
store i32 %23, i32* %7
%24 = load i32, i32* %9
%25 = load i32*, i32** %6
%26 = getelementptr inbounds i32, i32* %25, i64 4
%27 = load i32, i32* %26
%28 = call i32 @_mm_xor_si128(i32 %24, i32 %27)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = load i32*, i32** %6
%31 = getelementptr inbounds i32, i32* %30, i64 1
%32 = load i32, i32* %31
%33 = call i32 @_mm_xor_si128(i32 %29, i32 %32)
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = load i32, i32* %7
%36 = call i32 @_mm_xor_si128(i32 %34, i32 %35)
store i32 %36, i32* %8
%37 = load i8*, i8** %5
%38 = bitcast i8* %37 to i32*
%39 = load i32, i32* %8
%40 = call i32 @_mm_store_si128(i32* %38, i32 %39)
%41 = load i32*, i32** %6
%42 = getelementptr inbounds i32, i32* %41, i64 3
%43 = load i32, i32* %42
%44 = load i32*, i32** %6
%45 = getelementptr inbounds i32, i32* %44, i64 4
%46 = load i32, i32* %45
%47 = call i32 @_mm_aesenc_si128(i32 %43, i32 %46)
%48 = load i32*, i32** %6
%49 = getelementptr inbounds i32, i32* %48, i64 4
store i32 %47, i32* %49
%50 = load i32*, i32** %6
%51 = getelementptr inbounds i32, i32* %50, i64 2
%52 = load i32, i32* %51
%53 = load i32*, i32** %6
%54 = getelementptr inbounds i32, i32* %53, i64 3
%55 = load i32, i32* %54
%56 = call i32 @_mm_aesenc_si128(i32 %52, i32 %55)
%57 = load i32*, i32** %6
%58 = getelementptr inbounds i32, i32* %57, i64 3
store i32 %56, i32* %58
%59 = load i32*, i32** %6
%60 = getelementptr inbounds i32, i32* %59, i64 1
%61 = load i32, i32* %60
%62 = load i32*, i32** %6
%63 = getelementptr inbounds i32, i32* %62, i64 2
%64 = load i32, i32* %63
%65 = call i32 @_mm_aesenc_si128(i32 %61, i32 %64)
%66 = load i32*, i32** %6
%67 = getelementptr inbounds i32, i32* %66, i64 2
store i32 %65, i32* %67
%68 = load i32*, i32** %6
%69 = getelementptr inbounds i32, i32* %68, i64 0
%70 = load i32, i32* %69
%71 = load i32*, i32** %6
%72 = getelementptr inbounds i32, i32* %71, i64 1
%73 = load i32, i32* %72
%74 = call i32 @_mm_aesenc_si128(i32 %70, i32 %73)
%75 = load i32*, i32** %6
%76 = getelementptr inbounds i32, i32* %75, i64 1
store i32 %74, i32* %76
%77 = load i32, i32* %10
%78 = load i32*, i32** %6
%79 = getelementptr inbounds i32, i32* %78, i64 0
%80 = load i32, i32* %79
%81 = call i32 @_mm_aesenc_si128(i32 %77, i32 %80)
%82 = load i32*, i32** %6
%83 = getelementptr inbounds i32, i32* %82, i64 0
store i32 %81, i32* %83
%84 = load i32*, i32** %6
%85 = getelementptr inbounds i32, i32* %84, i64 0
%86 = load i32, i32* %85
%87 = load i32, i32* %9
%88 = call i32 @_mm_xor_si128(i32 %86, i32 %87)
%89 = load i32*, i32** %6
%90 = getelementptr inbounds i32, i32* %89, i64 0
store i32 %88, i32* %90
ret void
}

LLVM IR (-O2):
define void @aegis128_enc_aut_step(i8* %0, i8* %1, i32* nocapture %2) {
%4 = bitcast i8* %0 to i32*
%5 = tail call i32 @_mm_load_si128(i32* %4)
%6 = getelementptr inbounds i32, i32* %2, i64 4
%7 = load i32, i32* %6
%8 = getelementptr inbounds i32, i32* %2, i64 2
%9 = load i32, i32* %8
%10 = getelementptr inbounds i32, i32* %2, i64 3
%11 = load i32, i32* %10
%12 = tail call i32 @_mm_and_si128(i32 %9, i32 %11)
%13 = load i32, i32* %6
%14 = tail call i32 @_mm_xor_si128(i32 %5, i32 %13)
%15 = getelementptr inbounds i32, i32* %2, i64 1
%16 = load i32, i32* %15
%17 = tail call i32 @_mm_xor_si128(i32 %14, i32 %16)
%18 = tail call i32 @_mm_xor_si128(i32 %17, i32 %12)
%19 = bitcast i8* %1 to i32*
%20 = tail call i32 @_mm_store_si128(i32* %19, i32 %18)
%21 = load i32, i32* %10
%22 = load i32, i32* %6
%23 = tail call i32 @_mm_aesenc_si128(i32 %21, i32 %22)
store i32 %23, i32* %6
%24 = load i32, i32* %8
%25 = load i32, i32* %10
%26 = tail call i32 @_mm_aesenc_si128(i32 %24, i32 %25)
store i32 %26, i32* %10
%27 = load i32, i32* %15
%28 = load i32, i32* %8
%29 = tail call i32 @_mm_aesenc_si128(i32 %27, i32 %28)
store i32 %29, i32* %8
%30 = load i32, i32* %2
%31 = load i32, i32* %15
%32 = tail call i32 @_mm_aesenc_si128(i32 %30, i32 %31)
store i32 %32, i32* %15
%33 = load i32, i32* %2
%34 = tail call i32 @_mm_aesenc_si128(i32 %7, i32 %33)
store i32 %34, i32* %2
%35 = tail call i32 @_mm_xor_si128(i32 %34, i32 %5)
store i32 %35, i32* %2
ret void
}