// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xa8, %rsp
movq 0xe0(%rsp), %rax
movq 0xd8(%rsp), %rax
movq 0xd0(%rsp), %rax
movq 0xc8(%rsp), %rax
movq 0xc0(%rsp), %rax
movq 0xb8(%rsp), %rax
movq 0xb0(%rsp), %rax
movq %rdi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
movq %rdx, 0x90(%rsp)
movq %rcx, 0x88(%rsp)
movq %r8, 0x80(%rsp)
movq %r9, 0x78(%rsp)
movq 0xd8(%rsp), %rsi
movq 0xe0(%rsp), %rdx
shlq $0x3, %rdx
movq 0xc8(%rsp), %rcx
movq 0xd0(%rsp), %r8
shlq $0x3, %r8
leaq 0x8(%rsp), %rdi
callq 0x1110
cmpl $0x0, %eax
je 0x2208
jmp 0x23d4
movl $0x1, 0x74(%rsp)
cmpq $0x20, 0xb8(%rsp)
jb 0x2268
movq 0xb0(%rsp), %rsi
movl 0x74(%rsp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x74(%rsp)
movl %eax, %eax
movl %eax, %edx
leaq 0x8(%rsp), %rdi
callq 0x10d0
movq 0xb8(%rsp), %rax
subq $0x20, %rax
movq %rax, 0xb8(%rsp)
movq 0xb0(%rsp), %rax
addq $0x20, %rax
movq %rax, 0xb0(%rsp)
jmp 0x2210
movq 0xb0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
shlq $0x3, %rdx
movl 0x74(%rsp), %eax
movl %eax, %ecx
leaq 0x8(%rsp), %rdi
callq 0x1040
movq 0x98(%rsp), %rax
movq $0x0, (%rax)
cmpq $0x0, 0xc0(%rsp)
je 0x22e6
movq 0xa0(%rsp), %rsi
movq 0xc0(%rsp), %rdx
leaq 0x8(%rsp), %rdi
callq 0x10b0
movq 0x98(%rsp), %rax
movq (%rax), %rcx
addq $0x20, %rcx
movq %rcx, (%rax)
movq 0xa0(%rsp), %rax
addq $0x20, %rax
movq %rax, 0xa0(%rsp)
movl $0x1, 0x74(%rsp)
cmpq $0x20, 0x78(%rsp)
jb 0x236b
movq 0xa0(%rsp), %rsi
movq 0x80(%rsp), %rdx
movl 0x74(%rsp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x74(%rsp)
movl %eax, %eax
movl %eax, %ecx
leaq 0x8(%rsp), %rdi
callq 0x1060
movq 0x80(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x80(%rsp)
movq 0xa0(%rsp), %rax
addq $0x20, %rax
movq %rax, 0xa0(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %rcx
addq $0x20, %rcx
movq %rcx, (%rax)
movq 0x78(%rsp), %rax
subq $0x20, %rax
movq %rax, 0x78(%rsp)
jmp 0x22ee
movq 0xa0(%rsp), %rsi
movq 0x80(%rsp), %rdx
movq 0x78(%rsp), %rcx
shlq $0x3, %rcx
movl 0x74(%rsp), %eax
movl %eax, %r8d
leaq 0x8(%rsp), %rdi
callq 0x1080
movq 0x78(%rsp), %rcx
movq 0x98(%rsp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq 0x90(%rsp), %rsi
leaq 0x8(%rsp), %rdi
callq 0x1130
cmpq $0x0, 0x88(%rsp)
je 0x23d4
movq 0x88(%rsp), %rax
movq $0x20, (%rax)
addq $0xa8, %rsp
retq
nopl (%rax)