#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*/ __m256i;

/* Variables and functions */
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) {
  unsigned long long i, j;
  unsigned char ciphertextblock[32];
  __m256i morus_state[5];
  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    $0x80,%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    0x20(%rbp),%rdi
mov    0x18(%rbp),%rsi
lea    -0x80(%rbp),%rdx
call   1050 <morus_initialization@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x20,%rax
cmp    -0x30(%rbp),%rax
ja     11c0 <crypto_aead_encrypt+0x80>
mov    -0x28(%rbp),%rdi
add    -0x38(%rbp),%rdi
lea    -0x60(%rbp),%rsi
lea    -0x80(%rbp),%rdx
call   1060 <morus_enc_aut_step@plt>
mov    -0x38(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x38(%rbp)
jmp    1188 <crypto_aead_encrypt+0x48>
mov    -0x30(%rbp),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     11ef <crypto_aead_encrypt+0xaf>
mov    -0x28(%rbp),%rdi
add    -0x38(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    -0x30(%rbp),%rdx
and    $0x1f,%rdx
lea    -0x80(%rbp),%rcx
call   1040 <morus_enc_aut_partialblock@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x20,%rax
cmp    -0x20(%rbp),%rax
ja     1233 <crypto_aead_encrypt+0xf3>
mov    -0x18(%rbp),%rdi
add    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    -0x38(%rbp),%rsi
lea    -0x80(%rbp),%rdx
call   1060 <morus_enc_aut_step@plt>
mov    -0x38(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x38(%rbp)
jmp    11f7 <crypto_aead_encrypt+0xb7>
mov    -0x20(%rbp),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     1266 <crypto_aead_encrypt+0x126>
mov    -0x18(%rbp),%rdi
add    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rdx
and    $0x1f,%rdx
lea    -0x80(%rbp),%rcx
call   1040 <morus_enc_aut_partialblock@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    -0x80(%rbp),%rcx
call   1030 <morus_tag_generation@plt>
mov    -0x20(%rbp),%rcx
add    $0x10,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_aead_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r9,%rbx
mov    %r8,%rbp
mov    %rcx,%r13
mov    %rdx,0x18(%rsp)
mov    %rsi,0x28(%rsp)
mov    %rdi,0x20(%rsp)
mov    0xa0(%rsp),%rdi
mov    0x98(%rsp),%rsi
mov    %rsp,%rdx
call   1050 <morus_initialization@plt>
cmp    $0x20,%rbx
jae    1188 <crypto_aead_encrypt+0x48>
xor    %eax,%eax
jmp    11bf <crypto_aead_encrypt+0x7f>
xor    %r15d,%r15d
lea    0x30(%rsp),%r14
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%r15,%rbp,1),%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1060 <morus_enc_aut_step@plt>
lea    0x20(%r15),%rax
add    $0x40,%r15
cmp    %rbx,%r15
mov    %rax,%r15
jbe    11a0 <crypto_aead_encrypt+0x60>
mov    %rbx,%rdx
and    $0x1f,%rdx
je     11db <crypto_aead_encrypt+0x9b>
add    %rax,%rbp
lea    0x30(%rsp),%rsi
mov    %rsp,%rcx
mov    %rbp,%rdi
call   1040 <morus_enc_aut_partialblock@plt>
mov    %rbx,%r14
cmp    $0x20,%r13
mov    0x20(%rsp),%r12
mov    0x18(%rsp),%rbp
jae    11f2 <crypto_aead_encrypt+0xb2>
xor    %esi,%esi
jmp    1220 <crypto_aead_encrypt+0xe0>
xor    %ebx,%ebx
mov    %rsp,%r15
nopw   0x0(%rax,%rax,1)
lea    (%rbx,%rbp,1),%rdi
lea    (%r12,%rbx,1),%rsi
mov    %r15,%rdx
call   1060 <morus_enc_aut_step@plt>
lea    0x20(%rbx),%rsi
add    $0x40,%rbx
cmp    %r13,%rbx
mov    %rsi,%rbx
jbe    1200 <crypto_aead_encrypt+0xc0>
mov    %r13,%rdx
and    $0x1f,%rdx
je     123a <crypto_aead_encrypt+0xfa>
add    %rsi,%rbp
add    %r12,%rsi
mov    %rsp,%rcx
mov    %rbp,%rdi
call   1040 <morus_enc_aut_partialblock@plt>
mov    %rsp,%rcx
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1030 <morus_tag_generation@plt>
add    $0x10,%r13
mov    0x28(%rsp),%rax
mov    %r13,(%rax)
xor    %eax,%eax
add    $0x58,%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 i64
%20 = alloca i64
%21 = alloca [32 x i8]
%22 = alloca [5 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
%23 = load i8*, i8** %18
%24 = load i8*, i8** %17
%25 = getelementptr inbounds [5 x i32], [5 x i32]* %22, i64 0, i64 0
%26 = call i32 @morus_initialization(i8* %23, i8* %24, i32* %25)
store i64 0, i64* %19
br label %27
27: ; preds = %39, %9
%28 = load i64, i64* %19
%29 = add i64 %28, 32
%30 = load i64, i64* %15
%31 = icmp ule i64 %29, %30
br i1 %31, label %32, label %42
32: ; preds = %27
%33 = load i8*, i8** %14
%34 = load i64, i64* %19
%35 = getelementptr inbounds i8, i8* %33, i64 %34
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %21, i64 0, i64 0
%37 = getelementptr inbounds [5 x i32], [5 x i32]* %22, i64 0, i64 0
%38 = call i32 @morus_enc_aut_step(i8* %35, i8* %36, i32* %37)
br label %39
39: ; preds = %32
%40 = load i64, i64* %19
%41 = add i64 %40, 32
store i64 %41, i64* %19
br label %27
42: ; preds = %27
%43 = load i64, i64* %15
%44 = and i64 %43, 31
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %55
46: ; preds = %42
%47 = load i8*, i8** %14
%48 = load i64, i64* %19
%49 = getelementptr inbounds i8, i8* %47, i64 %48
%50 = getelementptr inbounds [32 x i8], [32 x i8]* %21, i64 0, i64 0
%51 = load i64, i64* %15
%52 = and i64 %51, 31
%53 = getelementptr inbounds [5 x i32], [5 x i32]* %22, i64 0, i64 0
%54 = call i32 @morus_enc_aut_partialblock(i8* %49, i8* %50, i64 %52, i32* %53)
br label %55
55: ; preds = %46, %42
store i64 0, i64* %19
br label %56
56: ; preds = %70, %55
%57 = load i64, i64* %19
%58 = add i64 %57, 32
%59 = load i64, i64* %13
%60 = icmp ule i64 %58, %59
br i1 %60, label %61, label %73
61: ; preds = %56
%62 = load i8*, i8** %12
%63 = load i64, i64* %19
%64 = getelementptr inbounds i8, i8* %62, i64 %63
%65 = load i8*, i8** %10
%66 = load i64, i64* %19
%67 = getelementptr inbounds i8, i8* %65, i64 %66
%68 = getelementptr inbounds [5 x i32], [5 x i32]* %22, i64 0, i64 0
%69 = call i32 @morus_enc_aut_step(i8* %64, i8* %67, i32* %68)
br label %70
70: ; preds = %61
%71 = load i64, i64* %19
%72 = add i64 %71, 32
store i64 %72, i64* %19
br label %56
73: ; preds = %56
%74 = load i64, i64* %13
%75 = and i64 %74, 31
%76 = icmp ne i64 %75, 0
br i1 %76, label %77, label %88
77: ; preds = %73
%78 = load i8*, i8** %12
%79 = load i64, i64* %19
%80 = getelementptr inbounds i8, i8* %78, i64 %79
%81 = load i8*, i8** %10
%82 = load i64, i64* %19
%83 = getelementptr inbounds i8, i8* %81, i64 %82
%84 = load i64, i64* %13
%85 = and i64 %84, 31
%86 = getelementptr inbounds [5 x i32], [5 x i32]* %22, i64 0, i64 0
%87 = call i32 @morus_enc_aut_partialblock(i8* %80, i8* %83, i64 %85, i32* %86)
br label %88
88: ; preds = %77, %73
%89 = load i64, i64* %13
%90 = load i64, i64* %15
%91 = load i8*, i8** %10
%92 = getelementptr inbounds [5 x i32], [5 x i32]* %22, i64 0, i64 0
%93 = call i32 @morus_tag_generation(i64 %89, i64 %90, i8* %91, i32* %92)
%94 = load i64, i64* %13
%95 = add i64 %94, 16
%96 = load i64*, i64** %11
store i64 %95, i64* %96
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 i32]
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%13 = bitcast [5 x i32]* %11 to i8*
%14 = getelementptr inbounds [5 x i32], [5 x i32]* %11, i64 0, i64 0
%15 = call i32 @morus_initialization(i8* %8, i8* %7, i32* %14)
%16 = icmp ult i64 %5, 32
br i1 %16, label %24, label %17
17: ; preds = %9, %17
%18 = phi i64 [ %22, %17 ], [ 32, %9 ]
%19 = phi i64 [ %18, %17 ], [ 0, %9 ]
%20 = getelementptr inbounds i8, i8* %4, i64 %19
%21 = call i32 @morus_enc_aut_step(i8* %20, i8* %12, i32* %14)
%22 = add i64 %18, 32
%23 = icmp ugt i64 %22, %5
br i1 %23, label %24, label %17
24: ; preds = %17, %9
%25 = phi i64 [ 0, %9 ], [ %18, %17 ]
%26 = and i64 %5, 31
%27 = icmp eq i64 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %24
%29 = getelementptr inbounds i8, i8* %4, i64 %25
%30 = call i32 @morus_enc_aut_partialblock(i8* %29, i8* %12, i64 %26, i32* %14)
br label %31
31: ; preds = %28, %24
%32 = icmp ult i64 %3, 32
br i1 %32, label %41, label %33
33: ; preds = %31, %33
%34 = phi i64 [ %39, %33 ], [ 32, %31 ]
%35 = phi i64 [ %34, %33 ], [ 0, %31 ]
%36 = getelementptr inbounds i8, i8* %2, i64 %35
%37 = getelementptr inbounds i8, i8* %0, i64 %35
%38 = call i32 @morus_enc_aut_step(i8* %36, i8* %37, i32* %14)
%39 = add i64 %34, 32
%40 = icmp ugt i64 %39, %3
br i1 %40, label %41, label %33
41: ; preds = %33, %31
%42 = phi i64 [ 0, %31 ], [ %34, %33 ]
%43 = and i64 %3, 31
%44 = icmp eq i64 %43, 0
br i1 %44, label %49, label %45
45: ; preds = %41
%46 = getelementptr inbounds i8, i8* %2, i64 %42
%47 = getelementptr inbounds i8, i8* %0, i64 %42
%48 = call i32 @morus_enc_aut_partialblock(i8* %46, i8* %47, i64 %43, i32* %14)
br label %49
49: ; preds = %45, %41
%50 = call i32 @morus_tag_generation(i64 %3, i64 %5, i8* %0, i32* %14)
%51 = add i64 %3, 16
store i64 %51, i64* %1
ret i32 0
}