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

/* Variables and functions */
int /*<<< orphan*/ morus_enc_aut_partialblock(unsigned char const *,
                                              unsigned char *,
                                              unsigned long long,
                                              unsigned int **);
int /*<<< orphan*/ morus_enc_aut_step(unsigned char const *, unsigned char *,
                                      unsigned int **);
int /*<<< orphan*/ morus_initialization(unsigned char const *,
                                        unsigned char const *, unsigned int **);
int /*<<< orphan*/ morus_tag_generation(unsigned long long, unsigned long long,
                                        unsigned char *, unsigned int **);
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;
  unsigned char plaintextblock[16], ciphertextblock[16];
  unsigned int morus_state[5][4];
  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    $0xb0,%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    -0xb0(%rbp),%rdx
call   1050 <morus_initialization@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x10,%rax
cmp    -0x30(%rbp),%rax
ja     11c6 <crypto_aead_encrypt+0x86>
mov    -0x28(%rbp),%rdi
add    -0x38(%rbp),%rdi
lea    -0x60(%rbp),%rsi
lea    -0xb0(%rbp),%rdx
call   1060 <morus_enc_aut_step@plt>
mov    -0x38(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x38(%rbp)
jmp    118b <crypto_aead_encrypt+0x4b>
mov    -0x30(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
je     11f8 <crypto_aead_encrypt+0xb8>
mov    -0x28(%rbp),%rdi
add    -0x38(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    -0x30(%rbp),%rdx
and    $0xf,%rdx
lea    -0xb0(%rbp),%rcx
call   1040 <morus_enc_aut_partialblock@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x10,%rax
cmp    -0x20(%rbp),%rax
ja     123f <crypto_aead_encrypt+0xff>
mov    -0x18(%rbp),%rdi
add    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    -0x38(%rbp),%rsi
lea    -0xb0(%rbp),%rdx
call   1060 <morus_enc_aut_step@plt>
mov    -0x38(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x38(%rbp)
jmp    1200 <crypto_aead_encrypt+0xc0>
mov    -0x20(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
je     1275 <crypto_aead_encrypt+0x135>
mov    -0x18(%rbp),%rdi
add    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rdx
and    $0xf,%rdx
lea    -0xb0(%rbp),%rcx
call   1040 <morus_enc_aut_partialblock@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    -0xb0(%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    $0xb0,%rsp
pop    %rbp
ret

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