// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %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 $0x11, %rdx
vmovdqa %xmm1, (%rsp)
jb 0x19cc
vmovq %xmm1, %r12
vpextrq $0x1, %xmm1, %r13
xorl %ebp, %ebp
testq %rbp, %rbp
je 0x197a
bswapq %r12
bswapq %r13
movq %r12, %rax
shrq %rax
shldq $0x3f, %r13, %r12
movq %rax, %rcx
movabsq $-0x1f00000000000000, %rdx # imm = 0xE100000000000000
xorq %rdx, %rcx
testb $0x1, %r13b
cmoveq %rax, %rcx
bswapq %rcx
bswapq %r12
vmovq %r12, %xmm0
vmovq %rcx, %xmm1
vpunpcklqdq %xmm0, %xmm1, %xmm0 # xmm0 = xmm1[0],xmm0[0]
movq %r12, %r13
movq %rcx, %r12
jmp 0x197f
vmovdqa (%rsp), %xmm0
vmovdqa %xmm0, (%rsp)
vpxor (%r15,%rbp), %xmm0, %xmm0
vmovdqa %xmm0, 0x10(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %rbx, %rdx
callq 0x1120
vmovups 0x270(%rbx), %xmm0
vxorps 0x20(%rsp), %xmm0, %xmm0
vmovups %xmm0, 0x270(%rbx)
addq $0x10, %rbp
addq $-0x10, %r14
cmpq $0x10, %r14
ja 0x1930
jmp 0x19ce
xorl %ebp, %ebp
vmovdqa (%rsp), %xmm0
vpshufb 0x1624(%rip), %xmm0, %xmm0 # 0x3000
vpextrq $0x1, %xmm0, %rcx
vmovq %xmm0, %r13
movq %r13, %rax
shrq %rax
shldq $0x3f, %rcx, %r13
vmovq %r13, %xmm0
vmovq %rax, %xmm1
vpunpcklqdq %xmm0, %xmm1, %xmm0 # xmm0 = xmm1[0],xmm0[0]
testb $0x1, %cl
je 0x1a18
movabsq $-0x1f00000000000000, %rcx # imm = 0xE100000000000000
xorq %rcx, %rax
vpinsrq $0x0, %rax, %xmm0, %xmm0
leaq 0x270(%rbx), %rax
movq %rax, (%rsp)
vmovq %xmm0, %r12
cmpq $0x10, %r14
jne 0x1a78
vmovups (%r15,%rbp), %xmm0
vmovaps %xmm0, 0x10(%rsp)
movq %r12, %rcx
shrq %rcx
movq %r12, %rax
shldq $0x3f, %r13, %rax
vmovq %rax, %xmm0
vmovq %rcx, %xmm1
vpunpcklqdq %xmm0, %xmm1, %xmm0 # xmm0 = xmm1[0],xmm0[0]
testb $0x1, %r13b
je 0x1b04
movabsq $-0x1f00000000000000, %rdx # imm = 0xE100000000000000
xorq %rdx, %rcx
vpinsrq $0x0, %rcx, %xmm0, %xmm0
jmp 0x1b04
vpxor %xmm0, %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
vmovdqa %xmm0, (%rdi)
addq %rbp, %r15
movq %r15, %rsi
movq %r14, %rdx
callq 0x1140
movb $-0x80, 0x10(%rsp,%r14)
movq %r12, %rax
shrq %rax
movq %r12, %rcx
shldq $0x3f, %r13, %rcx
vmovq %rcx, %xmm0
vmovq %rax, %xmm1
vpunpcklqdq %xmm0, %xmm1, %xmm0 # xmm0 = xmm1[0],xmm0[0]
testb $0x1, %r13b
je 0x1ace
movabsq $-0x1f00000000000000, %rdx # imm = 0xE100000000000000
xorq %rdx, %rax
vpinsrq $0x0, %rax, %xmm0, %xmm0
vmovq %xmm0, %rax
movq %rax, %rdx
shrq %rdx
shldq $0x3f, %rcx, %rax
vmovq %rax, %xmm0
vmovq %rdx, %xmm1
vpunpcklqdq %xmm0, %xmm1, %xmm0 # xmm0 = xmm1[0],xmm0[0]
testb $0x1, %cl
je 0x1b04
movabsq $-0x1f00000000000000, %rcx # imm = 0xE100000000000000
xorq %rcx, %rdx
vpinsrq $0x0, %rdx, %xmm0, %xmm0
vmovq %xmm0, %rcx
xorq %r12, %rcx
bswapq %rcx
xorq %r13, %rax
bswapq %rax
vmovq %rax, %xmm0
vmovq %rcx, %xmm1
vpunpcklqdq %xmm0, %xmm1, %xmm0 # xmm0 = xmm1[0],xmm0[0]
leaq 0x10(%rsp), %rdi
vpxor (%rdi), %xmm0, %xmm0
vmovdqa %xmm0, (%rdi)
vpxor 0x270(%rbx), %xmm0, %xmm0
vmovdqa %xmm0, (%rdi)
movq (%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 $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq