#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;

/* Variables and functions */
int /*<<< orphan*/ morus_enc_aut_partialblock(unsigned char const *,
                                              unsigned char *,
                                              unsigned long long, int **);
int /*<<< orphan*/ morus_enc_aut_step(unsigned char const *, unsigned char *,
                                      int **);
int /*<<< orphan*/ morus_initialization(unsigned char const *,
                                        unsigned char const *, int **);
int /*<<< orphan*/ morus_tag_generation(unsigned long long, unsigned long long,
                                        unsigned char *, 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) {
  uint64_t i;
  uint8_t plaintextblock[32], ciphertextblock[32];
  uint64_t morus_state[5][4];
  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    $0xd0,%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    -0xd0(%rbp),%rdx
call   1050 <morus_initialization@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x20,%eax
cltq
cmp    -0x30(%rbp),%rax
ja     11c5 <crypto_aead_encrypt+0x85>
mov    -0x28(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
lea    -0x80(%rbp),%rsi
lea    -0xd0(%rbp),%rdx
call   1060 <morus_enc_aut_step@plt>
mov    -0x34(%rbp),%eax
add    $0x20,%eax
mov    %eax,-0x34(%rbp)
jmp    118a <crypto_aead_encrypt+0x4a>
mov    -0x30(%rbp),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     11fa <crypto_aead_encrypt+0xba>
mov    -0x28(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
lea    -0x80(%rbp),%rsi
mov    -0x30(%rbp),%rdx
and    $0x1f,%rdx
lea    -0xd0(%rbp),%rcx
call   1040 <morus_enc_aut_partialblock@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x20,%eax
cltq
cmp    -0x20(%rbp),%rax
ja     1243 <crypto_aead_encrypt+0x103>
mov    -0x18(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
lea    -0xd0(%rbp),%rdx
call   1060 <morus_enc_aut_step@plt>
mov    -0x34(%rbp),%eax
add    $0x20,%eax
mov    %eax,-0x34(%rbp)
jmp    1201 <crypto_aead_encrypt+0xc1>
mov    -0x20(%rbp),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     127f <crypto_aead_encrypt+0x13f>
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    -0xd0(%rbp),%rcx
call   1040 <morus_enc_aut_partialblock@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    -0xd0(%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    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_aead_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %r9,%r14
mov    %r8,%rbp
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,0x10(%rsp)
mov    0xe0(%rsp),%rdi
mov    0xd8(%rsp),%rsi
lea    0x20(%rsp),%rdx
call   1050 <morus_initialization@plt>
cmp    $0x20,%r14
mov    %rbx,0x18(%rsp)
jae    118f <crypto_aead_encrypt+0x4f>
xor    %r13d,%r13d
jmp    11ca <crypto_aead_encrypt+0x8a>
mov    %r15,0x8(%rsp)
xor    %r13d,%r13d
lea    0x20(%rsp),%rbx
nopl   0x0(%rax)
mov    %r13,%r15
add    $0x20,%r13
lea    (%r15,%rbp,1),%rdi
lea    0x70(%rsp),%rsi
mov    %rbx,%rdx
call   1060 <morus_enc_aut_step@plt>
add    $0x40,%r15
cmp    %r14,%r15
jbe    11a0 <crypto_aead_encrypt+0x60>
and    $0xffffffe0,%r13d
mov    0x8(%rsp),%r15
mov    %r14,%rdx
and    $0x1f,%rdx
je     11e8 <crypto_aead_encrypt+0xa8>
add    %r13,%rbp
lea    0x70(%rsp),%rsi
lea    0x20(%rsp),%rcx
mov    %rbp,%rdi
call   1040 <morus_enc_aut_partialblock@plt>
cmp    $0x20,%r15
jae    11f5 <crypto_aead_encrypt+0xb5>
xor    %ebx,%ebx
mov    %r12,%rdi
jmp    123d <crypto_aead_encrypt+0xfd>
mov    %r14,0x8(%rsp)
xor    %ebx,%ebx
lea    0x20(%rsp),%r14
mov    0x10(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rbp
add    $0x20,%rbx
lea    (%r12,%rbp,1),%rdi
mov    %r13,%rsi
add    %rbp,%rsi
mov    %r14,%rdx
call   1060 <morus_enc_aut_step@plt>
add    $0x40,%rbp
cmp    %r15,%rbp
jbe    1210 <crypto_aead_encrypt+0xd0>
mov    %r12,%rdi
and    $0xffffffe0,%ebx
mov    0x8(%rsp),%r14
mov    %r15,%rdx
and    $0x1f,%rdx
mov    0x10(%rsp),%rbp
je     125e <crypto_aead_encrypt+0x11e>
add    %rbx,%rdi
add    %rbp,%rbx
lea    0x20(%rsp),%rcx
mov    %rbx,%rsi
call   1040 <morus_enc_aut_partialblock@plt>
lea    0x20(%rsp),%rcx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
call   1030 <morus_tag_generation@plt>
add    $0x10,%r15
mov    0x18(%rsp),%rax
mov    %r15,(%rax)
xor    %eax,%eax
add    $0x98,%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 [32 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 i32 0, i32* %19
br label %28
28: ; preds = %43, %9
%29 = load i32, i32* %19
%30 = add nsw i32 %29, 32
%31 = sext i32 %30 to i64
%32 = load i64, i64* %15
%33 = icmp ule i64 %31, %32
br i1 %33, label %34, label %46
34: ; preds = %28
%35 = load i8*, i8** %14
%36 = load i32, i32* %19
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = getelementptr inbounds [32 x i8], [32 x i8]* %21, i64 0, i64 0
%40 = getelementptr inbounds [5 x [4 x i32]], [5 x [4 x i32]]* %22, i64 0, i64 0
%41 = bitcast [4 x i32]* %40 to i32**
%42 = call i32 @morus_enc_aut_step(i8* %38, i8* %39, i32** %41)
br label %43
43: ; preds = %34
%44 = load i32, i32* %19
%45 = add nsw i32 %44, 32
store i32 %45, i32* %19
br label %28
46: ; preds = %28
%47 = load i64, i64* %15
%48 = and i64 %47, 31
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %61
50: ; preds = %46
%51 = load i8*, i8** %14
%52 = load i32, i32* %19
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = getelementptr inbounds [32 x i8], [32 x i8]* %21, i64 0, i64 0
%56 = load i64, i64* %15
%57 = and i64 %56, 31
%58 = getelementptr inbounds [5 x [4 x i32]], [5 x [4 x i32]]* %22, i64 0, i64 0
%59 = bitcast [4 x i32]* %58 to i32**
%60 = call i32 @morus_enc_aut_partialblock(i8* %54, i8* %55, i64 %57, i32** %59)
br label %61
61: ; preds = %50, %46
store i32 0, i32* %19
br label %62
62: ; preds = %80, %61
%63 = load i32, i32* %19
%64 = add nsw i32 %63, 32
%65 = sext i32 %64 to i64
%66 = load i64, i64* %13
%67 = icmp ule i64 %65, %66
br i1 %67, label %68, label %83
68: ; preds = %62
%69 = load i8*, i8** %12
%70 = load i32, i32* %19
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
%73 = load i8*, i8** %10
%74 = load i32, i32* %19
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
%77 = getelementptr inbounds [5 x [4 x i32]], [5 x [4 x i32]]* %22, i64 0, i64 0
%78 = bitcast [4 x i32]* %77 to i32**
%79 = call i32 @morus_enc_aut_step(i8* %72, i8* %76, i32** %78)
br label %80
80: ; preds = %68
%81 = load i32, i32* %19
%82 = add nsw i32 %81, 32
store i32 %82, i32* %19
br label %62
83: ; preds = %62
%84 = load i64, i64* %13
%85 = and i64 %84, 31
%86 = icmp ne i64 %85, 0
br i1 %86, label %87, label %101
87: ; preds = %83
%88 = load i8*, i8** %12
%89 = load i32, i32* %19
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i8, i8* %88, i64 %90
%92 = load i8*, i8** %10
%93 = load i32, i32* %19
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i8, i8* %92, i64 %94
%96 = load i64, i64* %13
%97 = and i64 %96, 31
%98 = getelementptr inbounds [5 x [4 x i32]], [5 x [4 x i32]]* %22, i64 0, i64 0
%99 = bitcast [4 x i32]* %98 to i32**
%100 = call i32 @morus_enc_aut_partialblock(i8* %91, i8* %95, i64 %97, i32** %99)
br label %101
101: ; preds = %87, %83
%102 = load i64, i64* %13
%103 = load i64, i64* %15
%104 = load i8*, i8** %10
%105 = getelementptr inbounds [5 x [4 x i32]], [5 x [4 x i32]]* %22, i64 0, i64 0
%106 = bitcast [4 x i32]* %105 to i32**
%107 = call i32 @morus_tag_generation(i64 %102, i64 %103, i8* %104, i32** %106)
%108 = load i64, i64* %13
%109 = add i64 %108, 16
%110 = load i64*, i64** %11
store i64 %109, i64* %110
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 [4 x i32]]
%12 = getelementptr inbounds [32 x i8], [32 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, 32
br i1 %16, label %27, label %17
17: ; preds = %9, %17
%18 = phi i64 [ %20, %17 ], [ 0, %9 ]
%19 = phi i64 [ %23, %17 ], [ 32, %9 ]
%20 = add nuw nsw i64 %18, 32
%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, 32
%24 = icmp ugt i64 %23, %5
br i1 %24, label %25, label %17
25: ; preds = %17
%26 = and i64 %19, 4294967264
br label %27
27: ; preds = %25, %9
%28 = phi i64 [ 0, %9 ], [ %26, %25 ]
%29 = and i64 %5, 31
%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, 32
br i1 %35, label %47, label %36
36: ; preds = %34, %36
%37 = phi i64 [ %39, %36 ], [ 0, %34 ]
%38 = phi i64 [ %43, %36 ], [ 32, %34 ]
%39 = add nuw nsw i64 %37, 32
%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, 32
%44 = icmp ugt i64 %43, %3
br i1 %44, label %45, label %36
45: ; preds = %36
%46 = and i64 %38, 4294967264
br label %47
47: ; preds = %45, %34
%48 = phi i64 [ 0, %34 ], [ %46, %45 ]
%49 = and i64 %3, 31
%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
}