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

/* 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) {
  uint64_t i;
  unsigned char plaintextblock[16], ciphertextblock[16];
  __m128i morus_state[5];
  morus_initialization(k, npub, morus_state);
  for (i = 0; (i + 16) <= adlen; i += 16) {
    morus_enc_aut_step(ad + i, ciphertextblock, morus_state);
  }
  if ((adlen & 0xf) != 0) {
    morus_enc_aut_partialblock(ad + i, ciphertextblock, adlen & 0xf,
                               morus_state);
  }
  for (i = 0; (i + 16) <= mlen; i += 16) {
    morus_enc_aut_step(m + i, c + i, morus_state);
  }
  if ((mlen & 0xf) != 0) {
    morus_enc_aut_partialblock(m + i, c + i, mlen & 0xf, 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>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x10,%eax
cltq
cmp    -0x30(%rbp),%rax
ja     11bf <crypto_aead_encrypt+0x7f>
mov    -0x28(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
lea    -0x60(%rbp),%rsi
lea    -0x80(%rbp),%rdx
call   1060 <morus_enc_aut_step@plt>
mov    -0x34(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x34(%rbp)
jmp    1187 <crypto_aead_encrypt+0x47>
mov    -0x30(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
je     11f1 <crypto_aead_encrypt+0xb1>
mov    -0x28(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
lea    -0x60(%rbp),%rsi
mov    -0x30(%rbp),%rdx
and    $0xf,%rdx
lea    -0x80(%rbp),%rcx
call   1040 <morus_enc_aut_partialblock@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x10,%eax
cltq
cmp    -0x20(%rbp),%rax
ja     1237 <crypto_aead_encrypt+0xf7>
mov    -0x18(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
lea    -0x80(%rbp),%rdx
call   1060 <morus_enc_aut_step@plt>
mov    -0x34(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x34(%rbp)
jmp    11f8 <crypto_aead_encrypt+0xb8>
mov    -0x20(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
je     1270 <crypto_aead_encrypt+0x130>
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    $0xf,%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    $0x48,%rsp
mov    %r9,%r14
mov    %r8,%rbp
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,0x8(%rsp)
mov    0x90(%rsp),%rdi
mov    0x88(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1050 <morus_initialization@plt>
cmp    $0x10,%r14
mov    %rbx,0x28(%rsp)
jae    118c <crypto_aead_encrypt+0x4c>
xor    %r13d,%r13d
jmp    11c9 <crypto_aead_encrypt+0x89>
mov    %r15,(%rsp)
xor    %r13d,%r13d
lea    0x10(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %r13,%r15
add    $0x10,%r13
lea    (%r15,%rbp,1),%rdi
lea    0x30(%rsp),%rsi
mov    %rbx,%rdx
call   1060 <morus_enc_aut_step@plt>
add    $0x20,%r15
cmp    %r14,%r15
jbe    11a0 <crypto_aead_encrypt+0x60>
and    $0xfffffff0,%r13d
mov    (%rsp),%r15
mov    %r14,%rdx
and    $0xf,%rdx
je     11e7 <crypto_aead_encrypt+0xa7>
add    %r13,%rbp
lea    0x30(%rsp),%rsi
lea    0x10(%rsp),%rcx
mov    %rbp,%rdi
call   1040 <morus_enc_aut_partialblock@plt>
cmp    $0x10,%r15
jae    11f4 <crypto_aead_encrypt+0xb4>
xor    %ebx,%ebx
mov    %r12,%rdi
jmp    123c <crypto_aead_encrypt+0xfc>
mov    %r14,(%rsp)
xor    %ebx,%ebx
lea    0x10(%rsp),%r14
mov    0x8(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rbp
add    $0x10,%rbx
lea    (%r12,%rbp,1),%rdi
mov    %r13,%rsi
add    %rbp,%rsi
mov    %r14,%rdx
call   1060 <morus_enc_aut_step@plt>
add    $0x20,%rbp
cmp    %r15,%rbp
jbe    1210 <crypto_aead_encrypt+0xd0>
mov    %r12,%rdi
and    $0xfffffff0,%ebx
mov    (%rsp),%r14
mov    %r15,%rdx
and    $0xf,%rdx
mov    0x8(%rsp),%rbp
je     125d <crypto_aead_encrypt+0x11d>
add    %rbx,%rdi
add    %rbp,%rbx
lea    0x10(%rsp),%rcx
mov    %rbx,%rsi
call   1040 <morus_enc_aut_partialblock@plt>
lea    0x10(%rsp),%rcx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
call   1030 <morus_tag_generation@plt>
add    $0x10,%r15
mov    0x28(%rsp),%rax
mov    %r15,(%rax)
xor    %eax,%eax
add    $0x48,%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 [16 x i8]
%21 = alloca [16 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 i32 0, i32* %19
br label %27
27: ; preds = %41, %9
%28 = load i32, i32* %19
%29 = add nsw i32 %28, 16
%30 = sext i32 %29 to i64
%31 = load i64, i64* %15
%32 = icmp ule i64 %30, %31
br i1 %32, label %33, label %44
33: ; preds = %27
%34 = load i8*, i8** %14
%35 = load i32, i32* %19
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = getelementptr inbounds [16 x i8], [16 x i8]* %21, i64 0, i64 0
%39 = getelementptr inbounds [5 x i32], [5 x i32]* %22, i64 0, i64 0
%40 = call i32 @morus_enc_aut_step(i8* %37, i8* %38, i32* %39)
br label %41
41: ; preds = %33
%42 = load i32, i32* %19
%43 = add nsw i32 %42, 16
store i32 %43, i32* %19
br label %27
44: ; preds = %27
%45 = load i64, i64* %15
%46 = and i64 %45, 15
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %58
48: ; preds = %44
%49 = load i8*, i8** %14
%50 = load i32, i32* %19
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = getelementptr inbounds [16 x i8], [16 x i8]* %21, i64 0, i64 0
%54 = load i64, i64* %15
%55 = and i64 %54, 15
%56 = getelementptr inbounds [5 x i32], [5 x i32]* %22, i64 0, i64 0
%57 = call i32 @morus_enc_aut_partialblock(i8* %52, i8* %53, i64 %55, i32* %56)
br label %58
58: ; preds = %48, %44
store i32 0, i32* %19
br label %59
59: ; preds = %76, %58
%60 = load i32, i32* %19
%61 = add nsw i32 %60, 16
%62 = sext i32 %61 to i64
%63 = load i64, i64* %13
%64 = icmp ule i64 %62, %63
br i1 %64, label %65, label %79
65: ; preds = %59
%66 = load i8*, i8** %12
%67 = load i32, i32* %19
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %66, i64 %68
%70 = load i8*, i8** %10
%71 = load i32, i32* %19
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %70, i64 %72
%74 = getelementptr inbounds [5 x i32], [5 x i32]* %22, i64 0, i64 0
%75 = call i32 @morus_enc_aut_step(i8* %69, i8* %73, i32* %74)
br label %76
76: ; preds = %65
%77 = load i32, i32* %19
%78 = add nsw i32 %77, 16
store i32 %78, i32* %19
br label %59
79: ; preds = %59
%80 = load i64, i64* %13
%81 = and i64 %80, 15
%82 = icmp ne i64 %81, 0
br i1 %82, label %83, label %96
83: ; preds = %79
%84 = load i8*, i8** %12
%85 = load i32, i32* %19
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8, i8* %84, i64 %86
%88 = load i8*, i8** %10
%89 = load i32, i32* %19
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i8, i8* %88, i64 %90
%92 = load i64, i64* %13
%93 = and i64 %92, 15
%94 = getelementptr inbounds [5 x i32], [5 x i32]* %22, i64 0, i64 0
%95 = call i32 @morus_enc_aut_partialblock(i8* %87, i8* %91, i64 %93, i32* %94)
br label %96
96: ; preds = %83, %79
%97 = load i64, i64* %13
%98 = load i64, i64* %15
%99 = load i8*, i8** %10
%100 = getelementptr inbounds [5 x i32], [5 x i32]* %22, i64 0, i64 0
%101 = call i32 @morus_tag_generation(i64 %97, i64 %98, i8* %99, i32* %100)
%102 = load i64, i64* %13
%103 = add i64 %102, 16
%104 = load i64*, i64** %11
store i64 %103, i64* %104
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 [16 x i8]
%11 = alloca [5 x i32]
%12 = getelementptr inbounds [16 x i8], [16 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, 16
br i1 %16, label %27, label %17
17: ; preds = %9, %17
%18 = phi i64 [ %20, %17 ], [ 0, %9 ]
%19 = phi i64 [ %23, %17 ], [ 16, %9 ]
%20 = add nuw nsw i64 %18, 16
%21 = getelementptr inbounds i8, i8* %4, i64 %18
%22 = call i32 @morus_enc_aut_step(i8* %21, i8* %12, i32* %14)
%23 = add nuw i64 %19, 16
%24 = icmp ugt i64 %23, %5
br i1 %24, label %25, label %17
25: ; preds = %17
%26 = and i64 %19, 4294967280
br label %27
27: ; preds = %25, %9
%28 = phi i64 [ 0, %9 ], [ %26, %25 ]
%29 = and i64 %5, 15
%30 = icmp eq i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %27
%32 = getelementptr inbounds i8, i8* %4, i64 %28
%33 = call i32 @morus_enc_aut_partialblock(i8* %32, i8* %12, i64 %29, i32* %14)
br label %34
34: ; preds = %31, %27
%35 = icmp ult i64 %3, 16
br i1 %35, label %47, label %36
36: ; preds = %34, %36
%37 = phi i64 [ %39, %36 ], [ 0, %34 ]
%38 = phi i64 [ %43, %36 ], [ 16, %34 ]
%39 = add nuw nsw i64 %37, 16
%40 = getelementptr inbounds i8, i8* %2, i64 %37
%41 = getelementptr inbounds i8, i8* %0, i64 %37
%42 = call i32 @morus_enc_aut_step(i8* %40, i8* %41, i32* %14)
%43 = add nuw i64 %38, 16
%44 = icmp ugt i64 %43, %3
br i1 %44, label %45, label %36
45: ; preds = %36
%46 = and i64 %38, 4294967280
br label %47
47: ; preds = %45, %34
%48 = phi i64 [ 0, %34 ], [ %46, %45 ]
%49 = and i64 %3, 15
%50 = icmp eq i64 %49, 0
br i1 %50, label %55, label %51
51: ; preds = %47
%52 = getelementptr inbounds i8, i8* %2, i64 %48
%53 = getelementptr inbounds i8, i8* %0, i64 %48
%54 = call i32 @morus_enc_aut_partialblock(i8* %52, i8* %53, i64 %49, i32* %14)
br label %55
55: ; preds = %51, %47
%56 = call i32 @morus_tag_generation(i64 %3, i64 %5, i8* %0, i32* %14)
%57 = add i64 %3, 16
store i64 %57, i64* %1
ret i32 0
}