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

/* Variables and functions */
int /*<<< orphan*/ _mm_setzero_si128();
int /*<<< orphan*/ morus_enc_aut_partialblock(unsigned char const *,
                                              unsigned char *,
                                              unsigned long long,
                                              int /*<<< orphan*/ **);
int /*<<< orphan*/ morus_enc_aut_step(unsigned char const *, unsigned char *,
                                      int /*<<< orphan*/ **);
int /*<<< orphan*/ morus_initialization(unsigned char const *,
                                        unsigned char const *,
                                        int /*<<< orphan*/ **);
int /*<<< orphan*/ morus_tag_generation(unsigned long long, unsigned long long,
                                        unsigned char *, int /*<<< orphan*/ **);
int crypto_aead_encrypt(unsigned char *c, unsigned long long *clen,
                        const unsigned char *m, unsigned long long mlen,
                        const unsigned char *ad, unsigned long long adlen,
                        const unsigned char *nsec, const unsigned char *npub,
                        const unsigned char *k) {
  uint64_t i;
  uint8_t ciphertextblock[32];
  __m128i morus_state[5][2];
  morus_state[0][0] = _mm_setzero_si128();
  morus_initialization(k, npub, morus_state);
  for (i = 0; (i + 32) <= adlen; i += 32) {
    morus_enc_aut_step(ad + i, ciphertextblock, morus_state);
  }
  if ((adlen & 0x1f) != 0) {
    morus_enc_aut_partialblock(ad + i, ciphertextblock, adlen & 0x1f,
                               morus_state);
  }
  for (i = 0; (i + 32) <= mlen; i += 32) {
    morus_enc_aut_step(m + i, c + i, morus_state);
  }
  if ((mlen & 0x1f) != 0) {
    morus_enc_aut_partialblock(m + i, c + i, mlen & 0x1f, morus_state);
  }
  morus_tag_generation(mlen, adlen, c, morus_state);
  *clen = mlen + 16;
  return 0;
}


