// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/pi32cipher256v2/ref3/pi-cipher.c
// Function: pi32_encrypt_simple
void PI_ENCRYPT_SIMPLE(
        void *cipher,
        size_t *cipher_len_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, nonce_public, nonce_public_len_B)) {
        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, i);
    *cipher_len_B = 0;
    if (nonce_secret) {
        PI_ENCRYPT_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, i);
    *cipher_len_B += msg_len_B;
    cipher = &((uint8_t*)cipher)[msg_len_B];
    PI_EXTRACT_TAG(&ctx, cipher);
    *cipher_len_B += PI_TAG_BYTES;
}

// Assembly:
subq $0xa8, %rsp
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 0xc8(%rsp), %rsi
movq 0xd0(%rsp), %rdx
movq 0xb8(%rsp), %rcx
movq 0xc0(%rsp), %r8
leaq 0x8(%rsp), %rdi
callq 0x1110
cmpl $0x0, %eax
je 0x2000
jmp 0x21da
movl $0x1, 0x74(%rsp)
cmpq $0x20, 0x78(%rsp)
jb 0x2057
movq 0x80(%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 0x78(%rsp), %rax
subq $0x20, %rax
movq %rax, 0x78(%rsp)
movq 0x80(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x80(%rsp)
jmp 0x2008
movq 0x80(%rsp), %rsi
movq 0x78(%rsp), %rdx
movl 0x74(%rsp), %eax
movl %eax, %ecx
leaq 0x8(%rsp), %rdi
callq 0x1040
movq 0x98(%rsp), %rax
movq $0x0, (%rax)
cmpq $0x0, 0xb0(%rsp)
je 0x20ce
movq 0xa0(%rsp), %rsi
movq 0xb0(%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, 0x88(%rsp)
jb 0x215f
movq 0xa0(%rsp), %rsi
movq 0x90(%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 0x90(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x90(%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 0x88(%rsp), %rax
subq $0x20, %rax
movq %rax, 0x88(%rsp)
jmp 0x20d6
movq 0xa0(%rsp), %rsi
movq 0x90(%rsp), %rdx
movq 0x88(%rsp), %rcx
movl 0x74(%rsp), %eax
movl %eax, %r8d
leaq 0x8(%rsp), %rdi
callq 0x1080
movq 0x88(%rsp), %rcx
movq 0x98(%rsp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq 0xa0(%rsp), %rax
addq 0x88(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0xa0(%rsp), %rsi
leaq 0x8(%rsp), %rdi
callq 0x1130
movq 0x98(%rsp), %rax
movq (%rax), %rcx
addq $0x20, %rcx
movq %rcx, (%rax)
addq $0xa8, %rsp
retq
nopw %cs:(%rax,%rax)