// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/acorn128v2/ref/encrypt.c
// 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
	)
{
    unsigned long long i;
    unsigned char plaintextbyte, ciphertextbyte, ksbyte, mac[16];
    unsigned char state[293];
    unsigned char ca, cb;

    //initialization stage
    acorn128_initialization(k, npub, state);

    //process the associated data
    for (i = 0; i < adlen; i++)
    {
        acorn128_enc_onebyte(state, ad[i], &ciphertextbyte, &ksbyte, 0xff, 0xff);
    }

    for (i = 0; i < 256/8; i++)
    {
        if ( i == 0 ) plaintextbyte = 0x1;
        else plaintextbyte = 0;

        if ( i < 128/8)   ca = 0xff;
        else ca = 0;

        cb = 0xff;

        acorn128_enc_onebyte(state, plaintextbyte, &ciphertextbyte, &ksbyte, ca, cb);
    }


    //process the plaintext
    for (i = 0; i < mlen; i++)
    {
        acorn128_enc_onebyte(state, m[i], &(c[i]), &ksbyte, 0xff, 0 );
    }

    for (i = 0; i < 256/8; i++)
    {
        if (i == 0) plaintextbyte = 0x1;
        else plaintextbyte = 0;

        if ( i < 128/8)   ca = 0xff;
        else ca = 0;

        cb = 0;

        acorn128_enc_onebyte(state, plaintextbyte, &ciphertextbyte, &ksbyte, ca, cb);
    }

    //finalization stage, we assume that the tag length is a multiple of bytes
    acorn128_tag_generation(mlen, adlen, 16, mac, state);

    *clen = mlen + 16;
    memcpy(c+mlen, mac, 16);

    return 0;
}

// Assembly:
subq $0x198, %rsp            # imm = 0x198
movq 0x1b0(%rsp), %rax
movq 0x1a8(%rsp), %rax
movq 0x1a0(%rsp), %rax
movq %rdi, 0x190(%rsp)
movq %rsi, 0x188(%rsp)
movq %rdx, 0x180(%rsp)
movq %rcx, 0x178(%rsp)
movq %r8, 0x170(%rsp)
movq %r9, 0x168(%rsp)
movq 0x1b0(%rsp), %rdi
movq 0x1a8(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x10c0
movq $0x0, 0x160(%rsp)
movq 0x160(%rsp), %rax
cmpq 0x168(%rsp), %rax
jae 0x1c34
leaq 0x10(%rsp), %rdi
movq 0x170(%rsp), %rax
movq 0x160(%rsp), %rsi
leaq 0x15e(%rsp), %rdx
leaq 0x15d(%rsp), %rcx
movl $0xff, %r9d
movzbl (%rax,%rsi), %esi
movl %r9d, %r8d
callq 0x10d0
movq 0x160(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x160(%rsp)
jmp 0x1bd5
movq $0x0, 0x160(%rsp)
cmpq $0x20, 0x160(%rsp)
jae 0x1cd5
cmpq $0x0, 0x160(%rsp)
jne 0x1c64
movb $0x1, 0x15f(%rsp)
jmp 0x1c6c
movb $0x0, 0x15f(%rsp)
cmpq $0x10, 0x160(%rsp)
jae 0x1c7e
movb $-0x1, 0xf(%rsp)
jmp 0x1c83
movb $0x0, 0xf(%rsp)
movb $-0x1, 0xe(%rsp)
leaq 0x10(%rsp), %rdi
movb 0x15f(%rsp), %sil
movb 0xf(%rsp), %al
leaq 0x15e(%rsp), %rdx
leaq 0x15d(%rsp), %rcx
movzbl %sil, %esi
movzbl %al, %r8d
movzbl 0xe(%rsp), %r9d
callq 0x10d0
movq 0x160(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x160(%rsp)
jmp 0x1c40
movq $0x0, 0x160(%rsp)
movq 0x160(%rsp), %rax
cmpq 0x178(%rsp), %rax
jae 0x1d4a
leaq 0x10(%rsp), %rdi
movq 0x180(%rsp), %rax
movq 0x160(%rsp), %rcx
movb (%rax,%rcx), %al
movq 0x190(%rsp), %rdx
addq 0x160(%rsp), %rdx
leaq 0x15d(%rsp), %rcx
movl $0xff, %r8d
xorl %r9d, %r9d
movzbl %al, %esi
callq 0x10d0
movq 0x160(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x160(%rsp)
jmp 0x1ce1
movq $0x0, 0x160(%rsp)
cmpq $0x20, 0x160(%rsp)
jae 0x1deb
cmpq $0x0, 0x160(%rsp)
jne 0x1d7a
movb $0x1, 0x15f(%rsp)
jmp 0x1d82
movb $0x0, 0x15f(%rsp)
cmpq $0x10, 0x160(%rsp)
jae 0x1d94
movb $-0x1, 0xf(%rsp)
jmp 0x1d99
movb $0x0, 0xf(%rsp)
movb $0x0, 0xe(%rsp)
leaq 0x10(%rsp), %rdi
movb 0x15f(%rsp), %sil
movb 0xf(%rsp), %al
leaq 0x15e(%rsp), %rdx
leaq 0x15d(%rsp), %rcx
movzbl %sil, %esi
movzbl %al, %r8d
movzbl 0xe(%rsp), %r9d
callq 0x10d0
movq 0x160(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x160(%rsp)
jmp 0x1d56
movq 0x178(%rsp), %rdi
movq 0x168(%rsp), %rsi
leaq 0x140(%rsp), %rcx
leaq 0x10(%rsp), %r8
movl $0x10, %edx
callq 0x1090
movq 0x178(%rsp), %rcx
addq $0x10, %rcx
movq 0x188(%rsp), %rax
movq %rcx, (%rax)
movq 0x190(%rsp), %rax
movq 0x178(%rsp), %rcx
movq 0x140(%rsp), %rdx
movq %rdx, (%rax,%rcx)
movq 0x148(%rsp), %rdx
movq %rdx, 0x8(%rax,%rcx)
xorl %eax, %eax
addq $0x198, %rsp            # imm = 0x198
retq
nopl (%rax)