// File: /workspace/github_c_makefile_star2_O1/mjosaarinen[P]brutus/crypto_aead/pi32cipher256v2/ref2/pi-cipher.c
// Function: pi32_encrypt_simple
void PI_ENCRYPT_SIMPLE(
        void *cipher,
        size_t *cipher_len_B,
        void *tag,
        size_t *tag_length_B,
        const void *msg,
        size_t msg_len_B,
        const void *ad,
        size_t ad_len_B,
        const void *nonce_secret,
        const void *nonce_public,
        size_t nonce_public_len_B,
        const void *key,
        size_t key_len_B
        )
{
    unsigned i;
    PI_CTX ctx;
    if (PI_INIT(&ctx, key, key_len_B * 8, nonce_public, nonce_public_len_B * 8)) {
        printf("ERROR! <%s %s %d>\n", __FILE__, __func__, __LINE__);
        return;
    }
    i = 1;
    while (ad_len_B >= PI_AD_BLOCK_LENGTH_BYTES) {
        PI_PROCESS_AD_BLOCK(&ctx, ad, i++);
        ad_len_B -= PI_AD_BLOCK_LENGTH_BYTES;
        ad = &((const uint8_t*)ad)[PI_AD_BLOCK_LENGTH_BYTES];
    }
    PI_PROCESS_AD_LAST_BLOCK(&ctx, ad, ad_len_B * 8, i);
    *cipher_len_B = 0;
    if (nonce_secret) {
        PI_PROCESS_SMN(&ctx, cipher, nonce_secret);
        *cipher_len_B += PI_CT_BLOCK_LENGTH_BYTES;
        cipher = &((uint8_t*)cipher)[PI_CT_BLOCK_LENGTH_BYTES];
    }
    i = 1;
    while (msg_len_B >= PI_PT_BLOCK_LENGTH_BYTES) {
        PI_ENCRYPT_BLOCK(&ctx, cipher, msg, i++);
        msg = &((const uint8_t*)msg)[PI_PT_BLOCK_LENGTH_BYTES];
        cipher = &((uint8_t*)cipher)[PI_CT_BLOCK_LENGTH_BYTES];
        *cipher_len_B += PI_CT_BLOCK_LENGTH_BYTES;
        msg_len_B -= PI_PT_BLOCK_LENGTH_BYTES;
    }
    PI_ENCRYPT_LAST_BLOCK(&ctx, cipher, msg, msg_len_B * 8, i);
    *cipher_len_B += msg_len_B;
    PI_EXTRACT_TAG(&ctx, tag);
    if (tag_length_B) {
    	*tag_length_B = PI_TAG_BYTES;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, %r15
movq %r8, %r13
movq %rcx, %r12
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %rbp
movq 0xe8(%rsp), %rsi
movq 0xd8(%rsp), %rcx
movq 0xe0(%rsp), %r8
movq 0xf0(%rsp), %rdx
shlq $0x3, %rdx
shlq $0x3, %r8
leaq 0x20(%rsp), %rdi
callq 0x1100
testl %eax, %eax
jne 0x1cef
movq %r14, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
movq 0xc8(%rsp), %rbx
movq 0xc0(%rsp), %r14
movl $0x1, %ecx
cmpq $0x20, %rbx
movq %r12, 0x8(%rsp)
jb 0x1be8
movl $0x1, %r12d
movl %r12d, %edx
incl %r12d
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x10c0
addq $-0x20, %rbx
addq $0x20, %r14
cmpq $0x1f, %rbx
ja 0x1bbf
movl %r12d, %ecx
movq 0x8(%rsp), %r12
shlq $0x3, %rbx
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1030
movq 0x10(%rsp), %r14
movq $0x0, (%r14)
movq 0xd0(%rsp), %rdx
testq %rdx, %rdx
je 0x1c2a
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x10a0
addq $0x20, (%r14)
addq $0x20, %rbp
movl $0x1, %r8d
cmpq $0x20, %r15
jb 0x1c7a
movq %r14, %r12
movl $0x1, %r14d
leaq 0x20(%rsp), %rbx
movl %r14d, %ecx
incl %r14d
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x1050
addq $0x20, %r13
addq $0x20, %rbp
addq $0x20, (%r12)
addq $-0x20, %r15
cmpq $0x1f, %r15
ja 0x1c44
movl %r14d, %r8d
movq %r12, %r14
movq 0x8(%rsp), %r12
leaq (,%r15,8), %rcx
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x1070
addq %r15, (%r14)
vmovdqu 0x40(%rbx), %ymm0
vpsrld $0x8, %ymm0, %ymm1
vpsrld $0x10, %ymm0, %ymm2
vpsrld $0x18, %ymm0, %ymm3
vpmovdb %ymm0, %xmm0
vpmovdb %ymm1, %xmm1
vpunpcklbw %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3],xmm0[4],xmm1[4],xmm0[5],xmm1[5],xmm0[6],xmm1[6],xmm0[7],xmm1[7]
vpmovdb %ymm3, %xmm1
vpmovdb %ymm2, %xmm2
vpunpcklbw %xmm1, %xmm2, %xmm1 # xmm1 = xmm2[0],xmm1[0],xmm2[1],xmm1[1],xmm2[2],xmm1[2],xmm2[3],xmm1[3],xmm2[4],xmm1[4],xmm2[5],xmm1[5],xmm2[6],xmm1[6],xmm2[7],xmm1[7]
vpunpcklwd %xmm1, %xmm0, %xmm2 # xmm2 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
vpunpckhwd %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[4],xmm1[4],xmm0[5],xmm1[5],xmm0[6],xmm1[6],xmm0[7],xmm1[7]
movq 0x18(%rsp), %rax
vmovdqu %xmm0, 0x10(%rax)
vmovdqu %xmm2, (%rax)
testq %r12, %r12
je 0x1cef
movq $0x20, (%r12)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq