// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/aes128poetv1aes4/ni/poet.c
// Function: process_header
void process_header(struct poet_ctx *ctx, const uint8_t  *header, uint64_t header_len )
{
  uint64_t h[2];
  unsigned char *mask = (unsigned char *) h;
  block in;
  block out;
  uint64_t offset=0;

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


  while(header_len > BLOCKLEN)
    {

      if(offset)
	{
	  h[0] = TO_BIG_ENDIAN_64(h[0]);  h[1] = TO_BIG_ENDIAN_64(h[1]);
	  GF128_double(h);
	  h[0] = TO_BIG_ENDIAN_64(h[0]); h[1] = TO_BIG_ENDIAN_64(h[1]);
	}
      xor_block(in,header+offset,mask);

      AESNI_encrypt(in,out,ctx->aes_enc);
      xor_block(ctx->tau,out,ctx->tau);

      offset += BLOCKLEN;
      header_len -= BLOCKLEN;
    }

  h[0] = TO_BIG_ENDIAN_64(h[0]);  h[1] = TO_BIG_ENDIAN_64(h[1]);
  GF128_double(h);
  h[0] = TO_BIG_ENDIAN_64(h[0]);  h[1] = TO_BIG_ENDIAN_64(h[1]);

  /* LASTBLOCK */
   if(header_len < 16)
    {
      memset(in,0,BLOCKLEN);
      memcpy(in,header+offset,header_len);
      in[header_len]=0x80;

      h[0] = TO_BIG_ENDIAN_64(h[0]); h[1] = TO_BIG_ENDIAN_64(h[1]);
      GF128_quintuple(h);
      h[0] = TO_BIG_ENDIAN_64(h[0]); h[1] = TO_BIG_ENDIAN_64(h[1]);

    }
   else
     {
       memcpy(in,header+offset,BLOCKLEN);
       h[0] = TO_BIG_ENDIAN_64(h[0]); h[1] = TO_BIG_ENDIAN_64(h[1]);
       GF128_triple(h);
       h[0] = TO_BIG_ENDIAN_64(h[0]); h[1] = TO_BIG_ENDIAN_64(h[1]);
     }

   xor_block(in,mask,in);

   xor_block(in,in,ctx->tau);
   AESNI_encrypt(in ,ctx->tau, ctx->aes_enc);
   memcpy(ctx->x, ctx->tau, BLOCKLEN);
   memcpy(ctx->y, ctx->tau, BLOCKLEN);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r15
movq %rsi, %r12
andq $0x0, 0x280(%rdi)
vmovaps 0x220(%rdi), %xmm0
movq %rsp, %rax
vmovaps %xmm0, (%rax)
leaq 0x270(%rdi), %r14
vxorps %xmm0, %xmm0, %xmm0
movq %rdi, 0x18(%rsp)
vmovaps %xmm0, 0x270(%rdi)
xorl %ebx, %ebx
leaq 0x20(%rsp), %rbp
leaq 0x30(%rsp), %r13
cmpq $0x11, %r15
jb 0x19ab
testq %rbx, %rbx
je 0x1974
movbeq (%rsp), %rax
movbeq 0x8(%rsp), %rcx
movq %rax, %rdx
shrq %rdx
shldq $0x3f, %rcx, %rax
movq %rdx, %rsi
movabsq $-0x1f00000000000000, %rdi # imm = 0xE100000000000000
xorq %rdi, %rsi
testb $0x1, %cl
cmoveq %rdx, %rsi
movbeq %rsi, (%rsp)
movbeq %rax, 0x8(%rsp)
leaq (%r12,%rbx), %rsi
movq %rbp, %rdi
movq %rsp, %rdx
callq 0x1140
movq %rbp, %rdi
movq %r13, %rsi
movq 0x18(%rsp), %rdx
callq 0x1120
movq %r14, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x1140
addq $0x10, %rbx
addq $-0x10, %r15
jmp 0x192d
movbeq (%rsp), %r13
movbeq 0x8(%rsp), %rax
movq %r13, %rcx
shrq %rcx
shldq $0x3f, %rax, %r13
movq %rcx, %rbp
movabsq $-0x1f00000000000000, %rdi # imm = 0xE100000000000000
xorq %rdi, %rbp
testb $0x1, %al
cmoveq %rcx, %rbp
cmpq $0x10, %r15
jne 0x19fb
vmovups (%r12,%rbx), %xmm0
vmovaps %xmm0, 0x20(%rsp)
movq %rbp, %rax
shldq $0x3f, %r13, %rax
movq %r13, %rcx
movq %rbp, %rdx
jmp 0x1a4f
vxorps %xmm0, %xmm0, %xmm0
leaq 0x20(%rsp), %rdi
vmovaps %xmm0, (%rdi)
addq %rbx, %r12
movq %r12, %rsi
movq %r15, %rdx
callq 0x1150
movb $-0x80, 0x20(%rsp,%r15)
movq %rbp, %rax
shrq %rax
movq %rbp, %rcx
shldq $0x3f, %r13, %rcx
movq %rcx, 0x8(%rsp)
movq %rax, %rdx
movabsq $-0x1f00000000000000, %rdi # imm = 0xE100000000000000
xorq %rdi, %rdx
testb $0x1, %r13b
cmoveq %rax, %rdx
movq %rdx, %rax
shldq $0x3f, %rcx, %rax
shrq %rdx
xorq %rdx, %rdi
testb $0x1, %cl
cmoveq %rdx, %rdi
xorq %rbp, %rdi
xorq %r13, %rax
movq %rsp, %rsi
movbeq %rdi, (%rsi)
movbeq %rax, 0x8(%rsi)
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r15, %rdx
callq 0x1140
movq %r15, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1140
movq %r15, %rdi
movq %r14, %rsi
movq 0x18(%rsp), %rbx
movq %rbx, %rdx
callq 0x1120
vmovaps (%r14), %xmm0
vmovaps %xmm0, 0x250(%rbx)
vmovaps (%r14), %xmm0
vmovaps %xmm0, 0x260(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq