// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/riverkeyakv2/ref/encrypt.cpp
// Function: crypto_aead_encrypt
int crypto_aead_encrypt(
    unsigned char *c,unsigned long long *clen,
    const unsigned char *m,unsigned long long mlen,
    const unsigned char *ad,unsigned long long adlen,
    const unsigned char *nsec,
    const unsigned char *npub,
    const unsigned char *k
    )
{
    string K((const char *)k, (size_t)CRYPTO_KEYBYTES);
    string N((const char *)npub, (size_t)CRYPTO_NPUBBYTES);
    stringstream dummy;
    stringstream AD(string((const char *)ad, adlen));
    stringstream plaintext(string((const char *)m, mlen));
    stringstream ciphertext;
    stringstream tag;

    RiverKeyak instance;
    instance.StartEngine(K, N, false, dummy, false, false);
    instance.Wrap(plaintext, ciphertext, AD, tag, false, false);
    memcpy(c, ciphertext.str().data(), ciphertext.str().size());
    *clen = ciphertext.str().size();
    memcpy(c+ciphertext.str().size(), tag.str().data(), tag.str().size());
    *clen += tag.str().size();

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x928, %rsp            # imm = 0x928
movq %r9, %r13
movq %r8, %rbp
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, 0x30(%rsp)
movq %rdi, %r14
movq 0x968(%rsp), %rbx
movq 0x970(%rsp), %rsi
leaq 0x88(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x10(%rsi), %rdx
leaq 0x78(%rsp), %rdi
callq 0x6220
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x3a(%rbx), %rdx
leaq 0x58(%rsp), %rdi
movq %rbx, %rsi
callq 0x6220
leaq 0x7a0(%rsp), %rdi
callq 0x6a50
leaq 0x318(%rsp), %rax
movq %rax, -0x10(%rax)
addq %rbp, %r13
leaq 0x308(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x6220
leaq 0x618(%rsp), %rdi
leaq 0x308(%rsp), %rsi
pushq $0x18
popq %rdx
callq 0x62e0
movq 0x30(%rsp), %rbp
leaq 0x308(%rsp), %rdi
callq 0x65b0
leaq 0xc8(%rsp), %rax
movq %rax, -0x10(%rax)
addq %r12, %r15
leaq 0xb8(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x6220
leaq 0x308(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
pushq $0x18
popq %rdx
callq 0x62e0
leaq 0xb8(%rsp), %rdi
callq 0x65b0
leaq 0xb8(%rsp), %rdi
callq 0x6a50
leaq 0x490(%rsp), %rdi
callq 0x6a50
leaq 0x240(%rsp), %rdi
callq 0x6350
andl $0x0, (%rsp)
leaq 0x240(%rsp), %rdi
leaq 0x78(%rsp), %rsi
leaq 0x58(%rsp), %rdx
leaq 0x7a0(%rsp), %r8
xorl %ecx, %ecx
xorl %r9d, %r9d
callq 0x60b0
andl $0x0, (%rsp)
leaq 0x240(%rsp), %rdi
leaq 0x308(%rsp), %rsi
leaq 0xb8(%rsp), %rdx
leaq 0x618(%rsp), %rcx
leaq 0x490(%rsp), %r8
xorl %r9d, %r9d
callq 0x6620
leaq 0xd0(%rsp), %r15
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x66e0
movq 0x10(%rsp), %r12
leaq 0x38(%rsp), %rdi
movq %r15, %rsi
callq 0x66e0
leaq 0x38(%rsp), %rbx
movq 0x8(%rbx), %rdx
movq %r14, %rdi
movq %r12, %rsi
callq 0x6480
movq %rbx, %rdi
callq 0x65b0
leaq 0x10(%rsp), %rdi
callq 0x65b0
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x66e0
leaq 0x10(%rsp), %rdi
movq 0x8(%rdi), %rax
movq %rax, (%rbp)
callq 0x65b0
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x66e0
addq 0x18(%rsp), %r14
leaq 0x4a8(%rsp), %r15
leaq 0x38(%rsp), %rdi
movq %r15, %rsi
callq 0x66e0
movq 0x38(%rsp), %r12
leaq 0x98(%rsp), %rdi
movq %r15, %rsi
callq 0x66e0
leaq 0x98(%rsp), %rbx
movq 0x8(%rbx), %rdx
movq %r14, %rdi
movq %r12, %rsi
callq 0x6480
movq %rbx, %rdi
callq 0x65b0
leaq 0x38(%rsp), %rdi
callq 0x65b0
leaq 0x10(%rsp), %rdi
callq 0x65b0
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x66e0
leaq 0x10(%rsp), %rdi
movq 0x8(%rdi), %rax
addq %rax, (%rbp)
callq 0x65b0
leaq 0x240(%rsp), %rdi
callq 0x60e0
leaq 0x490(%rsp), %rdi
callq 0x6a70
leaq 0xb8(%rsp), %rdi
callq 0x6a70
leaq 0x308(%rsp), %rdi
callq 0x6a70
leaq 0x618(%rsp), %rdi
callq 0x6a70
leaq 0x7a0(%rsp), %rdi
callq 0x6a70
leaq 0x58(%rsp), %rdi
callq 0x65b0
leaq 0x78(%rsp), %rdi
callq 0x65b0
xorl %eax, %eax
addq $0x928, %rsp            # imm = 0x928
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xa62f
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x65b0
jmp 0xa5da
jmp 0xa5d7
jmp 0xa62f
jmp 0xa62f
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x65b0
jmp 0xa632
jmp 0xa62f
movq %rax, %rbx
jmp 0xa63f
movq %rax, %rbx
jmp 0xa64c
movq %rax, %rbx
jmp 0xa659
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x65b0
jmp 0xa666
movq %rax, %rbx
jmp 0xa666
movq %rax, %rbx
leaq 0x308(%rsp), %rdi
callq 0x65b0
jmp 0xa673
movq %rax, %rbx
jmp 0xa673
movq %rax, %rbx
jmp 0xa680
movq %rax, %rbx
jmp 0xa68a
movq %rax, %rbx
leaq 0x240(%rsp), %rdi
callq 0x60e0
leaq 0x490(%rsp), %rdi
callq 0x6a70
leaq 0xb8(%rsp), %rdi
callq 0x6a70
leaq 0x308(%rsp), %rdi
callq 0x6a70
leaq 0x618(%rsp), %rdi
callq 0x6a70
leaq 0x7a0(%rsp), %rdi
callq 0x6a70
leaq 0x58(%rsp), %rdi
callq 0x65b0
leaq 0x78(%rsp), %rdi
callq 0x65b0
movq %rbx, %rdi
callq 0x6980