#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 unsigned long long uint64_t;
typedef int /*<<< orphan*/ __m128i;

/* Variables and functions */
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*/);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ morus_stateupdate(int /*<<< orphan*/, int /*<<< orphan*/ *);
void morus_tag_generation(unsigned long long msglen, unsigned long long adlen,
                          unsigned char *c, __m128i *state) {
  int i;
  unsigned char t[16];
  __m128i tmp;
  _mm_store_si128((__m128i *)t, state[3]);
  ((uint64_t *)t)[0] ^= (adlen << 3);
  ((uint64_t *)t)[1] ^= (msglen << 3);
  state[4] = _mm_xor_si128((state[4]), (state[0]));
  tmp = _mm_load_si128((__m128i *)t);
  for (i = 0; i < 8; i++)
    morus_stateupdate(tmp, state);
  for (i = 2; i < 5; i++)
    state[1] = _mm_xor_si128((state[1]), (state[i]));
  _mm_store_si128((__m128i *)t, state[1]);
  memcpy(c + msglen, t, 16);
}


x86 assembly (clang, -O0):
<morus_tag_generation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    0xc(%rax),%esi
call   1040 <_mm_store_si128@plt>
mov    -0x10(%rbp),%rax
shl    $0x3,%rax
xor    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
shl    $0x3,%rax
xor    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
call   1060 <_mm_xor_si128@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x10(%rax)
lea    -0x40(%rbp),%rdi
call   1030 <_mm_load_si128@plt>
mov    %eax,-0x44(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x8,-0x24(%rbp)
jge    11ea <morus_tag_generation+0x9a>
mov    -0x44(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1070 <morus_stateupdate@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c6 <morus_tag_generation+0x76>
movl   $0x2,-0x24(%rbp)
cmpl   $0x5,-0x24(%rbp)
jge    1229 <morus_tag_generation+0xd9>
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1060 <_mm_xor_si128@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11f1 <morus_tag_generation+0xa1>
lea    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%esi
call   1040 <_mm_store_si128@plt>
mov    -0x18(%rbp),%rdi
add    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<morus_tag_generation>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %rsi,%rbp
mov    %rdi,%r15
mov    0xc(%rcx),%esi
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <_mm_store_si128@plt>
movq   %r15,%xmm0
movq   %rbp,%xmm1
punpcklqdq %xmm0,%xmm1
psllq  $0x3,%xmm1
pxor   (%rsp),%xmm1
movdqa %xmm1,(%rsp)
mov    (%rbx),%esi
mov    0x10(%rbx),%edi
call   1060 <_mm_xor_si128@plt>
mov    %eax,0x10(%rbx)
mov    %r14,%rdi
call   1030 <_mm_load_si128@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
call   1070 <morus_stateupdate@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <morus_stateupdate@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <morus_stateupdate@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <morus_stateupdate@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <morus_stateupdate@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <morus_stateupdate@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <morus_stateupdate@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <morus_stateupdate@plt>
mov    0x4(%rbx),%edi
mov    0x8(%rbx),%esi
call   1060 <_mm_xor_si128@plt>
mov    %eax,0x4(%rbx)
mov    0xc(%rbx),%esi
mov    %eax,%edi
call   1060 <_mm_xor_si128@plt>
mov    %eax,0x4(%rbx)
mov    0x10(%rbx),%esi
mov    %eax,%edi
call   1060 <_mm_xor_si128@plt>
mov    %eax,0x4(%rbx)
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <_mm_store_si128@plt>
add    %r15,%r12
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @morus_tag_generation(i64 %0, i64 %1, i8* %2, i32* %3) {
%5 = alloca <2 x i64>
%6 = bitcast <2 x i64>* %5 to i8*
%7 = bitcast <2 x i64>* %5 to i32*
%8 = getelementptr inbounds i32, i32* %3, i64 3
%9 = load i32, i32* %8
%10 = call i32 @_mm_store_si128(i32* %7, i32 %9)
%11 = insertelement <2 x i64> poison, i64 %1, i64 0
%12 = insertelement <2 x i64> %11, i64 %0, i64 1
%13 = shl <2 x i64> %12, <i64 3, i64 3>
%14 = load <2 x i64>, <2 x i64>* %5
%15 = xor <2 x i64> %14, %13
store <2 x i64> %15, <2 x i64>* %5
%16 = getelementptr inbounds i32, i32* %3, i64 4
%17 = load i32, i32* %16
%18 = load i32, i32* %3
%19 = call i32 @_mm_xor_si128(i32 %17, i32 %18)
store i32 %19, i32* %16
%20 = call i32 @_mm_load_si128(i32* %7)
%21 = call i32 @morus_stateupdate(i32 %20, i32* %3)
%22 = call i32 @morus_stateupdate(i32 %20, i32* %3)
%23 = call i32 @morus_stateupdate(i32 %20, i32* %3)
%24 = call i32 @morus_stateupdate(i32 %20, i32* %3)
%25 = call i32 @morus_stateupdate(i32 %20, i32* %3)
%26 = call i32 @morus_stateupdate(i32 %20, i32* %3)
%27 = call i32 @morus_stateupdate(i32 %20, i32* %3)
%28 = call i32 @morus_stateupdate(i32 %20, i32* %3)
%29 = getelementptr inbounds i32, i32* %3, i64 1
%30 = load i32, i32* %29
%31 = getelementptr inbounds i32, i32* %3, i64 2
%32 = load i32, i32* %31
%33 = call i32 @_mm_xor_si128(i32 %30, i32 %32)
store i32 %33, i32* %29
%34 = load i32, i32* %8
%35 = call i32 @_mm_xor_si128(i32 %33, i32 %34)
store i32 %35, i32* %29
%36 = load i32, i32* %16
%37 = call i32 @_mm_xor_si128(i32 %35, i32 %36)
store i32 %37, i32* %29
%38 = call i32 @_mm_store_si128(i32* %7, i32 %37)
%39 = getelementptr inbounds i8, i8* %2, i64 %0
%40 = call i32 @memcpy(i8* %39, i8* %6, i32 16)
ret void
}