// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/aes128poetv2aes128ni/ref/poet.c
// Function: process_header
void process_header(poet_ctx_t *ctx,
                    const unsigned char *header,
                    unsigned long long header_len)
{
    __m128i l = ctx->l;
    __m128i sum = encode_parameters(NUM_BLOCKS_PER_PART, INTERMEDIATE_TAGLEN);
    sum = aes_encrypt(vxor(sum, l), ctx->aes_enc);
    l = double_block(l);

    while (header_len >= 8 * BLOCKLEN) {
        sum = vxor(sum, aes_encrypt(vxor(load(header     ), l), ctx->aes_enc));
        l = double_block(l);
        sum = vxor(sum, aes_encrypt(vxor(load(header + 16), l), ctx->aes_enc));
        l = double_block(l);
        sum = vxor(sum, aes_encrypt(vxor(load(header + 32), l), ctx->aes_enc));
        l = double_block(l);
        sum = vxor(sum, aes_encrypt(vxor(load(header + 48), l), ctx->aes_enc));
        l = double_block(l);
        sum = vxor(sum, aes_encrypt(vxor(load(header + 64), l), ctx->aes_enc));
        l = double_block(l);
        sum = vxor(sum, aes_encrypt(vxor(load(header + 80), l), ctx->aes_enc));
        l = double_block(l);
        sum = vxor(sum, aes_encrypt(vxor(load(header + 96), l), ctx->aes_enc));
        l = double_block(l);
        sum = vxor(sum, aes_encrypt(vxor(load(header + 112), l), ctx->aes_enc));
        l = double_block(l);
        header_len -= 8 * BLOCKLEN;
        header += 8 * BLOCKLEN;
    }

    if (header_len >= 4 * BLOCKLEN) {
        sum = vxor(sum, aes_encrypt(vxor(load(header     ), l), ctx->aes_enc));
        l = double_block(l);
        sum = vxor(sum, aes_encrypt(vxor(load(header + 16), l), ctx->aes_enc));
        l = double_block(l);
        sum = vxor(sum, aes_encrypt(vxor(load(header + 32), l), ctx->aes_enc));
        l = double_block(l);
        sum = vxor(sum, aes_encrypt(vxor(load(header + 48), l), ctx->aes_enc));
        l = double_block(l);
        header_len -= 4 * BLOCKLEN;
        header += 4 * BLOCKLEN;
    }

    if (header_len >= 2 * BLOCKLEN) {
        sum = vxor(sum, aes_encrypt(vxor(load(header     ), l), ctx->aes_enc));
        l = double_block(l);
        sum = vxor(sum, aes_encrypt(vxor(load(header + 16), l), ctx->aes_enc));
        l = double_block(l);
        header_len -= 2 * BLOCKLEN;
        header += 2 * BLOCKLEN;
    }

    if (header_len >= BLOCKLEN) {
        sum = vxor(aes_encrypt(vxor(load(header), l), ctx->aes_enc), sum);
        l = double_block(l);
        header_len -= BLOCKLEN;
        header += BLOCKLEN;
    }

    __m128i tmp = one_zero_pad(
        load_n_bytes(header, header_len), BLOCKLEN - header_len
    );
    sum = vxor(aes_encrypt(vxor(l, tmp), ctx->aes_enc), sum);

    ctx->tau = aes_encrypt(sum, ctx->aes_enc);
    ctx->x = ctx->tau;
    ctx->y = vxor(ctx->tau, one);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x90, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
vmovaps 0x210(%rdi), %xmm0
vmovaps %xmm0, (%rsp)
callq 0x1724
vmovaps %xmm0, 0x10(%rsp)
vmovdqa (%rsp), %xmm0
callq 0x176e
addq $0x40, %r15
cmpq $0x80, %r14
vmovdqa %xmm0, (%rsp)
jb 0x1558
vpxor -0x40(%r15), %xmm0, %xmm0
movq %rbx, %rdi
callq 0x1724
vmovdqa %xmm0, 0x40(%rsp)
vmovaps (%rsp), %xmm0
callq 0x176e
vmovaps %xmm0, 0x30(%rsp)
vxorps -0x30(%r15), %xmm0, %xmm0
movq %rbx, %rdi
callq 0x1724
vmovaps %xmm0, (%rsp)
vmovaps 0x30(%rsp), %xmm0
callq 0x176e
vmovaps %xmm0, 0x20(%rsp)
vxorps -0x20(%r15), %xmm0, %xmm0
movq %rbx, %rdi
callq 0x1724
vmovaps %xmm0, 0x30(%rsp)
vmovaps 0x20(%rsp), %xmm0
callq 0x176e
vmovaps %xmm0, 0x80(%rsp)
vxorps -0x10(%r15), %xmm0, %xmm0
movq %rbx, %rdi
callq 0x1724
vmovaps %xmm0, 0x20(%rsp)
vmovaps 0x80(%rsp), %xmm0
callq 0x176e
vmovaps %xmm0, 0x70(%rsp)
vxorps (%r15), %xmm0, %xmm0
movq %rbx, %rdi
callq 0x1724
vmovaps %xmm0, 0x80(%rsp)
vmovaps 0x70(%rsp), %xmm0
callq 0x176e
vmovaps %xmm0, 0x60(%rsp)
vxorps 0x10(%r15), %xmm0, %xmm0
movq %rbx, %rdi
callq 0x1724
vmovaps %xmm0, 0x70(%rsp)
vmovaps 0x60(%rsp), %xmm0
callq 0x176e
vmovaps %xmm0, 0x50(%rsp)
vxorps 0x20(%r15), %xmm0, %xmm0
movq %rbx, %rdi
callq 0x1724
vmovaps %xmm0, 0x60(%rsp)
vmovdqa 0x50(%rsp), %xmm0
callq 0x176e
vmovdqa %xmm0, 0x50(%rsp)
vpxor 0x30(%r15), %xmm0, %xmm0
movq %rbx, %rdi
callq 0x1724
vmovdqa (%rsp), %xmm1
vmovdqa 0x30(%rsp), %xmm2
vpternlogq $0x96, 0x40(%rsp), %xmm1, %xmm2
vmovdqa 0x80(%rsp), %xmm1
vpternlogq $0x96, 0x20(%rsp), %xmm1, %xmm2
vmovdqa 0x60(%rsp), %xmm1
vpternlogq $0x96, 0x70(%rsp), %xmm1, %xmm2
vmovdqa 0x10(%rsp), %xmm1
vpternlogq $0x96, %xmm0, %xmm2, %xmm1
vmovdqa %xmm1, 0x10(%rsp)
vmovdqa 0x50(%rsp), %xmm0
callq 0x176e
addq $-0x80, %r14
subq $-0x80, %r15
jmp 0x13cf
cmpq $0x40, %r14
jb 0x1615
vpxor -0x40(%r15), %xmm0, %xmm0
movq %rbx, %rdi
callq 0x1724
vmovdqa %xmm0, 0x40(%rsp)
vmovaps (%rsp), %xmm0
callq 0x176e
vmovaps %xmm0, 0x30(%rsp)
vxorps -0x30(%r15), %xmm0, %xmm0
movq %rbx, %rdi
callq 0x1724
vmovaps %xmm0, (%rsp)
vmovaps 0x30(%rsp), %xmm0
callq 0x176e
vmovaps %xmm0, 0x20(%rsp)
vxorps -0x20(%r15), %xmm0, %xmm0
movq %rbx, %rdi
callq 0x1724
vmovaps %xmm0, 0x30(%rsp)
vmovdqa 0x20(%rsp), %xmm0
callq 0x176e
vmovdqa %xmm0, 0x20(%rsp)
vpxor -0x10(%r15), %xmm0, %xmm0
movq %rbx, %rdi
callq 0x1724
vmovdqa (%rsp), %xmm1
vmovdqa 0x30(%rsp), %xmm2
vpternlogq $0x96, 0x40(%rsp), %xmm1, %xmm2
vmovdqa 0x10(%rsp), %xmm1
vpternlogq $0x96, %xmm0, %xmm2, %xmm1
vmovdqa %xmm1, 0x10(%rsp)
vmovdqa 0x20(%rsp), %xmm0
callq 0x176e
addq $-0x40, %r14
jmp 0x1619
addq $-0x40, %r15
cmpq $0x20, %r14
jb 0x167b
vmovdqa %xmm0, (%rsp)
vpxor (%r15), %xmm0, %xmm0
movq %rbx, %rdi
callq 0x1724
vmovdqa %xmm0, 0x40(%rsp)
vmovdqa (%rsp), %xmm0
callq 0x176e
vmovdqa %xmm0, (%rsp)
vpxor 0x10(%r15), %xmm0, %xmm0
movq %rbx, %rdi
callq 0x1724
vmovdqa 0x10(%rsp), %xmm1
vpternlogq $0x96, 0x40(%rsp), %xmm0, %xmm1
vmovdqa %xmm1, 0x10(%rsp)
vmovdqa (%rsp), %xmm0
callq 0x176e
addq $-0x20, %r14
addq $0x20, %r15
cmpq $0x10, %r14
vmovdqa %xmm0, (%rsp)
jb 0x16ba
vpxor (%r15), %xmm0, %xmm0
movq %rbx, %rdi
callq 0x1724
vmovdqa 0x10(%rsp), %xmm1
vpxor %xmm1, %xmm0, %xmm1
vmovdqa %xmm1, 0x10(%rsp)
vmovdqa (%rsp), %xmm0
callq 0x176e
vmovdqa %xmm0, (%rsp)
addq $-0x10, %r14
addq $0x10, %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x1793
leaq 0x1964(%rip), %rax      # 0x3030
subq %r14, %rax
vpand 0x10(%rax), %xmm0, %xmm0
vmovdqa (%rsp), %xmm1
vpternlogq $0x36, 0x20(%rax), %xmm1, %xmm0
movq %rbx, %rdi
callq 0x1724
vpxor 0x10(%rsp), %xmm0, %xmm0
movq %rbx, %rdi
callq 0x1724
vmovdqa %xmm0, 0x240(%rbx)
vmovdqa %xmm0, 0x220(%rbx)
vpxor 0x18f1(%rip), %xmm0, %xmm0 # 0x3000
vmovdqa %xmm0, 0x230(%rbx)
addq $0x90, %rsp
popq %rbx
popq %r14
popq %r15
retq