#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];
  if (clen < 16)
    return -1;
  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    $0x1f0,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
movl   $0x0,-0x194(%rbp)
cmpq   $0x10,-0x30(%rbp)
jae    11b0 <crypto_aead_decrypt+0x50>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f2 <crypto_aead_decrypt+0x192>
mov    0x20(%rbp),%rdi
mov    0x18(%rbp),%rsi
lea    -0x1f0(%rbp),%rdx
call   1070 <morus_initialization@plt>
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    $0x20,%rax
cmp    0x10(%rbp),%rax
ja     120a <crypto_aead_decrypt+0xaa>
mov    -0x38(%rbp),%rdi
add    -0x40(%rbp),%rdi
lea    -0x150(%rbp),%rsi
lea    -0x1f0(%rbp),%rdx
call   1080 <morus_enc_aut_step@plt>
mov    -0x40(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x40(%rbp)
jmp    11cc <crypto_aead_decrypt+0x6c>
mov    0x10(%rbp),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     123f <crypto_aead_decrypt+0xdf>
mov    -0x38(%rbp),%rdi
add    -0x40(%rbp),%rdi
lea    -0x150(%rbp),%rsi
mov    0x10(%rbp),%rdx
and    $0x1f,%rdx
lea    -0x1f0(%rbp),%rcx
call   1060 <morus_enc_aut_partialblock@plt>
mov    -0x30(%rbp),%rcx
sub    $0x10,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    $0x20,%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
ja     1298 <crypto_aead_decrypt+0x138>
mov    -0x10(%rbp),%rdi
add    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    -0x40(%rbp),%rsi
lea    -0x1f0(%rbp),%rdx
call   1030 <morus_dec_aut_step@plt>
mov    -0x40(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x40(%rbp)
jmp    1256 <crypto_aead_decrypt+0xf6>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     12d4 <crypto_aead_decrypt+0x174>
mov    -0x10(%rbp),%rdi
add    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
and    $0x1f,%rdx
lea    -0x1f0(%rbp),%rcx
call   1050 <morus_dec_aut_partialblock@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    -0x1f0(%rbp),%rcx
call   1040 <morus_tag_verification@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_aead_decrypt>:
mov    $0xffffffff,%eax
cmp    $0x10,%r8
jb     12af <crypto_aead_decrypt+0x14f>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
mov    %r9,%rbp
mov    %r8,%rbx
mov    %rdi,%r13
mov    %rsi,(%rsp)
mov    %rcx,0x8(%rsp)
mov    0x130(%rsp),%rdi
mov    0x128(%rsp),%rsi
mov    0x120(%rsp),%r14
lea    0x10(%rsp),%rdx
call   1070 <morus_initialization@plt>
cmp    $0x20,%r14
jae    11c1 <crypto_aead_decrypt+0x61>
mov    %r14,%rdx
xor    %eax,%eax
jmp    11f8 <crypto_aead_decrypt+0x98>
xor    %r12d,%r12d
lea    0x60(%rsp),%r15
lea    0x10(%rsp),%r14
xchg   %ax,%ax
lea    (%r12,%rbp,1),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1080 <morus_enc_aut_step@plt>
mov    0x120(%rsp),%rdx
lea    0x20(%r12),%rax
add    $0x40,%r12
cmp    %rdx,%r12
mov    %rax,%r12
jbe    11d0 <crypto_aead_decrypt+0x70>
and    $0x1f,%rdx
je     1213 <crypto_aead_decrypt+0xb3>
add    %rax,%rbp
lea    0x60(%rsp),%rsi
lea    0x10(%rsp),%rcx
mov    %rbp,%rdi
call   1060 <morus_enc_aut_partialblock@plt>
add    $0xfffffffffffffff0,%rbx
mov    (%rsp),%r12
mov    %rbx,(%r12)
cmp    $0x20,%rbx
mov    0x8(%rsp),%r15
jae    122e <crypto_aead_decrypt+0xce>
xor    %esi,%esi
jmp    1266 <crypto_aead_decrypt+0x106>
xor    %ebp,%ebp
lea    0x10(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
add    %rbp,%rdi
lea    (%r15,%rbp,1),%rsi
mov    %r14,%rdx
call   1030 <morus_dec_aut_step@plt>
mov    (%r12),%rbx
lea    0x20(%rbp),%rsi
add    $0x40,%rbp
cmp    %rbx,%rbp
mov    %rsi,%rbp
jbe    1240 <crypto_aead_decrypt+0xe0>
mov    %rbx,%rdx
and    $0x1f,%rdx
je     1286 <crypto_aead_decrypt+0x126>
add    %rsi,%r13
add    %r15,%rsi
lea    0x10(%rsp),%rcx
mov    %r13,%rdi
call   1050 <morus_dec_aut_partialblock@plt>
mov    (%r12),%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 i32
%11 = alloca i8*
%12 = alloca i64*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i64
%21 = alloca i64
%22 = alloca [32 x i32]
%23 = alloca [32 x i32]
%24 = alloca [16 x i32]
%25 = alloca i32
%26 = alloca [5 x [4 x i32]]
store i8* %0, i8** %11
store i64* %1, i64** %12
store i8* %2, i8** %13
store i8* %3, i8** %14
store i64 %4, i64* %15
store i8* %5, i8** %16
store i64 %6, i64* %17
store i8* %7, i8** %18
store i8* %8, i8** %19
store i32 0, i32* %25
%27 = load i64, i64* %15
%28 = icmp ult i64 %27, 16
br i1 %28, label %29, label %30
29: ; preds = %9
store i32 -1, i32* %10
br label %115
30: ; preds = %9
%31 = load i8*, i8** %19
%32 = load i8*, i8** %18
%33 = getelementptr inbounds [5 x [4 x i32]], [5 x [4 x i32]]* %26, i64 0, i64 0
%34 = bitcast [4 x i32]* %33 to i32**
%35 = call i32 @morus_initialization(i8* %31, i8* %32, i32** %34)
store i64 0, i64* %20
br label %36
36: ; preds = %49, %30
%37 = load i64, i64* %20
%38 = add i64 %37, 32
%39 = load i64, i64* %17
%40 = icmp ule i64 %38, %39
br i1 %40, label %41, label %52
41: ; preds = %36
%42 = load i8*, i8** %16
%43 = load i64, i64* %20
%44 = getelementptr inbounds i8, i8* %42, i64 %43
%45 = getelementptr inbounds [32 x i32], [32 x i32]* %23, i64 0, i64 0
%46 = getelementptr inbounds [5 x [4 x i32]], [5 x [4 x i32]]* %26, i64 0, i64 0
%47 = bitcast [4 x i32]* %46 to i32**
%48 = call i32 @morus_enc_aut_step(i8* %44, i32* %45, i32** %47)
br label %49
49: ; preds = %41
%50 = load i64, i64* %20
%51 = add i64 %50, 32
store i64 %51, i64* %20
br label %36
52: ; preds = %36
%53 = load i64, i64* %17
%54 = and i64 %53, 31
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %66
56: ; preds = %52
%57 = load i8*, i8** %16
%58 = load i64, i64* %20
%59 = getelementptr inbounds i8, i8* %57, i64 %58
%60 = getelementptr inbounds [32 x i32], [32 x i32]* %23, i64 0, i64 0
%61 = load i64, i64* %17
%62 = and i64 %61, 31
%63 = getelementptr inbounds [5 x [4 x i32]], [5 x [4 x i32]]* %26, i64 0, i64 0
%64 = bitcast [4 x i32]* %63 to i32**
%65 = call i32 @morus_enc_aut_partialblock(i8* %59, i32* %60, i64 %62, i32** %64)
br label %66
66: ; preds = %56, %52
%67 = load i64, i64* %15
%68 = sub i64 %67, 16
%69 = load i64*, i64** %12
store i64 %68, i64* %69
store i64 0, i64* %20
br label %70
70: ; preds = %86, %66
%71 = load i64, i64* %20
%72 = add i64 %71, 32
%73 = load i64*, i64** %12
%74 = load i64, i64* %73
%75 = icmp ule i64 %72, %74
br i1 %75, label %76, label %89
76: ; preds = %70
%77 = load i8*, i8** %11
%78 = load i64, i64* %20
%79 = getelementptr inbounds i8, i8* %77, i64 %78
%80 = load i8*, i8** %14
%81 = load i64, i64* %20
%82 = getelementptr inbounds i8, i8* %80, i64 %81
%83 = getelementptr inbounds [5 x [4 x i32]], [5 x [4 x i32]]* %26, i64 0, i64 0
%84 = bitcast [4 x i32]* %83 to i32**
%85 = call i32 @morus_dec_aut_step(i8* %79, i8* %82, i32** %84)
br label %86
86: ; preds = %76
%87 = load i64, i64* %20
%88 = add i64 %87, 32
store i64 %88, i64* %20
br label %70
89: ; preds = %70
%90 = load i64*, i64** %12
%91 = load i64, i64* %90
%92 = and i64 %91, 31
%93 = icmp ne i64 %92, 0
br i1 %93, label %94, label %107
94: ; preds = %89
%95 = load i8*, i8** %11
%96 = load i64, i64* %20
%97 = getelementptr inbounds i8, i8* %95, i64 %96
%98 = load i8*, i8** %14
%99 = load i64, i64* %20
%100 = getelementptr inbounds i8, i8* %98, i64 %99
%101 = load i64*, i64** %12
%102 = load i64, i64* %101
%103 = and i64 %102, 31
%104 = getelementptr inbounds [5 x [4 x i32]], [5 x [4 x i32]]* %26, i64 0, i64 0
%105 = bitcast [4 x i32]* %104 to i32**
%106 = call i32 @morus_dec_aut_partialblock(i8* %97, i8* %100, i64 %103, i32** %105)
br label %107
107: ; preds = %94, %89
%108 = load i64*, i64** %12
%109 = load i64, i64* %108
%110 = load i64, i64* %17
%111 = load i8*, i8** %14
%112 = getelementptr inbounds [5 x [4 x i32]], [5 x [4 x i32]]* %26, i64 0, i64 0
%113 = bitcast [4 x i32]* %112 to i32**
%114 = call i32 @morus_tag_verification(i64 %109, i64 %110, i8* %111, i32** %113)
store i32 %114, i32* %10
br label %115
115: ; preds = %107, %29
%116 = load i32, i32* %10
ret i32 %116
}

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