// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/aes128poetv1aes4/ref/poet.c
// Function: process_header
void process_header(struct poet_ctx *ctx, const uint8_t  *header,
		    uint64_t header_len)
{
  block mask;
  block factor;
  block in;
  block out;
  block product;
  uint64_t offset=0;

  ctx->mlen=0;
  memset(factor,0,BLOCKLEN);
  memset(product,0,BLOCKLEN);
  memset(mask,0,BLOCKLEN);
  memset(ctx->tau,0,BLOCKLEN);

  product[0] = 0x80; // since 1000 0000 = 1
  factor[0]  = 0x40; // since 0100 0000 = 2

  while(header_len > BLOCKLEN)
    {
      gf_mul(mask, product, ctx->l);
      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;

      gf_mul(product,product,factor);
    }

  /* LASTBLOCK */
  if(header_len < 16)
    {
      factor[0]=0xA0; // 1010 0000 = 5 in Big Endian
      memset(in,0,BLOCKLEN);
      memcpy(in,header+offset,header_len);
      in[header_len]=0x80;
    }
  else
    {
      factor[0]=0xC0; // 1100 0000 = 3 in Big Endian
      memcpy(in,header+offset,BLOCKLEN);
    }

  gf_mul(product,product,factor);
  gf_mul(mask,product,ctx->l);
  xor_block(in,mask,in);

  xor_block(in,in,ctx->tau);
  AES_encrypt(in ,ctx->tau, &(ctx->aes_enc));

  memcpy(ctx->x, ctx->tau, BLOCKLEN);
  memcpy(ctx->y, ctx->tau, BLOCKLEN);
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq %rdx, 0x60(%rsp)
movq $0x0, 0x8(%rsp)
movq 0x70(%rsp), %rax
movq $0x0, 0x450(%rax)
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1030
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1030
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1030
movq 0x70(%rsp), %rdi
addq $0x440, %rdi            # imm = 0x440
xorl %esi, %esi
movl $0x10, %edx
callq 0x1030
movb $-0x80, 0x10(%rsp)
movb $0x40, 0x40(%rsp)
cmpq $0x10, 0x60(%rsp)
jbe 0x67dc
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq 0x70(%rsp), %rdx
addq $0x3f0, %rdx            # imm = 0x3F0
callq 0x1040
leaq 0x30(%rsp), %rdi
movq 0x68(%rsp), %rsi
addq 0x8(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x1110
leaq 0x30(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq 0x70(%rsp), %rdx
callq 0x1060
movq 0x70(%rsp), %rdi
addq $0x440, %rdi            # imm = 0x440
leaq 0x20(%rsp), %rsi
movq 0x70(%rsp), %rdx
addq $0x440, %rdx            # imm = 0x440
callq 0x1110
movq 0x8(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x8(%rsp)
movq 0x60(%rsp), %rax
subq $0x10, %rax
movq %rax, 0x60(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x1040
jmp 0x6731
cmpq $0x10, 0x60(%rsp)
jae 0x681f
movb $-0x60, 0x40(%rsp)
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1030
leaq 0x30(%rsp), %rdi
movq 0x68(%rsp), %rsi
addq 0x8(%rsp), %rsi
movq 0x60(%rsp), %rdx
callq 0x1120
movq 0x60(%rsp), %rax
movb $-0x80, 0x30(%rsp,%rax)
jmp 0x6841
movb $-0x40, 0x40(%rsp)
movq 0x68(%rsp), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx), %rdx
movq %rdx, 0x30(%rsp)
movq 0x8(%rax,%rcx), %rax
movq %rax, 0x38(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x1040
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq 0x70(%rsp), %rdx
addq $0x3f0, %rdx            # imm = 0x3F0
callq 0x1040
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x1110
leaq 0x30(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movq 0x70(%rsp), %rdx
addq $0x440, %rdx            # imm = 0x440
callq 0x1110
leaq 0x30(%rsp), %rdi
movq 0x70(%rsp), %rsi
addq $0x440, %rsi            # imm = 0x440
movq 0x70(%rsp), %rdx
callq 0x1060
movq 0x70(%rsp), %rax
movq 0x70(%rsp), %rcx
movq 0x440(%rcx), %rdx
movq %rdx, 0x420(%rax)
movq 0x448(%rcx), %rcx
movq %rcx, 0x428(%rax)
movq 0x70(%rsp), %rax
movq 0x70(%rsp), %rcx
movq 0x440(%rcx), %rdx
movq %rdx, 0x430(%rax)
movq 0x448(%rcx), %rcx
movq %rcx, 0x438(%rax)
addq $0x78, %rsp
retq
nopl (%rax,%rax)