x86 assembly (clang, -O0):
<crypto_aead_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    $0x0,%al
call   1030 <_mm_setzero_si128@plt>
mov    %eax,-0x90(%rbp)
mov    0x20(%rbp),%rdi
mov    0x18(%rbp),%rsi
lea    -0x90(%rbp),%rdx
call   1060 <morus_initialization@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x20,%eax
cltq
cmp    -0x30(%rbp),%rax
ja     11e2 <crypto_aead_encrypt+0x92>
mov    -0x28(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
lea    -0x60(%rbp),%rsi
lea    -0x90(%rbp),%rdx
call   1070 <morus_enc_aut_step@plt>
mov    -0x34(%rbp),%eax
add    $0x20,%eax
mov    %eax,-0x34(%rbp)
jmp    11a7 <crypto_aead_encrypt+0x57>
mov    -0x30(%rbp),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     1217 <crypto_aead_encrypt+0xc7>
mov    -0x28(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
lea    -0x60(%rbp),%rsi
mov    -0x30(%rbp),%rdx
and    $0x1f,%rdx
lea    -0x90(%rbp),%rcx
call   1050 <morus_enc_aut_partialblock@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x20,%eax
cltq
cmp    -0x20(%rbp),%rax
ja     1260 <crypto_aead_encrypt+0x110>
mov    -0x18(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
lea    -0x90(%rbp),%rdx
call   1070 <morus_enc_aut_step@plt>
mov    -0x34(%rbp),%eax
add    $0x20,%eax
mov    %eax,-0x34(%rbp)
jmp    121e <crypto_aead_encrypt+0xce>
mov    -0x20(%rbp),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     129c <crypto_aead_encrypt+0x14c>
mov    -0x18(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
mov    -0x20(%rbp),%rdx
and    $0x1f,%rdx
lea    -0x90(%rbp),%rcx
call   1050 <morus_enc_aut_partialblock@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    -0x90(%rbp),%rcx
call   1040 <morus_tag_generation@plt>
mov    -0x20(%rbp),%rcx
add    $0x10,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_aead_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %r9,%r15
mov    %r8,%rbp
mov    %rcx,%r12
mov    %rdx,(%rsp)
mov    %rsi,%rbx
mov    %rdi,0x18(%rsp)
mov    0xb8(%rsp),%r14
xor    %r13d,%r13d
xor    %eax,%eax
call   1030 <_mm_setzero_si128@plt>
mov    %eax,0x20(%rsp)
lea    0x20(%rsp),%rdx
mov    0xc0(%rsp),%rdi
mov    %r14,%rsi
call   1060 <morus_initialization@plt>
cmp    $0x20,%r15
mov    %r15,0x10(%rsp)
mov    %rbx,0x8(%rsp)
jae    11b6 <crypto_aead_encrypt+0x66>
mov    %r15,%rdx
mov    %rbx,%r14
jmp    11fd <crypto_aead_encrypt+0xad>
xor    %r13d,%r13d
lea    0x50(%rsp),%r14
lea    0x20(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r13,%r15
add    $0x20,%r13
lea    (%r15,%rbp,1),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1070 <morus_enc_aut_step@plt>
mov    0x10(%rsp),%rdx
add    $0x40,%r15
cmp    %rdx,%r15
jbe    11d0 <crypto_aead_encrypt+0x80>
and    $0xffffffe0,%r13d
mov    0x8(%rsp),%r14
and    $0x1f,%rdx
mov    0x18(%rsp),%r15
je     121d <crypto_aead_encrypt+0xcd>
add    %r13,%rbp
lea    0x50(%rsp),%rsi
lea    0x20(%rsp),%rcx
mov    %rbp,%rdi
call   1050 <morus_enc_aut_partialblock@plt>
xor    %ebx,%ebx
cmp    $0x20,%r12
jae    122b <crypto_aead_encrypt+0xdb>
mov    (%rsp),%r13
jmp    126a <crypto_aead_encrypt+0x11a>
lea    0x20(%rsp),%r14
mov    (%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rbp
add    $0x20,%rbx
mov    %r13,%rdi
add    %rbp,%rdi
lea    (%r15,%rbp,1),%rsi
mov    %r14,%rdx
call   1070 <morus_enc_aut_step@plt>
add    $0x40,%rbp
cmp    %r12,%rbp
jbe    1240 <crypto_aead_encrypt+0xf0>
and    $0xffffffe0,%ebx
mov    0x8(%rsp),%r14
mov    %r12,%rdx
and    $0x1f,%rdx
je     1289 <crypto_aead_encrypt+0x139>
add    %rbx,%r13
add    %r15,%rbx
lea    0x20(%rsp),%rcx
mov    %r13,%rdi
mov    %rbx,%rsi
call   1050 <morus_enc_aut_partialblock@plt>
lea    0x20(%rsp),%rcx
mov    %r12,%rdi
mov    0x10(%rsp),%rsi
mov    %r15,%rdx
call   1040 <morus_tag_generation@plt>
add    $0x10,%r12
mov    %r12,(%r14)
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @crypto_aead_encrypt(i8* %0, i64* %1, i8* %2, i64 %3, i8* %4, i64 %5, i8* %6, i8* %7, i8* %8) {
%10 = alloca i8*
%11 = alloca i64*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i32
%20 = alloca [32 x i8]
%21 = alloca [5 x [2 x i32]]
store i8* %0, i8** %10
store i64* %1, i64** %11
store i8* %2, i8** %12
store i64 %3, i64* %13
store i8* %4, i8** %14
store i64 %5, i64* %15
store i8* %6, i8** %16
store i8* %7, i8** %17
store i8* %8, i8** %18
%22 = call i32 (...) @_mm_setzero_si128()
%23 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %21, i64 0, i64 0
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %23, i64 0, i64 0
store i32 %22, i32* %24
%25 = load i8*, i8** %18
%26 = load i8*, i8** %17
%27 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %21, i64 0, i64 0
%28 = bitcast [2 x i32]* %27 to i32**
%29 = call i32 @morus_initialization(i8* %25, i8* %26, i32** %28)
store i32 0, i32* %19
br label %30
30: ; preds = %45, %9
%31 = load i32, i32* %19
%32 = add nsw i32 %31, 32
%33 = sext i32 %32 to i64
%34 = load i64, i64* %15
%35 = icmp ule i64 %33, %34
br i1 %35, label %36, label %48
36: ; preds = %30
%37 = load i8*, i8** %14
%38 = load i32, i32* %19
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = getelementptr inbounds [32 x i8], [32 x i8]* %20, i64 0, i64 0
%42 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %21, i64 0, i64 0
%43 = bitcast [2 x i32]* %42 to i32**
%44 = call i32 @morus_enc_aut_step(i8* %40, i8* %41, i32** %43)
br label %45
45: ; preds = %36
%46 = load i32, i32* %19
%47 = add nsw i32 %46, 32
store i32 %47, i32* %19
br label %30
48: ; preds = %30
%49 = load i64, i64* %15
%50 = and i64 %49, 31
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %63
52: ; preds = %48
%53 = load i8*, i8** %14
%54 = load i32, i32* %19
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = getelementptr inbounds [32 x i8], [32 x i8]* %20, i64 0, i64 0
%58 = load i64, i64* %15
%59 = and i64 %58, 31
%60 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %21, i64 0, i64 0
%61 = bitcast [2 x i32]* %60 to i32**
%62 = call i32 @morus_enc_aut_partialblock(i8* %56, i8* %57, i64 %59, i32** %61)
br label %63
63: ; preds = %52, %48
store i32 0, i32* %19
br label %64
64: ; preds = %82, %63
%65 = load i32, i32* %19
%66 = add nsw i32 %65, 32
%67 = sext i32 %66 to i64
%68 = load i64, i64* %13
%69 = icmp ule i64 %67, %68
br i1 %69, label %70, label %85
70: ; preds = %64
%71 = load i8*, i8** %12
%72 = load i32, i32* %19
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %71, i64 %73
%75 = load i8*, i8** %10
%76 = load i32, i32* %19
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %75, i64 %77
%79 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %21, i64 0, i64 0
%80 = bitcast [2 x i32]* %79 to i32**
%81 = call i32 @morus_enc_aut_step(i8* %74, i8* %78, i32** %80)
br label %82
82: ; preds = %70
%83 = load i32, i32* %19
%84 = add nsw i32 %83, 32
store i32 %84, i32* %19
br label %64
85: ; preds = %64
%86 = load i64, i64* %13
%87 = and i64 %86, 31
%88 = icmp ne i64 %87, 0
br i1 %88, label %89, label %103
89: ; preds = %85
%90 = load i8*, i8** %12
%91 = load i32, i32* %19
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i8, i8* %90, i64 %92
%94 = load i8*, i8** %10
%95 = load i32, i32* %19
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i8, i8* %94, i64 %96
%98 = load i64, i64* %13
%99 = and i64 %98, 31
%100 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %21, i64 0, i64 0
%101 = bitcast [2 x i32]* %100 to i32**
%102 = call i32 @morus_enc_aut_partialblock(i8* %93, i8* %97, i64 %99, i32** %101)
br label %103
103: ; preds = %89, %85
%104 = load i64, i64* %13
%105 = load i64, i64* %15
%106 = load i8*, i8** %10
%107 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %21, i64 0, i64 0
%108 = bitcast [2 x i32]* %107 to i32**
%109 = call i32 @morus_tag_generation(i64 %104, i64 %105, i8* %106, i32** %108)
%110 = load i64, i64* %13
%111 = add i64 %110, 16
%112 = load i64*, i64** %11
store i64 %111, i64* %112
ret i32 0
}

LLVM IR (-O2):
define i32 @crypto_aead_encrypt(i8* %0, i64* nocapture writeonly %1, i8* %2, i64 %3, i8* %4, i64 %5, i8* nocapture readnone %6, i8* %7, i8* %8) {
%10 = alloca [32 x i8]
%11 = alloca [5 x [2 x i32]]
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%13 = bitcast [5 x [2 x i32]]* %11 to i8*
%14 = tail call i32 (...) @_mm_setzero_si128()
%15 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %11, i64 0, i64 0, i64 0
store i32 %14, i32* %15
%16 = bitcast [5 x [2 x i32]]* %11 to i32**
%17 = call i32 @morus_initialization(i8* %8, i8* %7, i32** %16)
%18 = icmp ult i64 %5, 32
br i1 %18, label %29, label %19
19: ; preds = %9, %19
%20 = phi i64 [ %22, %19 ], [ 0, %9 ]
%21 = phi i64 [ %25, %19 ], [ 32, %9 ]
%22 = add nuw nsw i64 %20, 32
%23 = getelementptr inbounds i8, i8* %4, i64 %20
%24 = call i32 @morus_enc_aut_step(i8* %23, i8* %12, i32** %16)
%25 = add nuw i64 %21, 32
%26 = icmp ugt i64 %25, %5
br i1 %26, label %27, label %19
27: ; preds = %19
%28 = and i64 %21, 4294967264
br label %29
29: ; preds = %27, %9
%30 = phi i64 [ 0, %9 ], [ %28, %27 ]
%31 = and i64 %5, 31
%32 = icmp eq i64 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %29
%34 = getelementptr inbounds i8, i8* %4, i64 %30
%35 = call i32 @morus_enc_aut_partialblock(i8* %34, i8* %12, i64 %31, i32** %16)
br label %36
36: ; preds = %33, %29
%37 = icmp ult i64 %3, 32
br i1 %37, label %49, label %38
38: ; preds = %36, %38
%39 = phi i64 [ %41, %38 ], [ 0, %36 ]
%40 = phi i64 [ %45, %38 ], [ 32, %36 ]
%41 = add nuw nsw i64 %39, 32
%42 = getelementptr inbounds i8, i8* %2, i64 %39
%43 = getelementptr inbounds i8, i8* %0, i64 %39
%44 = call i32 @morus_enc_aut_step(i8* %42, i8* %43, i32** %16)
%45 = add nuw i64 %40, 32
%46 = icmp ugt i64 %45, %3
br i1 %46, label %47, label %38
47: ; preds = %38
%48 = and i64 %40, 4294967264
br label %49
49: ; preds = %47, %36
%50 = phi i64 [ 0, %36 ], [ %48, %47 ]
%51 = and i64 %3, 31
%52 = icmp eq i64 %51, 0
br i1 %52, label %57, label %53
53: ; preds = %49
%54 = getelementptr inbounds i8, i8* %2, i64 %50
%55 = getelementptr inbounds i8, i8* %0, i64 %50
%56 = call i32 @morus_enc_aut_partialblock(i8* %54, i8* %55, i64 %51, i32** %16)
br label %57
57: ; preds = %53, %49
%58 = call i32 @morus_tag_generation(i64 %3, i64 %5, i8* %0, i32** %16)
%59 = add i64 %3, 16
store i64 %59, i64* %1
ret i32 0
}