// File: /workspace/github_c_makefile_star2_O1/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 0xa526
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 0x5730
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 0xa1db
movq 0x170(%rsp), %rsi
incq %rsi
callq 0x5060
leaq 0x160(%rsp), %rdi
callq 0x5730
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
movq 0x2e8(%rsp), %rdi
cmpq %r12, %rdi
je 0xa247
movq 0x2f8(%rsp), %rsi
incq %rsi
callq 0x5060
addq %r15, %rbx
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 0xa2a0
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 0x5560
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 0xa3f1
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 0xa3a2
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x5060
leaq 0x18(%rsp), %r15
movq -0x10(%r15), %rdi
cmpq %r15, %rdi
je 0xa3bd
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 0xa3ee
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5060
xorl %r14d, %r14d
movq 0x130(%rsp), %rdi
testq %rdi, %rdi
je 0xa40e
movq 0x140(%rsp), %rsi
subq %rdi, %rsi
callq 0x5060
leaq 0x100(%rsp), %r15
movq %r15, %rdi
callq 0x55e0
movq 0x4b7b(%rip), %rax      # 0xefa0
addq $0x10, %rax
movq %rax, -0x68(%r15)
movq -0x30(%r15), %rdi
testq %rdi, %rdi
je 0xa446
movq 0xe0(%rsp), %rsi
subq %rdi, %rsi
callq 0x5060
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0xa463
movq 0xc8(%rsp), %rsi
subq %rdi, %rsi
callq 0x5060
movq 0x4b66(%rip), %r15      # 0xefd0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x53b0
movl $0x80, %r12d
addq %r12, %rbx
movq %rbx, %rdi
callq 0x55c0
movq %rbp, %rdi
movq %r15, %rsi
callq 0x53b0
addq %r12, %rbp
movq %rbp, %rdi
callq 0x55c0
movq %r13, %rdi
movq %r15, %rsi
callq 0x53b0
addq %r12, %r13
movq %r13, %rdi
callq 0x55c0
leaq 0x470(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x53b0
addq %r12, %rbx
movq %rbx, %rdi
callq 0x55c0
leaq 0x5f8(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x53b0
addq %r12, %rbx
movq %rbx, %rdi
callq 0x55c0
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0xa50a
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x5060
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xa526
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 0xa561
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa564
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5060
jmp 0xa564
jmp 0xa561
jmp 0xa561
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x50a0
jmp 0xa576
movq %rax, %rbx
movq 0x4a53(%rip), %rsi      # 0xefd0
leaq 0x2e8(%rsp), %rdi
callq 0x53b0
leaq 0x368(%rsp), %rdi
callq 0x55c0
movq 0x4a32(%rip), %rsi      # 0xefd0
leaq 0x780(%rsp), %rdi
callq 0x53b0
leaq 0x800(%rsp), %rdi
callq 0x55c0
movq 0x4a11(%rip), %rsi      # 0xefd0
leaq 0x160(%rsp), %rdi
callq 0x53b0
leaq 0x1e0(%rsp), %rdi
callq 0x55c0
movq 0x49f0(%rip), %rsi      # 0xefd0
leaq 0x470(%rsp), %rdi
callq 0x53b0
leaq 0x4f0(%rsp), %rdi
callq 0x55c0
movq 0x49cf(%rip), %rsi      # 0xefd0
leaq 0x5f8(%rsp), %rdi
callq 0x53b0
leaq 0x678(%rsp), %rdi
callq 0x55c0
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0xa637
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x5060
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xa653
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x5060
movq %rbx, %rdi
callq 0x5680
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %r15, %rdi
je 0xa597
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x5060
jmp 0xa597
movq %rax, %rbx
jmp 0xa597
movq %rax, %rbx
movq 0x2e8(%rsp), %rdi
cmpq %r12, %rdi
je 0xa5b8
movq 0x2f8(%rsp), %rsi
incq %rsi
callq 0x5060
jmp 0xa5b8
movq %rax, %rbx
jmp 0xa5b8
movq %rax, %rbx
jmp 0xa5d9
movq %rax, %rbx
movq 0x160(%rsp), %rdi
cmpq %r14, %rdi
je 0xa5fa
movq 0x170(%rsp), %rsi
incq %rsi
callq 0x5060
jmp 0xa5fa
movq %rax, %rbx
jmp 0xa5fa
movq %rax, %rbx
jmp 0xa61b
movq %rax, %rbx
jmp 0xa637