// File: /workspace/github_c_makefile_star2_O3/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 0x5720
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 0x9aa2
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 0x9afb
movq 0x190(%rsp), %rsi
incq %rsi
callq 0x5060
leaq 0x180(%rsp), %rdi
callq 0x5720
leaq 0x490(%rsp), %rdi
callq 0x5720
leaq 0xb8(%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 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 0x9bf6
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x5060
leaq 0x20(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x9c11
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 0x9c42
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 0x9cb3
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 0x9ce4
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x5060
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x9cfb
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 0x9d2c
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5060
movq 0x150(%rsp), %rdi
testq %rdi, %rdi
je 0x9d49
movq 0x160(%rsp), %rsi
subq %rdi, %rsi
callq 0x5060
leaq 0x120(%rsp), %r14
movq %r14, %rdi
callq 0x55d0
movq 0x5240(%rip), %rax      # 0xefa0
addq $0x10, %rax
movq %rax, -0x68(%r14)
movq -0x30(%r14), %rdi
testq %rdi, %rdi
je 0x9d81
movq 0x100(%rsp), %rsi
subq %rdi, %rsi
callq 0x5060
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0x9d9e
movq 0xe8(%rsp), %rsi
subq %rdi, %rsi
callq 0x5060
movq 0x522b(%rip), %r15      # 0xefd0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x53b0
movl $0x80, %r14d
addq %r14, %rbx
movq %rbx, %rdi
callq 0x55b0
movq %rbp, %rdi
movq %r15, %rsi
callq 0x53b0
addq %r14, %rbp
movq %rbp, %rdi
callq 0x55b0
leaq 0x308(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x53b0
addq %r14, %rbx
movq %rbx, %rdi
callq 0x55b0
movq %r13, %rdi
movq %r15, %rsi
callq 0x53b0
addq %r14, %r13
movq %r13, %rdi
callq 0x55b0
movq %r12, %rdi
movq %r15, %rsi
callq 0x53b0
addq %r14, %r12
movq %r12, %rdi
callq 0x55b0
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x9e3d
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x5060
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x9e5f
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 0x9f68
movq %rax, %rbx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x9e9c
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x5060
jmp 0x9e9c
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
jmp 0x9ebe
jmp 0x9f68
jmp 0x9f68
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9f6b
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5060
jmp 0x9f6b
jmp 0x9f68
movq %rax, %rbx
jmp 0x9f78
movq %rax, %rbx
jmp 0x9f99
movq %rax, %rbx
jmp 0x9fba
movq %rax, %rbx
movq 0x180(%rsp), %rdi
cmpq %r15, %rdi
je 0x9fdb
movq 0x190(%rsp), %rsi
incq %rsi
callq 0x5060
jmp 0x9fdb
movq %rax, %rbx
jmp 0x9fdb
movq %rax, %rbx
movq 0x308(%rsp), %rdi
cmpq %r13, %rdi
je 0x9ffc
movq 0x318(%rsp), %rsi
incq %rsi
callq 0x5060
jmp 0x9ffc
movq %rax, %rbx
jmp 0x9ffc
movq %rax, %rbx
jmp 0xa01d
movq %rax, %rbx
jmp 0xa039
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x50a0
movq 0x5051(%rip), %rsi      # 0xefd0
leaq 0x490(%rsp), %rdi
callq 0x53b0
leaq 0x510(%rsp), %rdi
callq 0x55b0
movq 0x5030(%rip), %rsi      # 0xefd0
leaq 0x180(%rsp), %rdi
callq 0x53b0
leaq 0x200(%rsp), %rdi
callq 0x55b0
movq 0x500f(%rip), %rsi      # 0xefd0
leaq 0x308(%rsp), %rdi
callq 0x53b0
leaq 0x388(%rsp), %rdi
callq 0x55b0
movq 0x4fee(%rip), %rsi      # 0xefd0
leaq 0x618(%rsp), %rdi
callq 0x53b0
leaq 0x698(%rsp), %rdi
callq 0x55b0
movq 0x4fcd(%rip), %rsi      # 0xefd0
leaq 0x7a0(%rsp), %rdi
callq 0x53b0
leaq 0x820(%rsp), %rdi
callq 0x55b0
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0xa039
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x5060
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0xa05b
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x5060
movq %rbx, %rdi
callq 0x5670