// File: /workspace/github_c_makefile_star2_O3/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 $0x908, %rsp            # imm = 0x908
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpq $0x10, %r8
jb 0xa48e
movq %r9, %r12
movq %r8, %r15
movq %rcx, %rbx
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq 0x950(%rsp), %rsi
movq 0x948(%rsp), %r14
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x10(%rsi), %rdx
leaq 0x48(%rsp), %rdi
callq 0x5160
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x3a(%r14), %rdx
leaq 0x28(%rsp), %rdi
movq %r14, %rsi
callq 0x5160
leaq 0x5f8(%rsp), %rdi
callq 0x5720
movq 0x940(%rsp), %rdx
leaq 0x170(%rsp), %r14
movq %r14, -0x10(%r14)
addq %r12, %rdx
leaq 0x160(%rsp), %rdi
movq %r12, %rsi
callq 0x5160
leaq 0x470(%rsp), %rdi
leaq 0x160(%rsp), %rsi
movl $0x18, %edx
callq 0x51f0
movq 0x160(%rsp), %rdi
cmpq %r14, %rdi
je 0xa143
movq 0x170(%rsp), %rsi
incq %rsi
callq 0x5060
leaq 0x160(%rsp), %rdi
callq 0x5720
leaq 0x2f8(%rsp), %r12
movq %r12, -0x10(%r12)
leaq (%rbx,%r15), %r14
addq $-0x10, %r14
leaq 0x2e8(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x5160
leaq 0x780(%rsp), %rdi
leaq 0x2e8(%rsp), %rsi
movl $0x18, %edx
callq 0x51f0
addq %r15, %rbx
movq 0x2e8(%rsp), %rdi
cmpq %r12, %rdi
je 0xa1b2
movq 0x2f8(%rsp), %rsi
incq %rsi
callq 0x5060
leaq 0xa8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x98(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x5160
leaq 0x2e8(%rsp), %rdi
leaq 0x98(%rsp), %rsi
movl $0x18, %edx
callq 0x51f0
movq 0x98(%rsp), %rdi
cmpq %r15, %rdi
je 0xa208
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x5060
leaq 0x98(%rsp), %rdi
movl $0x320, %esi            # imm = 0x320
movl $0xc, %edx
movl $0x1, %ecx
movl $0x100, %r8d            # imm = 0x100
movl $0x80, %r9d
callq 0x5550
movl $0x0, (%rsp)
leaq 0x98(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x28(%rsp), %rdx
leaq 0x5f8(%rsp), %r8
xorl %ecx, %ecx
movl $0x1, %r9d
callq 0x5080
movl $0x0, (%rsp)
leaq 0x98(%rsp), %rdi
leaq 0x780(%rsp), %rbp
leaq 0x160(%rsp), %r13
leaq 0x470(%rsp), %rcx
leaq 0x2e8(%rsp), %rbx
movq %rbp, %rsi
movq %r13, %rdx
movq %rbx, %r8
movl $0x1, %r9d
callq 0x5440
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testb %al, %al
je 0xa359
leaq 0x178(%rsp), %r14
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x54b0
movq 0x8(%rsp), %r15
leaq 0x78(%rsp), %rdi
movq %r14, %rsi
callq 0x54b0
leaq 0x88(%rsp), %r12
movq -0x8(%r12), %rdx
movq 0x70(%rsp), %rdi
movq %r15, %rsi
callq 0x5300
movq -0x10(%r12), %rdi
cmpq %r12, %rdi
je 0xa30a
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x5060
leaq 0x18(%rsp), %r15
movq -0x10(%r15), %rdi
cmpq %r15, %rdi
je 0xa325
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5060
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x54b0
movq 0x10(%rsp), %rax
movq 0x68(%rsp), %rcx
movq %rax, (%rcx)
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0xa356
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5060
xorl %r14d, %r14d
movq 0x130(%rsp), %rdi
testq %rdi, %rdi
je 0xa376
movq 0x140(%rsp), %rsi
subq %rdi, %rsi
callq 0x5060
leaq 0x100(%rsp), %r15
movq %r15, %rdi
callq 0x55d0
movq 0x4c13(%rip), %rax      # 0xefa0
addq $0x10, %rax
movq %rax, -0x68(%r15)
movq -0x30(%r15), %rdi
testq %rdi, %rdi
je 0xa3ae
movq 0xe0(%rsp), %rsi
subq %rdi, %rsi
callq 0x5060
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0xa3cb
movq 0xc8(%rsp), %rsi
subq %rdi, %rsi
callq 0x5060
movq 0x4bfe(%rip), %r15      # 0xefd0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x53b0
movl $0x80, %r12d
addq %r12, %rbx
movq %rbx, %rdi
callq 0x55b0
movq %rbp, %rdi
movq %r15, %rsi
callq 0x53b0
addq %r12, %rbp
movq %rbp, %rdi
callq 0x55b0
movq %r13, %rdi
movq %r15, %rsi
callq 0x53b0
addq %r12, %r13
movq %r13, %rdi
callq 0x55b0
leaq 0x470(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x53b0
addq %r12, %rbx
movq %rbx, %rdi
callq 0x55b0
leaq 0x5f8(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x53b0
addq %r12, %rbx
movq %rbx, %rdi
callq 0x55b0
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0xa472
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x5060
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xa48e
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x5060
movl %r14d, %eax
addq $0x908, %rsp            # imm = 0x908
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xa4c9
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa4cc
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5060
jmp 0xa4cc
jmp 0xa4c9
jmp 0xa4c9
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x50a0
jmp 0xa4de
movq %rax, %rbx
movq 0x4aeb(%rip), %rsi      # 0xefd0
leaq 0x2e8(%rsp), %rdi
callq 0x53b0
leaq 0x368(%rsp), %rdi
callq 0x55b0
movq 0x4aca(%rip), %rsi      # 0xefd0
leaq 0x780(%rsp), %rdi
callq 0x53b0
leaq 0x800(%rsp), %rdi
callq 0x55b0
movq 0x4aa9(%rip), %rsi      # 0xefd0
leaq 0x160(%rsp), %rdi
callq 0x53b0
leaq 0x1e0(%rsp), %rdi
callq 0x55b0
movq 0x4a88(%rip), %rsi      # 0xefd0
leaq 0x470(%rsp), %rdi
callq 0x53b0
leaq 0x4f0(%rsp), %rdi
callq 0x55b0
movq 0x4a67(%rip), %rsi      # 0xefd0
leaq 0x5f8(%rsp), %rdi
callq 0x53b0
leaq 0x678(%rsp), %rdi
callq 0x55b0
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0xa59f
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x5060
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xa5bb
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x5060
movq %rbx, %rdi
callq 0x5670
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %r15, %rdi
je 0xa4ff
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x5060
jmp 0xa4ff
movq %rax, %rbx
jmp 0xa4ff
movq %rax, %rbx
movq 0x2e8(%rsp), %rdi
cmpq %r12, %rdi
je 0xa520
movq 0x2f8(%rsp), %rsi
incq %rsi
callq 0x5060
jmp 0xa520
movq %rax, %rbx
jmp 0xa520
movq %rax, %rbx
jmp 0xa541
movq %rax, %rbx
movq 0x160(%rsp), %rdi
cmpq %r14, %rdi
je 0xa562
movq 0x170(%rsp), %rsi
incq %rsi
callq 0x5060
jmp 0xa562
movq %rax, %rbx
jmp 0xa562
movq %rax, %rbx
jmp 0xa583
movq %rax, %rbx
jmp 0xa59f