// File: /workspace/github_c_makefile_star2_O1/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, %r15
movq %r8, %r12
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, 0x30(%rsp)
movq %rdi, %rbp
movq 0x968(%rsp), %r13
movq 0x970(%rsp), %rsi
leaq 0x88(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x10(%rsi), %rdx
leaq 0x78(%rsp), %rdi
callq 0x5160
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x3a(%r13), %rdx
leaq 0x58(%rsp), %rdi
movq %r13, %rsi
callq 0x5160
leaq 0x7a0(%rsp), %rdi
callq 0x5730
leaq 0x318(%rsp), %r13
movq %r13, -0x10(%r13)
addq %r12, %r15
leaq 0x308(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x5160
leaq 0x618(%rsp), %rdi
leaq 0x308(%rsp), %rsi
movl $0x18, %edx
callq 0x51f0
movq %rbp, %r12
movq 0x308(%rsp), %rdi
cmpq %r13, %rdi
je 0x9b3a
movq 0x318(%rsp), %rsi
incq %rsi
callq 0x5060
leaq 0x190(%rsp), %r15
movq %r15, -0x10(%r15)
addq %r14, %rbx
leaq 0x180(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x5160
leaq 0x308(%rsp), %rdi
leaq 0x180(%rsp), %rsi
movl $0x18, %edx
callq 0x51f0
movq 0x180(%rsp), %rdi
cmpq %r15, %rdi
je 0x9b93
movq 0x190(%rsp), %rsi
incq %rsi
callq 0x5060
leaq 0x180(%rsp), %rdi
callq 0x5730
leaq 0x490(%rsp), %rdi
callq 0x5730
leaq 0xb8(%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 0xb8(%rsp), %rdi
leaq 0x78(%rsp), %rsi
leaq 0x58(%rsp), %rdx
leaq 0x7a0(%rsp), %r8
xorl %ecx, %ecx
xorl %r9d, %r9d
callq 0x5080
movl $0x0, (%rsp)
leaq 0xb8(%rsp), %rdi
leaq 0x308(%rsp), %rsi
leaq 0x180(%rsp), %rbp
leaq 0x618(%rsp), %rcx
leaq 0x490(%rsp), %rbx
movq %rbp, %rdx
movq %rbx, %r8
xorl %r9d, %r9d
callq 0x5440
leaq 0x198(%rsp), %r15
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x54b0
movq 0x10(%rsp), %r14
leaq 0x38(%rsp), %rdi
movq %r15, %rsi
callq 0x54b0
leaq 0x48(%rsp), %r13
movq -0x8(%r13), %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0x5300
movq -0x10(%r13), %rdi
cmpq %r13, %rdi
je 0x9c8e
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x5060
leaq 0x20(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x9ca9
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5060
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x54b0
movq 0x18(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rax, (%rcx)
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x9cda
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5060
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x54b0
addq 0x18(%rsp), %r12
leaq 0x4a8(%rsp), %r15
leaq 0x38(%rsp), %rdi
movq %r15, %rsi
callq 0x54b0
movq %r12, %r13
movq 0x38(%rsp), %r14
leaq 0x98(%rsp), %rdi
movq %r15, %rsi
callq 0x54b0
leaq 0xa8(%rsp), %r12
movq -0x8(%r12), %rdx
movq %r13, %rdi
movq %r14, %rsi
callq 0x5300
movq -0x10(%r12), %rdi
cmpq %r12, %rdi
je 0x9d4b
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x5060
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
leaq 0x7a0(%rsp), %r12
leaq 0x618(%rsp), %r13
leaq 0x20(%rsp), %r14
je 0x9d7c
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x5060
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x9d93
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5060
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x54b0
movq 0x18(%rsp), %rax
movq 0x30(%rsp), %rcx
addq %rax, (%rcx)
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x9dc4
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5060
movq 0x150(%rsp), %rdi
testq %rdi, %rdi
je 0x9de1
movq 0x160(%rsp), %rsi
subq %rdi, %rsi
callq 0x5060
leaq 0x120(%rsp), %r14
movq %r14, %rdi
callq 0x55e0
movq 0x51a8(%rip), %rax      # 0xefa0
addq $0x10, %rax
movq %rax, -0x68(%r14)
movq -0x30(%r14), %rdi
testq %rdi, %rdi
je 0x9e19
movq 0x100(%rsp), %rsi
subq %rdi, %rsi
callq 0x5060
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0x9e36
movq 0xe8(%rsp), %rsi
subq %rdi, %rsi
callq 0x5060
movq 0x5193(%rip), %r15      # 0xefd0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x53b0
movl $0x80, %r14d
addq %r14, %rbx
movq %rbx, %rdi
callq 0x55c0
movq %rbp, %rdi
movq %r15, %rsi
callq 0x53b0
addq %r14, %rbp
movq %rbp, %rdi
callq 0x55c0
leaq 0x308(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x53b0
addq %r14, %rbx
movq %rbx, %rdi
callq 0x55c0
movq %r13, %rdi
movq %r15, %rsi
callq 0x53b0
addq %r14, %r13
movq %r13, %rdi
callq 0x55c0
movq %r12, %rdi
movq %r15, %rsi
callq 0x53b0
addq %r14, %r12
movq %r12, %rdi
callq 0x55c0
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x9ed5
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x5060
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x9ef7
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x5060
xorl %eax, %eax
addq $0x928, %rsp            # imm = 0x928
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xa000
movq %rax, %rbx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x9f34
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x5060
jmp 0x9f34
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
jmp 0x9f56
jmp 0xa000
jmp 0xa000
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa003
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5060
jmp 0xa003
jmp 0xa000
movq %rax, %rbx
jmp 0xa010
movq %rax, %rbx
jmp 0xa031
movq %rax, %rbx
jmp 0xa052
movq %rax, %rbx
movq 0x180(%rsp), %rdi
cmpq %r15, %rdi
je 0xa073
movq 0x190(%rsp), %rsi
incq %rsi
callq 0x5060
jmp 0xa073
movq %rax, %rbx
jmp 0xa073
movq %rax, %rbx
movq 0x308(%rsp), %rdi
cmpq %r13, %rdi
je 0xa094
movq 0x318(%rsp), %rsi
incq %rsi
callq 0x5060
jmp 0xa094
movq %rax, %rbx
jmp 0xa094
movq %rax, %rbx
jmp 0xa0b5
movq %rax, %rbx
jmp 0xa0d1
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x50a0
movq 0x4fb9(%rip), %rsi      # 0xefd0
leaq 0x490(%rsp), %rdi
callq 0x53b0
leaq 0x510(%rsp), %rdi
callq 0x55c0
movq 0x4f98(%rip), %rsi      # 0xefd0
leaq 0x180(%rsp), %rdi
callq 0x53b0
leaq 0x200(%rsp), %rdi
callq 0x55c0
movq 0x4f77(%rip), %rsi      # 0xefd0
leaq 0x308(%rsp), %rdi
callq 0x53b0
leaq 0x388(%rsp), %rdi
callq 0x55c0
movq 0x4f56(%rip), %rsi      # 0xefd0
leaq 0x618(%rsp), %rdi
callq 0x53b0
leaq 0x698(%rsp), %rdi
callq 0x55c0
movq 0x4f35(%rip), %rsi      # 0xefd0
leaq 0x7a0(%rsp), %rdi
callq 0x53b0
leaq 0x820(%rsp), %rdi
callq 0x55c0
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0xa0d1
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x5060
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0xa0f3
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x5060
movq %rbx, %rdi
callq 0x5680