// File: /workspace/github_c_makefile_star2_O3/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, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq $0x0, 0x280(%rdi)
vmovdqa 0x220(%rdi), %xmm1
vxorps %xmm0, %xmm0, %xmm0
vmovaps %xmm0, 0x270(%rdi)
cmpq $0x10, %rdx
vmovdqa %xmm1, 0x10(%rsp)
jbe 0x19cd
vmovq %xmm1, %r13
vpextrq $0x1, %xmm1, %rbp
xorl %r12d, %r12d
testq %r12, %r12
je 0x197c
bswapq %r13
bswapq %rbp
movq %r13, %rax
shrq %rax
shldq $0x3f, %rbp, %r13
movq %rax, %rcx
movabsq $-0x1f00000000000000, %rdx # imm = 0xE100000000000000
xorq %rdx, %rcx
testb $0x1, %bpl
cmoveq %rax, %rcx
bswapq %rcx
bswapq %r13
vmovq %r13, %xmm0
vmovq %rcx, %xmm1
vpunpcklqdq %xmm0, %xmm1, %xmm0 # xmm0 = xmm1[0],xmm0[0]
movq %r13, %rbp
movq %rcx, %r13
jmp 0x1982
vmovdqa 0x10(%rsp), %xmm0
vmovdqa %xmm0, 0x10(%rsp)
vpxor (%r15,%r12), %xmm0, %xmm0
vmovdqa %xmm0, (%rsp)
movq %rsp, %rdi
leaq 0x30(%rsp), %rsi
movq %rbx, %rdx
callq 0x1120
vmovups 0x270(%rbx), %xmm0
vxorps 0x30(%rsp), %xmm0, %xmm0
vmovups %xmm0, 0x270(%rbx)
addq $0x10, %r12
addq $-0x10, %r14
cmpq $0x10, %r14
ja 0x1932
jmp 0x19d6
vpextrq $0x1, %xmm1, %rbp
xorl %r12d, %r12d
leaq 0x270(%rbx), %rax
movq %rax, 0x28(%rsp)
vmovdqa 0x10(%rsp), %xmm0
vmovq %xmm0, %rdi
bswapq %rdi
bswapq %rbp
movq %rdi, %rax
shrq %rax
shldq $0x3f, %rbp, %rdi
movq %rax, %r13
movabsq $-0x1f00000000000000, %rsi # imm = 0xE100000000000000
xorq %rsi, %r13
testb $0x1, %bpl
cmoveq %rax, %r13
cmpq $0x10, %r14
jne 0x1a37
vmovdqu (%r15,%r12), %xmm0
vmovdqa %xmm0, (%rsp)
movq %r13, %rax
shldq $0x3f, %rdi, %rax
movq %rdi, %rcx
movq %r13, %rdx
jmp 0x1a85
vpxor %xmm0, %xmm0, %xmm0
movq %rdi, %rbp
movq %rsp, %rdi
vmovdqa %xmm0, (%rdi)
addq %r12, %r15
movq %rsi, %r12
movq %r15, %rsi
movq %r14, %rdx
callq 0x1140
movq %rbp, %rdi
movb $-0x80, (%rsp,%r14)
movq %r13, %rax
shrq %rax
movq %r13, %rcx
shldq $0x3f, %rbp, %rcx
movq %rax, %rdx
xorq %r12, %rdx
testb $0x1, %dil
cmoveq %rax, %rdx
movq %rdx, %rax
shldq $0x3f, %rcx, %rax
movq %r12, %rsi
shrq %rdx
xorq %rdx, %rsi
testb $0x1, %cl
cmoveq %rdx, %rsi
xorq %r13, %rsi
xorq %rdi, %rax
bswapq %rsi
bswapq %rax
vmovq %rax, %xmm0
vmovq %rsi, %xmm1
vpunpcklqdq %xmm0, %xmm1, %xmm0 # xmm0 = xmm1[0],xmm0[0]
movq %rsp, %rdi
vpxor (%rdi), %xmm0, %xmm0
vmovdqa %xmm0, (%rdi)
vpxor 0x270(%rbx), %xmm0, %xmm0
vmovdqa %xmm0, (%rdi)
movq 0x28(%rsp), %r14
movq %r14, %rsi
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