#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 */

/* Variables and functions */
int AEAD_DEC(unsigned char const *, unsigned char const *,
             unsigned char const *, unsigned long long, unsigned char const *,
             unsigned long long, unsigned char *, unsigned char *,
             unsigned long long *);
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 cr;
  unsigned char tag[16];
  cr = clen + adlen;
  if ((cr < clen) && (cr < adlen))
    return -1;
  clen -= 16;
  if (clen % 32)
    return -1;
  do {
    int u;
    for (u = 0; u < 16; u++)
      (tag)[u] = (c + clen)[u];
  } while (0);
  return AEAD_DEC(k, npub, ad, adlen, c, clen, tag, m, mlen);
}


x86 assembly (clang, -O0):
<crypto_aead_decrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%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)
mov    -0x30(%rbp),%rax
add    0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    1170 <crypto_aead_decrypt+0x60>
mov    -0x40(%rbp),%rax
cmp    0x10(%rbp),%rax
jae    1170 <crypto_aead_decrypt+0x60>
movl   $0xffffffff,-0x4(%rbp)
jmp    1214 <crypto_aead_decrypt+0x104>
mov    -0x30(%rbp),%rax
sub    $0x10,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     119a <crypto_aead_decrypt+0x8a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1214 <crypto_aead_decrypt+0x104>
jmp    119f <crypto_aead_decrypt+0x8f>
movl   $0x0,-0x54(%rbp)
cmpl   $0x10,-0x54(%rbp)
jge    11d5 <crypto_aead_decrypt+0xc5>
mov    -0x28(%rbp),%rax
add    -0x30(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x54(%rbp),%rax
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11a6 <crypto_aead_decrypt+0x96>
jmp    11da <crypto_aead_decrypt+0xca>
mov    0x20(%rbp),%rdi
mov    0x18(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    0x10(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
lea    -0x50(%rbp),%r11
mov    -0x10(%rbp),%r10
mov    -0x18(%rbp),%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1030 <AEAD_DEC@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_aead_decrypt>:
sub    $0x18,%rsp
mov    %r9,%rdx
mov    %r8,%r9
mov    %rcx,%r8
mov    %rsi,%r11
mov    %rdi,%r10
mov    0x20(%rsp),%rcx
mov    %rcx,%rsi
mov    $0xffffffff,%eax
add    %r9,%rsi
jae    113f <crypto_aead_decrypt+0x2f>
cmp    %rcx,%rsi
jae    113f <crypto_aead_decrypt+0x2f>
add    $0x18,%rsp
ret
add    $0xfffffffffffffff0,%r9
test   $0x1f,%r9b
jne    113a <crypto_aead_decrypt+0x2a>
mov    0x30(%rsp),%rdi
mov    0x28(%rsp),%rsi
movups (%r8,%r9,1),%xmm0
movaps %xmm0,(%rsp)
sub    $0x8,%rsp
lea    0x8(%rsp),%rax
push   %r11
push   %r10
push   %rax
call   1030 <AEAD_DEC@plt>
add    $0x20,%rsp
add    $0x18,%rsp
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 [16 x i8]
%22 = alloca 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
%23 = load i64, i64* %15
%24 = load i64, i64* %17
%25 = add i64 %23, %24
store i64 %25, i64* %20
%26 = load i64, i64* %20
%27 = load i64, i64* %15
%28 = icmp ult i64 %26, %27
br i1 %28, label %29, label %34
29: ; preds = %9
%30 = load i64, i64* %20
%31 = load i64, i64* %17
%32 = icmp ult i64 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 -1, i32* %10
br label %72
34: ; preds = %29, %9
%35 = load i64, i64* %15
%36 = sub i64 %35, 16
store i64 %36, i64* %15
%37 = load i64, i64* %15
%38 = urem i64 %37, 32
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %34
store i32 -1, i32* %10
br label %72
41: ; preds = %34
br label %42
42: ; preds = %41
store i32 0, i32* %22
br label %43
43: ; preds = %57, %42
%44 = load i32, i32* %22
%45 = icmp slt i32 %44, 16
br i1 %45, label %46, label %60
46: ; preds = %43
%47 = load i8*, i8** %14
%48 = load i64, i64* %15
%49 = getelementptr inbounds i8, i8* %47, i64 %48
%50 = load i32, i32* %22
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8, i8* %52
%54 = load i32, i32* %22
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [16 x i8], [16 x i8]* %21, i64 0, i64 %55
store i8 %53, i8* %56
br label %57
57: ; preds = %46
%58 = load i32, i32* %22
%59 = add nsw i32 %58, 1
store i32 %59, i32* %22
br label %43
60: ; preds = %43
br label %61
61: ; preds = %60
%62 = load i8*, i8** %19
%63 = load i8*, i8** %18
%64 = load i8*, i8** %16
%65 = load i64, i64* %17
%66 = load i8*, i8** %14
%67 = load i64, i64* %15
%68 = getelementptr inbounds [16 x i8], [16 x i8]* %21, i64 0, i64 0
%69 = load i8*, i8** %11
%70 = load i64*, i64** %12
%71 = call i32 @AEAD_DEC(i8* %62, i8* %63, i8* %64, i64 %65, i8* %66, i64 %67, i8* %68, i8* %69, i64* %70)
store i32 %71, i32* %10
br label %72
72: ; preds = %61, %40, %33
%73 = load i32, i32* %10
ret i32 %73
}

LLVM IR (-O2):
define i32 @crypto_aead_decrypt(i8* %0, i64* %1, i8* nocapture readnone %2, i8* %3, i64 %4, i8* %5, i64 %6, i8* %7, i8* %8) {
%10 = alloca [16 x i8]
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%13 = add i64 %6, %4
%14 = icmp ult i64 %13, %4
%15 = icmp ult i64 %13, %6
%16 = and i1 %14, %15
br i1 %16, label %24, label %17
17: ; preds = %9
%18 = add i64 %4, -16
%19 = and i64 %18, 31
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = getelementptr inbounds i8, i8* %3, i64 %18
%23 = call i32 @AEAD_DEC(i8* %8, i8* %7, i8* %5, i64 %6, i8* %3, i64 %18, i8* %12, i8* %0, i64* %1)
br label %24
24: ; preds = %17, %9, %21
%25 = phi i32 [ %23, %21 ], [ -1, %9 ], [ -1, %17 ]
ret i32 %25
}