// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/riverkeyakv2/ref/encrypt.cpp
// Function: crypto_aead_decrypt
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
    )
{
    if (clen < CRYPTO_ABYTES)
        return -1;

    string K((const char *)k, CRYPTO_KEYBYTES);
    string N((const char *)npub, CRYPTO_NPUBBYTES);
    stringstream dummy;
    stringstream AD(string((const char *)ad, adlen));
    stringstream plaintext;
    stringstream ciphertext(string((const char *)c, clen-CRYPTO_ABYTES));
    stringstream tag(string((const char *)c+clen-CRYPTO_ABYTES, CRYPTO_ABYTES));

    RiverKeyak instance;
    instance.StartEngine(K, N, false, dummy, true, false);
    bool result = instance.Wrap(ciphertext, plaintext, AD, tag, true, false);

    if (result) {
        memcpy(m, plaintext.str().data(), plaintext.str().size());
        *mlen = plaintext.str().size();
        return 0;
    }
   else
       return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x8f8, %rsp            # imm = 0x8F8
cmpq $0x10, %r8
jae 0xa6bb
pushq $-0x1
popq %rbx
jmp 0xa947
movq %r9, %r13
movq %r8, %r12
movq %rcx, %r15
movq %rsi, %rbx
movq %rdi, %r14
movq 0x940(%rsp), %rsi
movq 0x938(%rsp), %rbp
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x10(%rsi), %rdx
leaq 0x48(%rsp), %rdi
callq 0x6220
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x3a(%rbp), %rdx
leaq 0x28(%rsp), %rdi
movq %rbp, %rsi
callq 0x6220
leaq 0x770(%rsp), %rdi
callq 0x6a50
movq 0x930(%rsp), %rdx
leaq 0x160(%rsp), %rax
movq %rax, -0x10(%rax)
addq %r13, %rdx
leaq 0x150(%rsp), %rdi
movq %r13, %rsi
callq 0x6220
leaq 0x5e8(%rsp), %rdi
leaq 0x150(%rsp), %rsi
pushq $0x18
popq %rdx
callq 0x62e0
leaq 0x150(%rsp), %rdi
callq 0x65b0
leaq 0x150(%rsp), %rdi
callq 0x6a50
leaq 0x2e8(%rsp), %rax
movq %rax, -0x10(%rax)
leaq (%r15,%r12), %r13
addq $-0x10, %r13
leaq 0x2d8(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x6220
leaq 0x460(%rsp), %rdi
leaq 0x2d8(%rsp), %rsi
pushq $0x18
popq %rdx
callq 0x62e0
addq %r12, %r15
leaq 0x2d8(%rsp), %rdi
callq 0x65b0
leaq 0x98(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x88(%rsp), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x6220
leaq 0x2d8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
pushq $0x18
popq %rdx
callq 0x62e0
leaq 0x88(%rsp), %rdi
callq 0x65b0
leaq 0x88(%rsp), %rdi
callq 0x6350
andl $0x0, (%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x28(%rsp), %rdx
leaq 0x770(%rsp), %r8
pushq $0x1
popq %r9
xorl %ecx, %ecx
callq 0x60b0
andl $0x0, (%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x460(%rsp), %rsi
leaq 0x150(%rsp), %rdx
leaq 0x5e8(%rsp), %rcx
leaq 0x2d8(%rsp), %r8
pushq $0x1
popq %r9
callq 0x6620
testb %al, %al
je 0xa8e2
leaq 0x168(%rsp), %r15
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x66e0
movq 0x8(%rsp), %r12
leaq 0x68(%rsp), %rdi
movq %r15, %rsi
callq 0x66e0
leaq 0x68(%rsp), %r13
movq 0x8(%r13), %rdx
movq %r14, %rdi
movq %r12, %rsi
callq 0x6480
movq %r13, %rdi
callq 0x65b0
leaq 0x8(%rsp), %rdi
callq 0x65b0
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x66e0
leaq 0x8(%rsp), %rdi
movq 0x8(%rdi), %rax
movq %rax, (%rbx)
callq 0x65b0
xorl %ebx, %ebx
jmp 0xa8e5
pushq $-0x1
popq %rbx
leaq 0x88(%rsp), %rdi
callq 0x60e0
leaq 0x2d8(%rsp), %rdi
callq 0x6a70
leaq 0x460(%rsp), %rdi
callq 0x6a70
leaq 0x150(%rsp), %rdi
callq 0x6a70
leaq 0x5e8(%rsp), %rdi
callq 0x6a70
leaq 0x770(%rsp), %rdi
callq 0x6a70
leaq 0x28(%rsp), %rdi
callq 0x65b0
leaq 0x48(%rsp), %rdi
callq 0x65b0
movl %ebx, %eax
addq $0x8f8, %rsp            # imm = 0x8F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xa970
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x65b0
jmp 0xa973
jmp 0xa970
jmp 0xa970
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x60e0
jmp 0xa985
movq %rax, %rbx
leaq 0x2d8(%rsp), %rdi
callq 0x6a70
leaq 0x460(%rsp), %rdi
callq 0x6a70
leaq 0x150(%rsp), %rdi
callq 0x6a70
leaq 0x5e8(%rsp), %rdi
callq 0x6a70
leaq 0x770(%rsp), %rdi
callq 0x6a70
leaq 0x28(%rsp), %rdi
callq 0x65b0
leaq 0x48(%rsp), %rdi
callq 0x65b0
movq %rbx, %rdi
callq 0x6980
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x65b0
jmp 0xa992
movq %rax, %rbx
jmp 0xa992
movq %rax, %rbx
leaq 0x2d8(%rsp), %rdi
callq 0x65b0
jmp 0xa99f
movq %rax, %rbx
jmp 0xa99f
movq %rax, %rbx
jmp 0xa9ac
movq %rax, %rbx
leaq 0x150(%rsp), %rdi
callq 0x65b0
jmp 0xa9b9
movq %rax, %rbx
jmp 0xa9b9
movq %rax, %rbx
jmp 0xa9c6
movq %rax, %rbx
jmp 0xa9d0