// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/aes128poetv2aes4/ref/poet.c
// Function: process_header
void process_header(poet_ctx_t *ctx,
                    const unsigned char *header,
                    unsigned long long header_len)
{
    block mask;
    block in;
    block out;
    uint64_t offset = 0;

    ctx->mlen = 0;
    memset(ctx->tau, 0, BLOCKLEN);
    memcpy(mask, ctx->l, BLOCKLEN);

    // Process parameters
    encode_parameters(in, NUM_BLOCKS_PER_PART, INTERMEDIATE_TAGLEN);

    xor_block(in, in, mask);

    aes_encrypt(in, out, &(ctx->aes_enc));
    xor_block(ctx->tau, out, ctx->tau);
    gf128_double(mask);

    while (header_len >= BLOCKLEN) {
        xor_block(in, header + offset, mask);
        aes_encrypt(in, out, &(ctx->aes_enc));
        xor_block(ctx->tau, out, ctx->tau);

        offset += BLOCKLEN;
        header_len -= BLOCKLEN;

        gf128_double(mask);
    }

    //  Final block 
    memset(in, 0, BLOCKLEN);
    memcpy(in, header + offset, header_len);
    in[header_len] = 0x80;
    xor_block(in, mask, in);
    aes_encrypt(in, out, &(ctx->aes_enc));
    
    xor_block(ctx->tau, out, ctx->tau);
    aes_encrypt(ctx->tau, ctx->tau, &(ctx->aes_enc));

    memcpy(ctx->x, ctx->tau, BLOCKLEN);
    memcpy(ctx->y, ctx->tau, BLOCKLEN);
    ctx->y[BLOCKLEN - 1] ^= 1;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq $0x0, 0x8(%rsp)
movq 0x50(%rsp), %rax
movq $0x0, 0x340(%rax)
movq 0x50(%rsp), %rdi
addq $0x32c, %rdi            # imm = 0x32C
xorl %esi, %esi
movl $0x10, %edx
callq 0x1030
movq 0x50(%rsp), %rax
movq 0x2ec(%rax), %rcx
movq %rcx, 0x30(%rsp)
movq 0x2f4(%rax), %rax
movq %rax, 0x38(%rsp)
leaq 0x20(%rsp), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x64f0
leaq 0x20(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x6590
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq 0x50(%rsp), %rdx
callq 0x1110
movq 0x50(%rsp), %rdi
addq $0x32c, %rdi            # imm = 0x32C
leaq 0x10(%rsp), %rsi
movq 0x50(%rsp), %rdx
addq $0x32c, %rdx            # imm = 0x32C
callq 0x6590
leaq 0x30(%rsp), %rdi
callq 0x65f0
cmpq $0x10, 0x40(%rsp)
jb 0x63e5
leaq 0x20(%rsp), %rdi
movq 0x48(%rsp), %rsi
addq 0x8(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x6590
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq 0x50(%rsp), %rdx
callq 0x1110
movq 0x50(%rsp), %rdi
addq $0x32c, %rdi            # imm = 0x32C
leaq 0x10(%rsp), %rsi
movq 0x50(%rsp), %rdx
addq $0x32c, %rdx            # imm = 0x32C
callq 0x6590
movq 0x8(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x8(%rsp)
movq 0x40(%rsp), %rax
subq $0x10, %rax
movq %rax, 0x40(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x65f0
jmp 0x6366
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1030
leaq 0x20(%rsp), %rdi
movq 0x48(%rsp), %rsi
addq 0x8(%rsp), %rsi
movq 0x40(%rsp), %rdx
callq 0x1120
movq 0x40(%rsp), %rax
movb $-0x80, 0x20(%rsp,%rax)
leaq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x6590
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq 0x50(%rsp), %rdx
callq 0x1110
movq 0x50(%rsp), %rdi
addq $0x32c, %rdi            # imm = 0x32C
leaq 0x10(%rsp), %rsi
movq 0x50(%rsp), %rdx
addq $0x32c, %rdx            # imm = 0x32C
callq 0x6590
movq 0x50(%rsp), %rdi
addq $0x32c, %rdi            # imm = 0x32C
movq 0x50(%rsp), %rsi
addq $0x32c, %rsi            # imm = 0x32C
movq 0x50(%rsp), %rdx
callq 0x1110
movq 0x50(%rsp), %rax
movq 0x50(%rsp), %rcx
movq 0x32c(%rcx), %rdx
movq %rdx, 0x30c(%rax)
movq 0x334(%rcx), %rcx
movq %rcx, 0x314(%rax)
movq 0x50(%rsp), %rax
movq 0x50(%rsp), %rcx
movq 0x32c(%rcx), %rdx
movq %rdx, 0x31c(%rax)
movq 0x334(%rcx), %rcx
movq %rcx, 0x324(%rax)
movq 0x50(%rsp), %rax
movzbl 0x32b(%rax), %ecx
xorl $0x1, %ecx
movb %cl, 0x32b(%rax)
addq $0x58, %rsp
retq
nopl (%rax,%rax)