// File: /workspace/github_c_makefile_star2_O1/mjosaarinen[P]brutus/crypto_aead/minalpherv11/ref/minalpher.c
// Function: AEAD_TGEN
static void AEAD_TGEN(
  const unsigned char     *_K,    /* I    Secret key                  */
  const unsigned char     *_N,    /* I    Nonce                       */
  const unsigned char     *_A,    /* I    Associated data             */
  unsigned long long      _alen,  /* I    Length of Associated data   */
  const unsigned char     *_C,    /* I    Ciphertext                  */
  unsigned long long      _clen,  /* I    Length of Ciphertext        */

  unsigned char           *tag_   /* O    Tag                         */
  )
{
  int d, pad;
  unsigned long long i, j, blocknum;
  const unsigned char *ap, *cp;
  unsigned char in[BLOCK_SIZE], out[BLOCK_SIZE], t[BLOCK_SIZE], zero[NONCEBYTES];

  i = 1;
  j = 1;
  ap = _A;
  cp = _C;

  /*-- Associated data --*/
  pad = _alen%BLOCK_SIZE;
  blocknum = _alen/BLOCK_SIZE;
  if( pad != 0 ) blocknum += 1;
  Clear( t, BLOCK_SIZE );
  Clear( zero, NONCEBYTES );

  while( blocknum > 1 ){

    Copy( in, ap, BLOCK_SIZE );
    TEM_ENC( _K, FLG_AD, zero, i, 0, in, out );
    Xor( t, out, BLOCK_SIZE );

    i++;
    blocknum--;
    ap += BLOCK_SIZE;
  }

  if( blocknum == 1 ){

    if( (pad == 0) && (_alen != 0) ){
      Copy( in, ap, BLOCK_SIZE );
    }else{
      Copy( in, ap, pad );
      in[pad] = 0x80;
      for( d=pad+1; d<BLOCK_SIZE; d++ ) in[d] = 0x00;
    }
    Xor( in, t, BLOCK_SIZE );

    if( pad == 0 ){
      TEM_ENC( _K, FLG_AD, zero, i-1, 1, in, out );
    }else{
      TEM_ENC( _K, FLG_AD, zero, i-1, 2, in, out );
    }

    Copy( t, out, BLOCK_SIZE );
  }


  /*-- Ciphertext --*/
  i=1;
  blocknum = _clen/BLOCK_SIZE;

  while( blocknum > 1 ){

    Copy( in, cp, BLOCK_SIZE );
    TEM_ENC( _K, FLG_M, _N, 2*i, 0, in, out );
    Xor( t, out, BLOCK_SIZE );

    i++;
    blocknum--;
    cp += BLOCK_SIZE;
  }

  /* blocknum == 1 */
  for( d=0; d<BLOCK_SIZE; d++ ) in[d] = cp[d] ^ t[d];
  TEM_ENC( _K, FLG_M, _N, 2*i-1, 1, in, out );
  Copy( tag_, out, TAGBYTES );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %r9, %r12
movq %r8, %r15
movq %rdx, %rbp
movq %rsi, %r14
movq %rdi, 0x10(%rsp)
xorl %eax, %eax
movl %ecx, %r8d
andl $0x1f, %r8d
setne %al
vxorps %xmm0, %xmm0, %xmm0
vmovups %ymm0, 0x70(%rsp)
xorl %r13d, %r13d
movq %r13, 0x40(%rsp)
movq %r13, 0x45(%rsp)
movq %rcx, %rbx
shrq $0x5, %rbx
addq %rax, %rbx
leaq 0x50(%rsp), %rsi
cmpq $0x2, %rbx
jb 0x154c
movq %rcx, 0x90(%rsp)
movl %r8d, 0x1c(%rsp)
movq %r14, 0x98(%rsp)
movl $0x1, %r13d
vmovups 0x70(%rsp), %ymm0
movq 0x10(%rsp), %r14
vmovups %ymm0, 0xa0(%rsp)
vmovups (%rbp), %ymm0
vmovups %ymm0, 0x20(%rsp)
movq %rsi, (%rsp)
movq %r14, %rdi
xorl %esi, %esi
leaq 0x40(%rsp), %rdx
movq %r13, %rcx
xorl %r8d, %r8d
leaq 0x20(%rsp), %r9
vzeroupper
callq 0x1a5c
vmovups 0xa0(%rsp), %ymm0
leaq 0x50(%rsp), %rsi
vxorps 0x50(%rsp), %ymm0, %ymm0
incq %r13
addq $0x20, %rbp
cmpq %r13, %rbx
jne 0x14d4
vmovups %ymm0, 0x70(%rsp)
decq %r13
movl $0x1, %ebx
movq 0x98(%rsp), %r14
movl 0x1c(%rsp), %r8d
movq 0x90(%rsp), %rcx
testq %rbx, %rbx
movq 0x10(%rsp), %rbx
je 0x1627
testl %r8d, %r8d
setne %al
testq %rcx, %rcx
sete %dl
orb %al, %dl
jne 0x157f
xorl %eax, %eax
movb (%rbp,%rax), %cl
movb %cl, 0x20(%rsp,%rax)
incq %rax
cmpq $0x20, %rax
jne 0x156c
jmp 0x15da
testl %r8d, %r8d
je 0x159b
movl %ecx, %eax
andl $0x1f, %eax
xorl %edi, %edi
movb (%rbp,%rdi), %dl
movb %dl, 0x20(%rsp,%rdi)
incq %rdi
cmpq %rdi, %rax
jne 0x158b
movl %ecx, %eax
andl $0x1f, %eax
movb $-0x80, 0x20(%rsp,%rax)
cmpl $0x1f, %r8d
je 0x15da
andl $0x1f, %ecx
leaq (%rsp,%rcx), %rdi
addq $0x21, %rdi
xorl %eax, %eax
movl $0x1e, %edx
subl %r8d, %edx
cmovbl %eax, %edx
incl %edx
xorl %esi, %esi
movl %r8d, %ebp
vzeroupper
callq 0x1040
movl %ebp, %r8d
leaq 0x50(%rsp), %rsi
leaq 0x20(%rsp), %r9
vmovups (%r9), %ymm0
vxorps 0x70(%rsp), %ymm0, %ymm0
vmovups %ymm0, (%r9)
cmpl $0x1, %r8d
movl $0x2, %r8d
sbbq $0x0, %r8
movq %rsi, (%rsp)
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
movq %r13, %rcx
vzeroupper
callq 0x1a5c
leaq 0x50(%rsp), %rsi
vmovups 0x50(%rsp), %ymm0
vmovups %ymm0, 0x70(%rsp)
movl $0x1, %r13d
cmpq $0x40, %r12
jb 0x16a2
shrq $0x5, %r12
vmovups 0x70(%rsp), %ymm0
leaq 0x20(%rsp), %rbp
vmovups %ymm0, 0xa0(%rsp)
vmovups (%r15), %ymm0
vmovups %ymm0, 0x20(%rsp)
leaq 0x1(%r13), %rcx
movq %rsi, (%rsp)
movq %rbx, %rdi
movl $0x40, %esi
movq %r14, %rdx
xorl %r8d, %r8d
movq %rbp, %r9
vzeroupper
callq 0x1a5c
vmovups 0xa0(%rsp), %ymm0
leaq 0x50(%rsp), %rsi
vxorps 0x50(%rsp), %ymm0, %ymm0
decq %r12
addq $0x20, %r15
addq $0x2, %r13
cmpq $0x1, %r12
ja 0x1642
vmovups %ymm0, 0x70(%rsp)
movq 0x100(%rsp), %rbx
xorl %eax, %eax
movb 0x70(%rsp,%rax), %cl
xorb (%r15,%rax), %cl
movb %cl, 0x20(%rsp,%rax)
incq %rax
cmpq $0x20, %rax
jne 0x16ac
movq %rsi, (%rsp)
leaq 0x20(%rsp), %r9
movl $0x1, %r8d
movq 0x10(%rsp), %rdi
movl $0x40, %esi
movq %r14, %rdx
movq %r13, %rcx
vzeroupper
callq 0x1a5c
vmovaps 0x50(%rsp), %xmm0
vmovups %xmm0, (%rbx)
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq