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

/* 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 *,
                                              int /*<<< orphan*/ *,
                                              unsigned long long,
                                              int /*<<< orphan*/ **);
int /*<<< orphan*/ morus_enc_aut_step(unsigned char const *,
                                      int /*<<< orphan*/ *,
                                      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 i, j;
  uint8_t plaintextblock[32], ciphertextblock[32];
  uint8_t tag[16];
  uint8_t check = 0;
  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);
  }
  *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    $0x1e0,%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)
movl   $0x0,-0x184(%rbp)
mov    0x20(%rbp),%rdi
mov    0x18(%rbp),%rsi
lea    -0x1e0(%rbp),%rdx
call   1070 <morus_initialization@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x20,%rax
cmp    0x10(%rbp),%rax
ja     11f3 <crypto_aead_decrypt+0x93>
mov    -0x30(%rbp),%rdi
add    -0x38(%rbp),%rdi
lea    -0x140(%rbp),%rsi
lea    -0x1e0(%rbp),%rdx
call   1080 <morus_enc_aut_step@plt>
mov    -0x38(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x38(%rbp)
jmp    11b5 <crypto_aead_decrypt+0x55>
mov    0x10(%rbp),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     1228 <crypto_aead_decrypt+0xc8>
mov    -0x30(%rbp),%rdi
add    -0x38(%rbp),%rdi
lea    -0x140(%rbp),%rsi
mov    0x10(%rbp),%rdx
and    $0x1f,%rdx
lea    -0x1e0(%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     1281 <crypto_aead_decrypt+0x121>
mov    -0x8(%rbp),%rdi
add    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    -0x38(%rbp),%rsi
lea    -0x1e0(%rbp),%rdx
call   1030 <morus_dec_aut_step@plt>
mov    -0x38(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x38(%rbp)
jmp    123f <crypto_aead_decrypt+0xdf>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     12bd <crypto_aead_decrypt+0x15d>
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    -0x1e0(%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    -0x1e0(%rbp),%rcx
call   1040 <morus_tag_verification@plt>
add    $0x1e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_aead_decrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
mov    %r9,%rbp
mov    %r8,%rbx
mov    %rcx,0x8(%rsp)
mov    %rsi,(%rsp)
mov    %rdi,%r14
mov    0x120(%rsp),%r15
mov    0x130(%rsp),%rdi
mov    0x128(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1070 <morus_initialization@plt>
mov    %r15,%r13
cmp    $0x20,%r15
jae    11b2 <crypto_aead_decrypt+0x52>
xor    %eax,%eax
jmp    11e2 <crypto_aead_decrypt+0x82>
xor    %r12d,%r12d
lea    0x10(%rsp),%r15
nopw   0x0(%rax,%rax,1)
lea    (%r12,%rbp,1),%rdi
lea    0x60(%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     1200 <crypto_aead_decrypt+0xa0>
add    %rax,%rbp
lea    0x60(%rsp),%rsi
lea    0x10(%rsp),%rcx
mov    %rbp,%rdi
mov    %r13,%rdx
call   1060 <morus_enc_aut_partialblock@plt>
add    $0xfffffffffffffff0,%rbx
mov    (%rsp),%r13
mov    %rbx,0x0(%r13)
cmp    $0x20,%rbx
mov    0x8(%rsp),%r15
jae    121e <crypto_aead_decrypt+0xbe>
xor    %esi,%esi
mov    %r14,%rdi
jmp    1257 <crypto_aead_decrypt+0xf7>
xor    %ebp,%ebp
lea    0x10(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
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     1274 <crypto_aead_decrypt+0x114>
add    %rsi,%rdi
add    %r15,%rsi
lea    0x10(%rsp),%rcx
call   1050 <morus_dec_aut_partialblock@plt>
mov    0x0(%r13),%rbx
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
mov    0x120(%rsp),%rsi
mov    %r15,%rdx
call   1040 <morus_tag_verification@plt>
add    $0xe8,%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 i32]
%22 = alloca [32 x i32]
%23 = alloca [16 x i32]
%24 = alloca i32
%25 = alloca [5 x [4 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 i32 0, i32* %24
%26 = load i8*, i8** %18
%27 = load i8*, i8** %17
%28 = getelementptr inbounds [5 x [4 x i32]], [5 x [4 x i32]]* %25, i64 0, i64 0
%29 = bitcast [4 x i32]* %28 to i32**
%30 = call i32 @morus_initialization(i8* %26, i8* %27, i32** %29)
store i64 0, i64* %19
br label %31
31: ; preds = %44, %9
%32 = load i64, i64* %19
%33 = add i64 %32, 32
%34 = load i64, i64* %16
%35 = icmp ule i64 %33, %34
br i1 %35, label %36, label %47
36: ; preds = %31
%37 = load i8*, i8** %15
%38 = load i64, i64* %19
%39 = getelementptr inbounds i8, i8* %37, i64 %38
%40 = getelementptr inbounds [32 x i32], [32 x i32]* %22, i64 0, i64 0
%41 = getelementptr inbounds [5 x [4 x i32]], [5 x [4 x i32]]* %25, i64 0, i64 0
%42 = bitcast [4 x i32]* %41 to i32**
%43 = call i32 @morus_enc_aut_step(i8* %39, i32* %40, i32** %42)
br label %44
44: ; preds = %36
%45 = load i64, i64* %19
%46 = add i64 %45, 32
store i64 %46, i64* %19
br label %31
47: ; preds = %31
%48 = load i64, i64* %16
%49 = and i64 %48, 31
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %61
51: ; preds = %47
%52 = load i8*, i8** %15
%53 = load i64, i64* %19
%54 = getelementptr inbounds i8, i8* %52, i64 %53
%55 = getelementptr inbounds [32 x i32], [32 x i32]* %22, i64 0, i64 0
%56 = load i64, i64* %16
%57 = and i64 %56, 31
%58 = getelementptr inbounds [5 x [4 x i32]], [5 x [4 x i32]]* %25, i64 0, i64 0
%59 = bitcast [4 x i32]* %58 to i32**
%60 = call i32 @morus_enc_aut_partialblock(i8* %54, i32* %55, i64 %57, i32** %59)
br label %61
61: ; preds = %51, %47
%62 = load i64, i64* %14
%63 = sub i64 %62, 16
%64 = load i64*, i64** %11
store i64 %63, i64* %64
store i64 0, i64* %19
br label %65
65: ; preds = %81, %61
%66 = load i64, i64* %19
%67 = add i64 %66, 32
%68 = load i64*, i64** %11
%69 = load i64, i64* %68
%70 = icmp ule i64 %67, %69
br i1 %70, label %71, label %84
71: ; preds = %65
%72 = load i8*, i8** %10
%73 = load i64, i64* %19
%74 = getelementptr inbounds i8, i8* %72, i64 %73
%75 = load i8*, i8** %13
%76 = load i64, i64* %19
%77 = getelementptr inbounds i8, i8* %75, i64 %76
%78 = getelementptr inbounds [5 x [4 x i32]], [5 x [4 x i32]]* %25, i64 0, i64 0
%79 = bitcast [4 x i32]* %78 to i32**
%80 = call i32 @morus_dec_aut_step(i8* %74, i8* %77, i32** %79)
br label %81
81: ; preds = %71
%82 = load i64, i64* %19
%83 = add i64 %82, 32
store i64 %83, i64* %19
br label %65
84: ; preds = %65
%85 = load i64*, i64** %11
%86 = load i64, i64* %85
%87 = and i64 %86, 31
%88 = icmp ne i64 %87, 0
br i1 %88, label %89, label %102
89: ; preds = %84
%90 = load i8*, i8** %10
%91 = load i64, i64* %19
%92 = getelementptr inbounds i8, i8* %90, i64 %91
%93 = load i8*, i8** %13
%94 = load i64, i64* %19
%95 = getelementptr inbounds i8, i8* %93, i64 %94
%96 = load i64*, i64** %11
%97 = load i64, i64* %96
%98 = and i64 %97, 31
%99 = getelementptr inbounds [5 x [4 x i32]], [5 x [4 x i32]]* %25, i64 0, i64 0
%100 = bitcast [4 x i32]* %99 to i32**
%101 = call i32 @morus_dec_aut_partialblock(i8* %92, i8* %95, i64 %98, i32** %100)
br label %102
102: ; preds = %89, %84
%103 = load i64*, i64** %11
%104 = load i64, i64* %103
%105 = load i64, i64* %16
%106 = load i8*, i8** %13
%107 = getelementptr inbounds [5 x [4 x i32]], [5 x [4 x i32]]* %25, i64 0, i64 0
%108 = bitcast [4 x i32]* %107 to i32**
%109 = call i32 @morus_tag_verification(i64 %104, i64 %105, i8* %106, i32** %108)
ret i32 %109
}

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 i32]
%11 = alloca [5 x [4 x i32]]
%12 = bitcast [32 x i32]* %10 to i8*
%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 %6, 32
br i1 %16, label %26, label %17
17: ; preds = %9
%18 = getelementptr inbounds [32 x i32], [32 x i32]* %10, i64 0, i64 0
br label %19
19: ; preds = %17, %19
%20 = phi i64 [ 32, %17 ], [ %24, %19 ]
%21 = phi i64 [ 0, %17 ], [ %20, %19 ]
%22 = getelementptr inbounds i8, i8* %5, i64 %21
%23 = call i32 @morus_enc_aut_step(i8* %22, i32* %18, i32** %14)
%24 = add i64 %20, 32
%25 = icmp ugt i64 %24, %6
br i1 %25, label %26, label %19
26: ; preds = %19, %9
%27 = phi i64 [ 0, %9 ], [ %20, %19 ]
%28 = and i64 %6, 31
%29 = icmp eq i64 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %26
%31 = getelementptr inbounds i8, i8* %5, i64 %27
%32 = getelementptr inbounds [32 x i32], [32 x i32]* %10, i64 0, i64 0
%33 = call i32 @morus_enc_aut_partialblock(i8* %31, i32* %32, i64 %28, i32** %14)
br label %34
34: ; preds = %30, %26
%35 = add i64 %4, -16
store i64 %35, i64* %1
%36 = icmp ult i64 %35, 32
br i1 %36, label %46, label %37
37: ; preds = %34, %37
%38 = phi i64 [ %43, %37 ], [ 32, %34 ]
%39 = phi i64 [ %38, %37 ], [ 0, %34 ]
%40 = getelementptr inbounds i8, i8* %0, i64 %39
%41 = getelementptr inbounds i8, i8* %3, i64 %39
%42 = call i32 @morus_dec_aut_step(i8* %40, i8* %41, i32** %14)
%43 = add i64 %38, 32
%44 = load i64, i64* %1
%45 = icmp ugt i64 %43, %44
br i1 %45, label %46, label %37
46: ; preds = %37, %34
%47 = phi i64 [ 0, %34 ], [ %38, %37 ]
%48 = phi i64 [ %35, %34 ], [ %44, %37 ]
%49 = and i64 %48, 31
%50 = icmp eq i64 %49, 0
br i1 %50, label %56, label %51
51: ; preds = %46
%52 = getelementptr inbounds i8, i8* %0, i64 %47
%53 = getelementptr inbounds i8, i8* %3, i64 %47
%54 = call i32 @morus_dec_aut_partialblock(i8* %52, i8* %53, i64 %49, i32** %14)
%55 = load i64, i64* %1
br label %56
56: ; preds = %51, %46
%57 = phi i64 [ %55, %51 ], [ %48, %46 ]
%58 = call i32 @morus_tag_verification(i64 %57, i64 %6, i8* %3, i32** %14)
ret i32 %58
}