#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;
  uint8_t ciphertextblock[32];
  __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    $0xf0,%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    0x20(%rbp),%rdi
mov    0x18(%rbp),%rsi
lea    -0xf0(%rbp),%rdx
call   1070 <morus_initialization@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x20,%eax
cltq
cmp    0x10(%rbp),%rax
ja     11e8 <crypto_aead_decrypt+0x88>
mov    -0x30(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
lea    -0xc0(%rbp),%rsi
lea    -0xf0(%rbp),%rdx
call   1080 <morus_enc_aut_step@plt>
mov    -0x34(%rbp),%eax
add    $0x20,%eax
mov    %eax,-0x34(%rbp)
jmp    11aa <crypto_aead_decrypt+0x4a>
mov    0x10(%rbp),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     1220 <crypto_aead_decrypt+0xc0>
mov    -0x30(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
lea    -0xc0(%rbp),%rsi
mov    0x10(%rbp),%rdx
and    $0x1f,%rdx
lea    -0xf0(%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     127b <crypto_aead_decrypt+0x11b>
mov    -0x8(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
lea    -0xf0(%rbp),%rdx
call   1030 <morus_dec_aut_step@plt>
mov    -0x34(%rbp),%eax
add    $0x20,%eax
mov    %eax,-0x34(%rbp)
jmp    1236 <crypto_aead_decrypt+0xd6>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     12bd <crypto_aead_decrypt+0x15d>
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    -0xf0(%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    -0xf0(%rbp),%rcx
call   1040 <morus_tag_verification@plt>
add    $0xf0,%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 [32 x i32]
%21 = 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
%22 = load i8*, i8** %18
%23 = load i8*, i8** %17
%24 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %21, i64 0, i64 0
%25 = bitcast [2 x i32]* %24 to i32**
%26 = call i32 @morus_initialization(i8* %22, i8* %23, i32** %25)
store i32 0, i32* %19
br label %27
27: ; preds = %42, %9
%28 = load i32, i32* %19
%29 = add nsw i32 %28, 32
%30 = sext i32 %29 to i64
%31 = load i64, i64* %16
%32 = icmp ule i64 %30, %31
br i1 %32, label %33, label %45
33: ; preds = %27
%34 = load i8*, i8** %15
%35 = load i32, i32* %19
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = getelementptr inbounds [32 x i32], [32 x i32]* %20, i64 0, i64 0
%39 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %21, i64 0, i64 0
%40 = bitcast [2 x i32]* %39 to i32**
%41 = call i32 @morus_enc_aut_step(i8* %37, i32* %38, i32** %40)
br label %42
42: ; preds = %33
%43 = load i32, i32* %19
%44 = add nsw i32 %43, 32
store i32 %44, i32* %19
br label %27
45: ; preds = %27
%46 = load i64, i64* %16
%47 = and i64 %46, 31
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %60
49: ; preds = %45
%50 = load i8*, i8** %15
%51 = load i32, i32* %19
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = getelementptr inbounds [32 x i32], [32 x i32]* %20, i64 0, i64 0
%55 = load i64, i64* %16
%56 = and i64 %55, 31
%57 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %21, i64 0, i64 0
%58 = bitcast [2 x i32]* %57 to i32**
%59 = call i32 @morus_enc_aut_partialblock(i8* %53, i32* %54, i64 %56, i32** %58)
br label %60
60: ; preds = %49, %45
%61 = load i64, i64* %14
%62 = sub i64 %61, 16
%63 = load i64*, i64** %11
store i64 %62, i64* %63
store i32 0, i32* %19
br label %64
64: ; preds = %83, %60
%65 = load i32, i32* %19
%66 = add nsw i32 %65, 32
%67 = sext i32 %66 to i64
%68 = load i64*, i64** %11
%69 = load i64, i64* %68
%70 = icmp ule i64 %67, %69
br i1 %70, label %71, label %86
71: ; preds = %64
%72 = load i8*, i8** %10
%73 = load i32, i32* %19
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %72, i64 %74
%76 = load i8*, i8** %13
%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]]* %21, i64 0, i64 0
%81 = bitcast [2 x i32]* %80 to i32**
%82 = call i32 @morus_dec_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 %64
86: ; preds = %64
%87 = load i64*, i64** %11
%88 = load i64, i64* %87
%89 = and i64 %88, 31
%90 = icmp ne i64 %89, 0
br i1 %90, label %91, label %106
91: ; preds = %86
%92 = load i8*, i8** %10
%93 = load i32, i32* %19
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i8, i8* %92, i64 %94
%96 = load i8*, i8** %13
%97 = load i32, i32* %19
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8, i8* %96, i64 %98
%100 = load i64*, i64** %11
%101 = load i64, i64* %100
%102 = and i64 %101, 31
%103 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %21, i64 0, i64 0
%104 = bitcast [2 x i32]* %103 to i32**
%105 = call i32 @morus_dec_aut_partialblock(i8* %95, i8* %99, i64 %102, i32** %104)
br label %106
106: ; preds = %91, %86
%107 = load i64*, i64** %11
%108 = load i64, i64* %107
%109 = load i64, i64* %16
%110 = load i8*, i8** %13
%111 = getelementptr inbounds [5 x [2 x i32]], [5 x [2 x i32]]* %21, i64 0, i64 0
%112 = bitcast [2 x i32]* %111 to i32**
%113 = call i32 @morus_tag_verification(i64 %108, i64 %109, i8* %110, i32** %112)
ret i32 %113
}

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
}