// File: /workspace/github_c_makefile_star2_O2/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, %rbx
movq %rdx, %r14
movq %rsi, %r12
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 0x1afd
movq %r12, (%rsp)
movq %r15, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
movq 0xc8(%rsp), %r12
movq 0xc0(%rsp), %rbx
leaq (,%r12,8), %r14
pushq $0x1
popq %r15
movl %r15d, %ecx
cmpq $0x20, %r12
jb 0x1a37
leal 0x1(%rcx), %r15d
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
movq %rcx, %rdx
callq 0x10c0
addq $-0x20, %r12
addq $0x20, %rbx
addq $-0x100, %r14
jmp 0x1a09
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1030
movq (%rsp), %rbx
andq $0x0, (%rbx)
movq 0xd0(%rsp), %rdx
testq %rdx, %rdx
je 0x1a71
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x10a0
addq $0x20, (%rbx)
addq $0x20, %rbp
movq 0x8(%rsp), %r15
leaq (,%r15,8), %r14
pushq $0x1
popq %r12
leaq 0x20(%rsp), %rbx
movl %r12d, %r8d
cmpq $0x20, %r15
jb 0x1ac2
leal 0x1(%r8), %r12d
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r8, %rcx
callq 0x1050
addq $0x20, %r13
addq $0x20, %rbp
movq (%rsp), %rax
addq $0x20, (%rax)
addq $-0x20, %r15
addq $-0x100, %r14
jmp 0x1a87
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x1070
movq (%rsp), %rax
addq %r15, (%rax)
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x1120
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0x1afd
movq $0x20, (%rax)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq