#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 plaintextblock[32], 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    $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    $0x0,%al
call   1030 <_mm_setzero_si128@plt>
mov    %eax,-0xb0(%rbp)
mov    0x20(%rbp),%rdi
mov    0x18(%rbp),%rsi
lea    -0xb0(%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    -0x80(%rbp),%rsi
lea    -0xb0(%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    -0x80(%rbp),%rsi
mov    -0x30(%rbp),%rdx
and    $0x1f,%rdx
lea    -0xb0(%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    -0xb0(%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    -0xb0(%rbp),%rcx
call   1050 <morus_enc_aut_partialblock@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    -0xb0(%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    $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    $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 [32 x i8]
%22 = 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
%23 = call i32 (...) @_mm_setzero_si128()
%24 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %22, i64 0, i64 0
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %24, i64 0, i64 0
store i32 %23, i32* %25
%26 = load i8*, i8** %18
%27 = load i8*, i8** %17
%28 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %22, i64 0, i64 0
%29 = bitcast [2 x i32]* %28 to i32**
%30 = call i32 @morus_initialization(i8* %26, i8* %27, i32** %29)
store i32 0, i32* %19
br label %31
31: ; preds = %46, %9
%32 = load i32, i32* %19
%33 = add nsw i32 %32, 32
%34 = sext i32 %33 to i64
%35 = load i64, i64* %15
%36 = icmp ule i64 %34, %35
br i1 %36, label %37, label %49
37: ; preds = %31
%38 = load i8*, i8** %14
%39 = load i32, i32* %19
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = getelementptr inbounds [32 x i8], [32 x i8]* %21, i64 0, i64 0
%43 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %22, i64 0, i64 0
%44 = bitcast [2 x i32]* %43 to i32**
%45 = call i32 @morus_enc_aut_step(i8* %41, i8* %42, i32** %44)
br label %46
46: ; preds = %37
%47 = load i32, i32* %19
%48 = add nsw i32 %47, 32
store i32 %48, i32* %19
br label %31
49: ; preds = %31
%50 = load i64, i64* %15
%51 = and i64 %50, 31
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %64
53: ; preds = %49
%54 = load i8*, i8** %14
%55 = load i32, i32* %19
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = getelementptr inbounds [32 x i8], [32 x i8]* %21, i64 0, i64 0
%59 = load i64, i64* %15
%60 = and i64 %59, 31
%61 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %22, i64 0, i64 0
%62 = bitcast [2 x i32]* %61 to i32**
%63 = call i32 @morus_enc_aut_partialblock(i8* %57, i8* %58, i64 %60, i32** %62)
br label %64
64: ; preds = %53, %49
store i32 0, i32* %19
br label %65
65: ; preds = %83, %64
%66 = load i32, i32* %19
%67 = add nsw i32 %66, 32
%68 = sext i32 %67 to i64
%69 = load i64, i64* %13
%70 = icmp ule i64 %68, %69
br i1 %70, label %71, label %86
71: ; preds = %65
%72 = load i8*, i8** %12
%73 = load i32, i32* %19
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %72, i64 %74
%76 = load i8*, i8** %10
%77 = load i32, i32* %19
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8, i8* %76, i64 %78
%80 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %22, i64 0, i64 0
%81 = bitcast [2 x i32]* %80 to i32**
%82 = call i32 @morus_enc_aut_step(i8* %75, i8* %79, i32** %81)
br label %83
83: ; preds = %71
%84 = load i32, i32* %19
%85 = add nsw i32 %84, 32
store i32 %85, i32* %19
br label %65
86: ; preds = %65
%87 = load i64, i64* %13
%88 = and i64 %87, 31
%89 = icmp ne i64 %88, 0
br i1 %89, label %90, label %104
90: ; preds = %86
%91 = load i8*, i8** %12
%92 = load i32, i32* %19
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8, i8* %91, i64 %93
%95 = load i8*, i8** %10
%96 = load i32, i32* %19
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8, i8* %95, i64 %97
%99 = load i64, i64* %13
%100 = and i64 %99, 31
%101 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %22, i64 0, i64 0
%102 = bitcast [2 x i32]* %101 to i32**
%103 = call i32 @morus_enc_aut_partialblock(i8* %94, i8* %98, i64 %100, i32** %102)
br label %104
104: ; preds = %90, %86
%105 = load i64, i64* %13
%106 = load i64, i64* %15
%107 = load i8*, i8** %10
%108 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %22, i64 0, i64 0
%109 = bitcast [2 x i32]* %108 to i32**
%110 = call i32 @morus_tag_generation(i64 %105, i64 %106, i8* %107, i32** %109)
%111 = load i64, i64* %13
%112 = add i64 %111, 16
%113 = load i64*, i64** %11
store i64 %112, i64* %113
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
}