#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_dec_aut_partialblock(unsigned char *,
                                              unsigned char const *,
                                              unsigned long long,
                                              int /*<<< orphan*/ *);
int /*<<< orphan*/ morus_dec_aut_step(unsigned char *, unsigned char const *,
                                      int /*<<< orphan*/ *);
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 morus_tag_verification(unsigned long long, unsigned long long,
                           unsigned char const *, int /*<<< orphan*/ *);
int crypto_aead_decrypt(unsigned char *m, unsigned long long *mlen,
                        unsigned char *nsec, const unsigned char *c,
                        unsigned long long clen, const unsigned char *ad,
                        unsigned long long adlen, const unsigned char *npub,
                        const unsigned char *k) {
  unsigned long long i, j;
  unsigned char ciphertextblock[32];
  unsigned char tag[16];
  unsigned char check = 0;
  __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);
  }
  *mlen = clen - 16;
  for (i = 0; (i + 32) <= *mlen; i += 32) {
    morus_dec_aut_step(m + i, c + i, morus_state);
  }
  if ((*mlen & 0x1f) != 0) {
    morus_dec_aut_partialblock(m + i, c + i, (*mlen) & 0x1f, morus_state);
  }
  return morus_tag_verification(*mlen, adlen, c, morus_state);
}


x86 assembly (clang, -O0):
<crypto_aead_decrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%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)
movb   $0x0,-0x71(%rbp)
mov    0x20(%rbp),%rdi
mov    0x18(%rbp),%rsi
lea    -0x90(%rbp),%rdx
call   1070 <morus_initialization@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x20,%rax
cmp    0x10(%rbp),%rax
ja     11ea <crypto_aead_decrypt+0x8a>
mov    -0x30(%rbp),%rdi
add    -0x38(%rbp),%rdi
lea    -0x60(%rbp),%rsi
lea    -0x90(%rbp),%rdx
call   1080 <morus_enc_aut_step@plt>
mov    -0x38(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x38(%rbp)
jmp    11af <crypto_aead_decrypt+0x4f>
mov    0x10(%rbp),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     121c <crypto_aead_decrypt+0xbc>
mov    -0x30(%rbp),%rdi
add    -0x38(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    0x10(%rbp),%rdx
and    $0x1f,%rdx
lea    -0x90(%rbp),%rcx
call   1060 <morus_enc_aut_partialblock@plt>
mov    -0x28(%rbp),%rcx
sub    $0x10,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x20,%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
ja     1275 <crypto_aead_decrypt+0x115>
mov    -0x8(%rbp),%rdi
add    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    -0x38(%rbp),%rsi
lea    -0x90(%rbp),%rdx
call   1030 <morus_dec_aut_step@plt>
mov    -0x38(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x38(%rbp)
jmp    1233 <crypto_aead_decrypt+0xd3>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     12b1 <crypto_aead_decrypt+0x151>
mov    -0x8(%rbp),%rdi
add    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
and    $0x1f,%rdx
lea    -0x90(%rbp),%rcx
call   1050 <morus_dec_aut_partialblock@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x90(%rbp),%rcx
call   1040 <morus_tag_verification@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_aead_decrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r9,%rbp
mov    %r8,%rbx
mov    %rcx,0x28(%rsp)
mov    %rsi,0x20(%rsp)
mov    %rdi,%r14
mov    0x90(%rsp),%r15
mov    0xa0(%rsp),%rdi
mov    0x98(%rsp),%rsi
mov    %rsp,%rdx
call   1070 <morus_initialization@plt>
mov    %r15,%r13
cmp    $0x20,%r15
jae    11ae <crypto_aead_decrypt+0x4e>
xor    %eax,%eax
jmp    11e2 <crypto_aead_decrypt+0x82>
xor    %r12d,%r12d
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%r12,%rbp,1),%rdi
lea    0x30(%rsp),%rsi
mov    %r15,%rdx
call   1080 <morus_enc_aut_step@plt>
lea    0x20(%r12),%rax
add    $0x40,%r12
cmp    %r13,%r12
mov    %rax,%r12
jbe    11c0 <crypto_aead_decrypt+0x60>
and    $0x1f,%r13
je     11fe <crypto_aead_decrypt+0x9e>
add    %rax,%rbp
lea    0x30(%rsp),%rsi
mov    %rsp,%rcx
mov    %rbp,%rdi
mov    %r13,%rdx
call   1060 <morus_enc_aut_partialblock@plt>
add    $0xfffffffffffffff0,%rbx
mov    0x20(%rsp),%r13
mov    %rbx,0x0(%r13)
cmp    $0x20,%rbx
mov    0x28(%rsp),%r15
jae    121d <crypto_aead_decrypt+0xbd>
xor    %esi,%esi
mov    %r14,%rdi
jmp    1257 <crypto_aead_decrypt+0xf7>
xor    %ebp,%ebp
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%r14,%rbp,1),%rdi
lea    (%r15,%rbp,1),%rsi
mov    %r12,%rdx
call   1030 <morus_dec_aut_step@plt>
mov    %r14,%rdi
mov    0x0(%r13),%rbx
lea    0x20(%rbp),%rsi
add    $0x40,%rbp
cmp    %rbx,%rbp
mov    %rsi,%rbp
jbe    1230 <crypto_aead_decrypt+0xd0>
mov    %rbx,%rdx
and    $0x1f,%rdx
je     1272 <crypto_aead_decrypt+0x112>
add    %rsi,%rdi
add    %r15,%rsi
mov    %rsp,%rcx
call   1050 <morus_dec_aut_partialblock@plt>
mov    0x0(%r13),%rbx
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    0x90(%rsp),%rsi
mov    %r15,%rdx
call   1040 <morus_tag_verification@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @crypto_aead_decrypt(i8* %0, i64* %1, i8* %2, i8* %3, i64 %4, i8* %5, i64 %6, i8* %7, i8* %8) {
%10 = alloca i8*
%11 = alloca i64*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i64
%20 = alloca i64
%21 = alloca [32 x i8]
%22 = alloca [16 x i8]
%23 = alloca i8
%24 = alloca [5 x i32]
store i8* %0, i8** %10
store i64* %1, i64** %11
store i8* %2, i8** %12
store i8* %3, i8** %13
store i64 %4, i64* %14
store i8* %5, i8** %15
store i64 %6, i64* %16
store i8* %7, i8** %17
store i8* %8, i8** %18
store i8 0, i8* %23
%25 = load i8*, i8** %18
%26 = load i8*, i8** %17
%27 = getelementptr inbounds [5 x i32], [5 x i32]* %24, i64 0, i64 0
%28 = call i32 @morus_initialization(i8* %25, i8* %26, i32* %27)
store i64 0, i64* %19
br label %29
29: ; preds = %41, %9
%30 = load i64, i64* %19
%31 = add i64 %30, 32
%32 = load i64, i64* %16
%33 = icmp ule i64 %31, %32
br i1 %33, label %34, label %44
34: ; preds = %29
%35 = load i8*, i8** %15
%36 = load i64, i64* %19
%37 = getelementptr inbounds i8, i8* %35, i64 %36
%38 = getelementptr inbounds [32 x i8], [32 x i8]* %21, i64 0, i64 0
%39 = getelementptr inbounds [5 x i32], [5 x i32]* %24, i64 0, i64 0
%40 = call i32 @morus_enc_aut_step(i8* %37, i8* %38, i32* %39)
br label %41
41: ; preds = %34
%42 = load i64, i64* %19
%43 = add i64 %42, 32
store i64 %43, i64* %19
br label %29
44: ; preds = %29
%45 = load i64, i64* %16
%46 = and i64 %45, 31
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %57
48: ; preds = %44
%49 = load i8*, i8** %15
%50 = load i64, i64* %19
%51 = getelementptr inbounds i8, i8* %49, i64 %50
%52 = getelementptr inbounds [32 x i8], [32 x i8]* %21, i64 0, i64 0
%53 = load i64, i64* %16
%54 = and i64 %53, 31
%55 = getelementptr inbounds [5 x i32], [5 x i32]* %24, i64 0, i64 0
%56 = call i32 @morus_enc_aut_partialblock(i8* %51, i8* %52, i64 %54, i32* %55)
br label %57
57: ; preds = %48, %44
%58 = load i64, i64* %14
%59 = sub i64 %58, 16
%60 = load i64*, i64** %11
store i64 %59, i64* %60
store i64 0, i64* %19
br label %61
61: ; preds = %76, %57
%62 = load i64, i64* %19
%63 = add i64 %62, 32
%64 = load i64*, i64** %11
%65 = load i64, i64* %64
%66 = icmp ule i64 %63, %65
br i1 %66, label %67, label %79
67: ; preds = %61
%68 = load i8*, i8** %10
%69 = load i64, i64* %19
%70 = getelementptr inbounds i8, i8* %68, i64 %69
%71 = load i8*, i8** %13
%72 = load i64, i64* %19
%73 = getelementptr inbounds i8, i8* %71, i64 %72
%74 = getelementptr inbounds [5 x i32], [5 x i32]* %24, i64 0, i64 0
%75 = call i32 @morus_dec_aut_step(i8* %70, i8* %73, i32* %74)
br label %76
76: ; preds = %67
%77 = load i64, i64* %19
%78 = add i64 %77, 32
store i64 %78, i64* %19
br label %61
79: ; preds = %61
%80 = load i64*, i64** %11
%81 = load i64, i64* %80
%82 = and i64 %81, 31
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %96
84: ; preds = %79
%85 = load i8*, i8** %10
%86 = load i64, i64* %19
%87 = getelementptr inbounds i8, i8* %85, i64 %86
%88 = load i8*, i8** %13
%89 = load i64, i64* %19
%90 = getelementptr inbounds i8, i8* %88, i64 %89
%91 = load i64*, i64** %11
%92 = load i64, i64* %91
%93 = and i64 %92, 31
%94 = getelementptr inbounds [5 x i32], [5 x i32]* %24, i64 0, i64 0
%95 = call i32 @morus_dec_aut_partialblock(i8* %87, i8* %90, i64 %93, i32* %94)
br label %96
96: ; preds = %84, %79
%97 = load i64*, i64** %11
%98 = load i64, i64* %97
%99 = load i64, i64* %16
%100 = load i8*, i8** %13
%101 = getelementptr inbounds [5 x i32], [5 x i32]* %24, i64 0, i64 0
%102 = call i32 @morus_tag_verification(i64 %98, i64 %99, i8* %100, i32* %101)
ret i32 %102
}

LLVM IR (-O2):
define i32 @crypto_aead_decrypt(i8* %0, i64* nocapture %1, i8* nocapture readnone %2, i8* %3, i64 %4, i8* %5, i64 %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 %6, 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* %5, 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, %6
br i1 %23, label %24, label %17
24: ; preds = %17, %9
%25 = phi i64 [ 0, %9 ], [ %18, %17 ]
%26 = and i64 %6, 31
%27 = icmp eq i64 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %24
%29 = getelementptr inbounds i8, i8* %5, 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 = add i64 %4, -16
store i64 %32, i64* %1
%33 = icmp ult i64 %32, 32
br i1 %33, label %43, label %34
34: ; preds = %31, %34
%35 = phi i64 [ %40, %34 ], [ 32, %31 ]
%36 = phi i64 [ %35, %34 ], [ 0, %31 ]
%37 = getelementptr inbounds i8, i8* %0, i64 %36
%38 = getelementptr inbounds i8, i8* %3, i64 %36
%39 = call i32 @morus_dec_aut_step(i8* %37, i8* %38, i32* %14)
%40 = add i64 %35, 32
%41 = load i64, i64* %1
%42 = icmp ugt i64 %40, %41
br i1 %42, label %43, label %34
43: ; preds = %34, %31
%44 = phi i64 [ 0, %31 ], [ %35, %34 ]
%45 = phi i64 [ %32, %31 ], [ %41, %34 ]
%46 = and i64 %45, 31
%47 = icmp eq i64 %46, 0
br i1 %47, label %53, label %48
48: ; preds = %43
%49 = getelementptr inbounds i8, i8* %0, i64 %44
%50 = getelementptr inbounds i8, i8* %3, i64 %44
%51 = call i32 @morus_dec_aut_partialblock(i8* %49, i8* %50, i64 %46, i32* %14)
%52 = load i64, i64* %1
br label %53
53: ; preds = %48, %43
%54 = phi i64 [ %52, %48 ], [ %45, %43 ]
%55 = call i32 @morus_tag_verification(i64 %54, i64 %6, i8* %3, i32* %14)
ret i32 %55
}