// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
leaq 0x40(%rsp), %rax
movq %rax, 0x38(%rsp)
movq $0x0, 0x8(%rsp)
movq 0x60(%rsp), %rax
movq $0x0, 0x280(%rax)
movq 0x60(%rsp), %rax
movq 0x220(%rax), %rcx
movq %rcx, 0x40(%rsp)
movq 0x228(%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x60(%rsp), %rdi
addq $0x270, %rdi            # imm = 0x270
xorl %esi, %esi
movl $0x10, %edx
callq 0x1030
cmpq $0x10, 0x50(%rsp)
jbe 0x27e5
cmpq $0x0, 0x8(%rsp)
je 0x2775
movq 0x40(%rsp), %rdi
callq 0x29b0
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rdi
callq 0x29b0
movq %rax, 0x48(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x2a60
movq 0x40(%rsp), %rdi
callq 0x29b0
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rdi
callq 0x29b0
movq %rax, 0x48(%rsp)
leaq 0x20(%rsp), %rdi
movq 0x58(%rsp), %rsi
addq 0x8(%rsp), %rsi
movq 0x38(%rsp), %rdx
callq 0x1150
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq 0x60(%rsp), %rdx
callq 0x1130
movq 0x60(%rsp), %rdi
addq $0x270, %rdi            # imm = 0x270
leaq 0x10(%rsp), %rsi
movq 0x60(%rsp), %rdx
addq $0x270, %rdx            # imm = 0x270
callq 0x1150
movq 0x8(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x8(%rsp)
movq 0x50(%rsp), %rax
subq $0x10, %rax
movq %rax, 0x50(%rsp)
jmp 0x271b
movq 0x40(%rsp), %rdi
callq 0x29b0
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rdi
callq 0x29b0
movq %rax, 0x48(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x2a60
movq 0x40(%rsp), %rdi
callq 0x29b0
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rdi
callq 0x29b0
movq %rax, 0x48(%rsp)
cmpq $0x10, 0x50(%rsp)
jae 0x28af
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1030
leaq 0x20(%rsp), %rdi
movq 0x58(%rsp), %rsi
addq 0x8(%rsp), %rsi
movq 0x50(%rsp), %rdx
callq 0x1160
movq 0x50(%rsp), %rax
movb $-0x80, 0x20(%rsp,%rax)
movq 0x40(%rsp), %rdi
callq 0x29b0
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rdi
callq 0x29b0
movq %rax, 0x48(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x2ab0
movq 0x40(%rsp), %rdi
callq 0x29b0
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rdi
callq 0x29b0
movq %rax, 0x48(%rsp)
jmp 0x2912
movq 0x58(%rsp), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx), %rdx
movq %rdx, 0x20(%rsp)
movq 0x8(%rax,%rcx), %rax
movq %rax, 0x28(%rsp)
movq 0x40(%rsp), %rdi
callq 0x29b0
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rdi
callq 0x29b0
movq %rax, 0x48(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x2b10
movq 0x40(%rsp), %rdi
callq 0x29b0
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rdi
callq 0x29b0
movq %rax, 0x48(%rsp)
leaq 0x20(%rsp), %rdi
movq 0x38(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x1150
leaq 0x20(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq 0x60(%rsp), %rdx
addq $0x270, %rdx            # imm = 0x270
callq 0x1150
leaq 0x20(%rsp), %rdi
movq 0x60(%rsp), %rsi
addq $0x270, %rsi            # imm = 0x270
movq 0x60(%rsp), %rdx
callq 0x1130
movq 0x60(%rsp), %rax
movq 0x60(%rsp), %rcx
movq 0x270(%rcx), %rdx
movq %rdx, 0x250(%rax)
movq 0x278(%rcx), %rcx
movq %rcx, 0x258(%rax)
movq 0x60(%rsp), %rax
movq 0x60(%rsp), %rcx
movq 0x270(%rcx), %rdx
movq %rdx, 0x260(%rax)
movq 0x278(%rcx), %rcx
movq %rcx, 0x268(%rax)
addq $0x68, %rsp
retq
nopl (%rax)