// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xa88, %rsp            # imm = 0xA88
movq 0xaa0(%rsp), %rax
movq 0xa98(%rsp), %rax
movq 0xa90(%rsp), %rax
movq %rdi, 0xa78(%rsp)
movq %rsi, 0xa70(%rsp)
movq %rdx, 0xa68(%rsp)
movq %rcx, 0xa60(%rsp)
movq %r8, 0xa58(%rsp)
movq %r9, 0xa50(%rsp)
cmpq $0x10, 0xa58(%rsp)
jae 0x1992a
movl $0xffffffff, 0xa84(%rsp) # imm = 0xFFFFFFFF
jmp 0x19fcf
movq 0xaa0(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0xa2f(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0xdce0
movq 0x88(%rsp), %rsi
movq 0x90(%rsp), %rcx
leaq 0xa30(%rsp), %rdi
movl $0x10, %edx
callq 0xe060
jmp 0x19973
leaq 0xa2f(%rsp), %rdi
callq 0xe050
movq 0xa98(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x9f7(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0xdce0
movq 0x78(%rsp), %rsi
movq 0x80(%rsp), %rcx
leaq 0x9f8(%rsp), %rdi
movl $0x3a, %edx
callq 0xe060
jmp 0x199c3
leaq 0x9f7(%rsp), %rdi
callq 0xe050
leaq 0x868(%rsp), %rdi
callq 0xea00
jmp 0x199df
movq 0xa50(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0xa90(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0x6bf(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0xdce0
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0x70(%rsp), %rcx
leaq 0x6c0(%rsp), %rdi
callq 0xe060
jmp 0x19a29
movl $0x10, %edi
movl $0x8, %esi
callq 0xe850
movl %eax, 0x5c(%rsp)
jmp 0x19a3e
movl 0x5c(%rsp), %edx
leaq 0x6e0(%rsp), %rdi
leaq 0x6c0(%rsp), %rsi
callq 0xd730
jmp 0x19a59
leaq 0x6c0(%rsp), %rdi
callq 0xe450
leaq 0x6bf(%rsp), %rdi
callq 0xe050
leaq 0x530(%rsp), %rdi
callq 0xea00
jmp 0x19a82
movq 0xa60(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0xa58(%rsp), %rax
addq $-0x10, %rax
movq %rax, 0x48(%rsp)
leaq 0x387(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0xdce0
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq 0x50(%rsp), %rcx
leaq 0x388(%rsp), %rdi
callq 0xe060
jmp 0x19ad0
movl $0x10, %edi
movl $0x8, %esi
callq 0xe850
movl %eax, 0x3c(%rsp)
jmp 0x19ae5
movl 0x3c(%rsp), %edx
leaq 0x3a8(%rsp), %rdi
leaq 0x388(%rsp), %rsi
callq 0xd730
jmp 0x19b00
leaq 0x388(%rsp), %rdi
callq 0xe450
leaq 0x387(%rsp), %rdi
callq 0xe050
movq 0xa60(%rsp), %rax
movq 0xa58(%rsp), %rcx
leaq -0x10(%rax,%rcx), %rax
movq %rax, 0x28(%rsp)
leaq 0x1d7(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0xdce0
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rcx
leaq 0x1d8(%rsp), %rdi
movl $0x10, %edx
callq 0xe060
jmp 0x19b64
movl $0x10, %edi
movl $0x8, %esi
callq 0xe850
movl %eax, 0x24(%rsp)
jmp 0x19b79
movl 0x24(%rsp), %edx
leaq 0x1f8(%rsp), %rdi
leaq 0x1d8(%rsp), %rsi
callq 0xd730
jmp 0x19b94
leaq 0x1d8(%rsp), %rdi
callq 0xe450
leaq 0x1d7(%rsp), %rdi
callq 0xe050
leaq 0x108(%rsp), %rdi
callq 0xd870
jmp 0x19bbd
movq %rsp, %rax
movl $0x0, (%rax)
leaq 0x108(%rsp), %rdi
leaq 0xa30(%rsp), %rsi
leaq 0x9f8(%rsp), %rdx
xorl %ecx, %ecx
leaq 0x868(%rsp), %r8
movl $0x1, %r9d
callq 0xd180
jmp 0x19bf5
movq %rsp, %rax
movl $0x0, (%rax)
leaq 0x108(%rsp), %rdi
leaq 0x3a8(%rsp), %rsi
leaq 0x530(%rsp), %rdx
leaq 0x6e0(%rsp), %rcx
leaq 0x1f8(%rsp), %r8
movl $0x1, %r9d
callq 0xdf90
movb %al, 0x23(%rsp)
jmp 0x19c37
movb 0x23(%rsp), %al
andb $0x1, %al
movb %al, 0x107(%rsp)
testb $0x1, 0x107(%rsp)
je 0x19ee5
movq 0xa78(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0xe0(%rsp), %rdi
leaq 0x530(%rsp), %rsi
callq 0xe1f0
jmp 0x19c76
leaq 0xe0(%rsp), %rdi
callq 0xd2b0
movq %rax, 0x10(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0x530(%rsp), %rsi
callq 0xe1f0
jmp 0x19c9f
leaq 0xc0(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0xdbb0
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %rax, %rdx
callq 0xdbe0
movq 0x8(%rsp), %rdi
callq 0xe450
leaq 0xe0(%rsp), %rdi
callq 0xe450
leaq 0xa0(%rsp), %rdi
leaq 0x530(%rsp), %rsi
callq 0xe1f0
jmp 0x19cf1
leaq 0xa0(%rsp), %rdi
callq 0xdbb0
movq %rax, %rcx
movq 0xa70(%rsp), %rax
movq %rcx, (%rax)
leaq 0xa0(%rsp), %rdi
callq 0xe450
movl $0x0, 0xa84(%rsp)
movl $0x1, 0x9c(%rsp)
jmp 0x19efb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa20(%rsp)
movl %eax, 0xa1c(%rsp)
leaq 0xa2f(%rsp), %rdi
callq 0xe050
jmp 0x19fde
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa20(%rsp)
movl %eax, 0xa1c(%rsp)
leaq 0x9f7(%rsp), %rdi
callq 0xe050
jmp 0x19fc0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa20(%rsp)
movl %eax, 0xa1c(%rsp)
jmp 0x19fb3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa20(%rsp)
movl %eax, 0xa1c(%rsp)
jmp 0x19dd0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa20(%rsp)
movl %eax, 0xa1c(%rsp)
leaq 0x6c0(%rsp), %rdi
callq 0xe450
leaq 0x6bf(%rsp), %rdi
callq 0xe050
jmp 0x19fa6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa20(%rsp)
movl %eax, 0xa1c(%rsp)
jmp 0x19f99
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa20(%rsp)
movl %eax, 0xa1c(%rsp)
jmp 0x19e32
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa20(%rsp)
movl %eax, 0xa1c(%rsp)
leaq 0x388(%rsp), %rdi
callq 0xe450
leaq 0x387(%rsp), %rdi
callq 0xe050
jmp 0x19f8c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa20(%rsp)
movl %eax, 0xa1c(%rsp)
jmp 0x19e7b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa20(%rsp)
movl %eax, 0xa1c(%rsp)
leaq 0x1d8(%rsp), %rdi
callq 0xe450
leaq 0x1d7(%rsp), %rdi
callq 0xe050
jmp 0x19f7f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa20(%rsp)
movl %eax, 0xa1c(%rsp)
jmp 0x19f72
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa20(%rsp)
movl %eax, 0xa1c(%rsp)
jmp 0x19f65
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa20(%rsp)
movl %eax, 0xa1c(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0xe450
jmp 0x19f65
movl $0xffffffff, 0xa84(%rsp) # imm = 0xFFFFFFFF
movl $0x1, 0x9c(%rsp)
leaq 0x108(%rsp), %rdi
callq 0xdee0
leaq 0x1f8(%rsp), %rdi
callq 0xea90
leaq 0x3a8(%rsp), %rdi
callq 0xea90
leaq 0x530(%rsp), %rdi
callq 0xea90
leaq 0x6e0(%rsp), %rdi
callq 0xea90
leaq 0x868(%rsp), %rdi
callq 0xea90
leaq 0x9f8(%rsp), %rdi
callq 0xe450
leaq 0xa30(%rsp), %rdi
callq 0xe450
jmp 0x19fcf
leaq 0x108(%rsp), %rdi
callq 0xdee0
leaq 0x1f8(%rsp), %rdi
callq 0xea90
leaq 0x3a8(%rsp), %rdi
callq 0xea90
leaq 0x530(%rsp), %rdi
callq 0xea90
leaq 0x6e0(%rsp), %rdi
callq 0xea90
leaq 0x868(%rsp), %rdi
callq 0xea90
leaq 0x9f8(%rsp), %rdi
callq 0xe450
leaq 0xa30(%rsp), %rdi
callq 0xe450
jmp 0x19fde
movl 0xa84(%rsp), %eax
addq $0xa88, %rsp            # imm = 0xA88
retq
movq 0xa20(%rsp), %rdi
callq 0xe7c0
nopl (%rax,%rax)