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

/* 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) {
  uint64_t i, j;
  uint8_t plaintextblock[32], ciphertextblock[32];
  uint8_t tag[16];
  uint8_t check = 0;
  __m128i morus_state[5][2];
  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    $0x1b0,%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    -0x1b0(%rbp),%rdx
call   1070 <morus_initialization@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x20,%eax
cltq
cmp    0x10(%rbp),%rax
ja     11f2 <crypto_aead_decrypt+0x92>
mov    -0x30(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
lea    -0x140(%rbp),%rsi
lea    -0x1b0(%rbp),%rdx
call   1080 <morus_enc_aut_step@plt>
mov    -0x34(%rbp),%eax
add    $0x20,%eax
mov    %eax,-0x34(%rbp)
jmp    11b4 <crypto_aead_decrypt+0x54>
mov    0x10(%rbp),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     122a <crypto_aead_decrypt+0xca>
mov    -0x30(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
lea    -0x140(%rbp),%rsi
mov    0x10(%rbp),%rdx
and    $0x1f,%rdx
lea    -0x1b0(%rbp),%rcx
call   1060 <morus_enc_aut_partialblock@plt>
mov    -0x28(%rbp),%rcx
sub    $0x10,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x20,%eax
cltq
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
ja     1285 <crypto_aead_decrypt+0x125>
mov    -0x8(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
lea    -0x1b0(%rbp),%rdx
call   1030 <morus_dec_aut_step@plt>
mov    -0x34(%rbp),%eax
add    $0x20,%eax
mov    %eax,-0x34(%rbp)
jmp    1240 <crypto_aead_decrypt+0xe0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     12c7 <crypto_aead_decrypt+0x167>
mov    -0x8(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
and    $0x1f,%rdx
lea    -0x1b0(%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    -0x1b0(%rbp),%rcx
call   1040 <morus_tag_verification@plt>
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_aead_decrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
mov    %r9,%rbp
mov    %r8,%r14
mov    %rcx,%r12
mov    %rsi,%rbx
mov    %rdi,%r15
mov    0x100(%rsp),%r13
mov    0x110(%rsp),%rdi
mov    0x108(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1070 <morus_initialization@plt>
cmp    $0x20,%r13
mov    %rbx,(%rsp)
jae    11b4 <crypto_aead_decrypt+0x54>
mov    %r13,%rsi
xor    %r13d,%r13d
jmp    120b <crypto_aead_decrypt+0xab>
mov    %r12,0x8(%rsp)
xor    %r13d,%r13d
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%r12
add    $0x20,%r13
lea    (%r12,%rbp,1),%rdi
lea    0x40(%rsp),%rsi
mov    %rbx,%rdx
call   1080 <morus_enc_aut_step@plt>
add    $0x40,%r12
cmp    0x100(%rsp),%r12
jbe    11d0 <crypto_aead_decrypt+0x70>
and    $0xffffffe0,%r13d
mov    0x8(%rsp),%r12
mov    0x100(%rsp),%rsi
mov    (%rsp),%rbx
mov    %rsi,%rdx
and    $0x1f,%rdx
je     122f <crypto_aead_decrypt+0xcf>
add    %r13,%rbp
mov    %rsi,%r13
lea    0x40(%rsp),%rsi
lea    0x10(%rsp),%rcx
mov    %rbp,%rdi
call   1060 <morus_enc_aut_partialblock@plt>
mov    %r13,%rsi
add    $0xfffffffffffffff0,%r14
mov    %r14,(%rbx)
xor    %ebx,%ebx
cmp    $0x20,%r14
jae    1243 <crypto_aead_decrypt+0xe3>
mov    %r15,%rdi
jmp    1284 <crypto_aead_decrypt+0x124>
mov    (%rsp),%r13
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rbp
add    $0x20,%rbx
lea    (%r15,%rbp,1),%rdi
lea    (%r12,%rbp,1),%rsi
lea    0x10(%rsp),%rdx
call   1030 <morus_dec_aut_step@plt>
mov    0x0(%r13),%r14
add    $0x40,%rbp
cmp    %rbp,%r14
jae    1250 <crypto_aead_decrypt+0xf0>
mov    %r15,%rdi
and    $0xffffffe0,%ebx
mov    0x100(%rsp),%rsi
mov    %r14,%rdx
and    $0x1f,%rdx
je     12ad <crypto_aead_decrypt+0x14d>
add    %rbx,%rdi
add    %r12,%rbx
lea    0x10(%rsp),%rcx
mov    %rsi,%rbp
mov    %rbx,%rsi
call   1050 <morus_dec_aut_partialblock@plt>
mov    %rbp,%rsi
mov    (%rsp),%rax
mov    (%rax),%r14
lea    0x10(%rsp),%rcx
mov    %r14,%rdi
mov    %r12,%rdx
call   1040 <morus_tag_verification@plt>
add    $0xc8,%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 i32
%20 = alloca i32
%21 = alloca [32 x i32]
%22 = alloca [32 x i32]
%23 = alloca [16 x i32]
%24 = alloca i32
%25 = alloca [5 x [2 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 [2 x i32]], [5 x [2 x i32]]* %25, 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* %16
%36 = icmp ule i64 %34, %35
br i1 %36, label %37, label %49
37: ; preds = %31
%38 = load i8*, i8** %15
%39 = load i32, i32* %19
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = getelementptr inbounds [32 x i32], [32 x i32]* %22, i64 0, i64 0
%43 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %25, i64 0, i64 0
%44 = bitcast [2 x i32]* %43 to i32**
%45 = call i32 @morus_enc_aut_step(i8* %41, i32* %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* %16
%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** %15
%55 = load i32, i32* %19
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = getelementptr inbounds [32 x i32], [32 x i32]* %22, i64 0, i64 0
%59 = load i64, i64* %16
%60 = and i64 %59, 31
%61 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %25, i64 0, i64 0
%62 = bitcast [2 x i32]* %61 to i32**
%63 = call i32 @morus_enc_aut_partialblock(i8* %57, i32* %58, i64 %60, i32** %62)
br label %64
64: ; preds = %53, %49
%65 = load i64, i64* %14
%66 = sub i64 %65, 16
%67 = load i64*, i64** %11
store i64 %66, i64* %67
store i32 0, i32* %19
br label %68
68: ; preds = %87, %64
%69 = load i32, i32* %19
%70 = add nsw i32 %69, 32
%71 = sext i32 %70 to i64
%72 = load i64*, i64** %11
%73 = load i64, i64* %72
%74 = icmp ule i64 %71, %73
br i1 %74, label %75, label %90
75: ; preds = %68
%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 = load i8*, i8** %13
%81 = load i32, i32* %19
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
%84 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %25, i64 0, i64 0
%85 = bitcast [2 x i32]* %84 to i32**
%86 = call i32 @morus_dec_aut_step(i8* %79, i8* %83, i32** %85)
br label %87
87: ; preds = %75
%88 = load i32, i32* %19
%89 = add nsw i32 %88, 32
store i32 %89, i32* %19
br label %68
90: ; preds = %68
%91 = load i64*, i64** %11
%92 = load i64, i64* %91
%93 = and i64 %92, 31
%94 = icmp ne i64 %93, 0
br i1 %94, label %95, label %110
95: ; preds = %90
%96 = load i8*, i8** %10
%97 = load i32, i32* %19
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8, i8* %96, i64 %98
%100 = load i8*, i8** %13
%101 = load i32, i32* %19
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i8, i8* %100, i64 %102
%104 = load i64*, i64** %11
%105 = load i64, i64* %104
%106 = and i64 %105, 31
%107 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %25, i64 0, i64 0
%108 = bitcast [2 x i32]* %107 to i32**
%109 = call i32 @morus_dec_aut_partialblock(i8* %99, i8* %103, i64 %106, i32** %108)
br label %110
110: ; preds = %95, %90
%111 = load i64*, i64** %11
%112 = load i64, i64* %111
%113 = load i64, i64* %16
%114 = load i8*, i8** %13
%115 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %25, i64 0, i64 0
%116 = bitcast [2 x i32]* %115 to i32**
%117 = call i32 @morus_tag_verification(i64 %112, i64 %113, i8* %114, i32** %116)
ret i32 %117
}

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