#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_dec_aut_step(unsigned char *plaintextblk,
                           const unsigned char *ciphertextblk, __m128i *state) {
  __m128i msg = _mm_load_si128((__m128i *)ciphertextblk);
  __m128i tmp = state[4];
  msg = _mm_xor_si128(msg, _mm_and_si128(state[2], state[3]));
  msg = _mm_xor_si128(msg, state[4]);
  msg = _mm_xor_si128(msg, state[1]);
  _mm_store_si128((__m128i *)plaintextblk, msg);
  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_dec_aut_step>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <_mm_load_si128@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%esi
call   1070 <_mm_and_si128@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%esi
call   1060 <_mm_xor_si128@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%esi
call   1060 <_mm_xor_si128@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%esi
call   1060 <_mm_xor_si128@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%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    -0x20(%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    -0x1c(%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_dec_aut_step>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <_mm_load_si128@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%r14d
mov    0x8(%rbx),%edi
mov    0xc(%rbx),%esi
call   1070 <_mm_and_si128@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1060 <_mm_xor_si128@plt>
mov    0x10(%rbx),%esi
mov    %eax,%edi
call   1060 <_mm_xor_si128@plt>
mov    0x4(%rbx),%esi
mov    %eax,%edi
call   1060 <_mm_xor_si128@plt>
mov    %eax,%ebp
mov    %r15,%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    %ebp,%esi
call   1060 <_mm_xor_si128@plt>
mov    %eax,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @aegis128_dec_aut_step(i8* %0, i8* %1, i32* nocapture %2) {
%4 = bitcast i8* %1 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 = tail call i32 @_mm_xor_si128(i32 %5, i32 %12)
%14 = load i32, i32* %6
%15 = tail call i32 @_mm_xor_si128(i32 %13, i32 %14)
%16 = getelementptr inbounds i32, i32* %2, i64 1
%17 = load i32, i32* %16
%18 = tail call i32 @_mm_xor_si128(i32 %15, i32 %17)
%19 = bitcast i8* %0 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* %16
%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* %16
%32 = tail call i32 @_mm_aesenc_si128(i32 %30, i32 %31)
store i32 %32, i32* %16
%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 %18)
store i32 %35, i32* %2
ret void
}