// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x118, %rsp            # imm = 0x118
movq 0x120(%rsp), %rax
movq %rdi, 0x110(%rsp)
movq %rsi, 0x108(%rsp)
movq %rdx, 0x100(%rsp)
movq %rcx, 0xf8(%rsp)
movq %r8, 0xf0(%rsp)
movq %r9, 0xe8(%rsp)
movq $0x1, 0xd8(%rsp)
movq $0x1, 0xd0(%rsp)
movq 0x100(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0xf8(%rsp), %rax
andq $0x1f, %rax
movl %eax, 0xe0(%rsp)
movq 0xf8(%rsp), %rax
shrq $0x5, %rax
movq %rax, 0xc8(%rsp)
cmpl $0x0, 0xe0(%rsp)
je 0x183c
movq 0xc8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xc8(%rsp)
jmp 0x183e
movl $0x0, 0x3c(%rsp)
cmpl $0x20, 0x3c(%rsp)
jge 0x1864
movslq 0x3c(%rsp), %rax
movb $0x0, 0x50(%rsp,%rax)
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x1846
jmp 0x1866
jmp 0x1868
movl $0x0, 0x38(%rsp)
cmpl $0xd, 0x38(%rsp)
jge 0x188e
movslq 0x38(%rsp), %rax
movb $0x0, 0x43(%rsp,%rax)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x1870
jmp 0x1890
jmp 0x1892
cmpq $0x1, 0xc8(%rsp)
jbe 0x1986
jmp 0x18a3
movl $0x0, 0x34(%rsp)
cmpl $0x20, 0x34(%rsp)
jge 0x18db
movq 0xc0(%rsp), %rax
movslq 0x34(%rsp), %rcx
movb (%rax,%rcx), %cl
movslq 0x34(%rsp), %rax
movb %cl, 0x90(%rsp,%rax)
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x18ab
jmp 0x18dd
movq 0x110(%rsp), %rdi
leaq 0x43(%rsp), %rdx
movq 0xd8(%rsp), %rcx
leaq 0x90(%rsp), %r9
leaq 0x70(%rsp), %rax
xorl %esi, %esi
xorl %r8d, %r8d
movq %rax, (%rsp)
callq 0x2570
movl $0x0, 0x30(%rsp)
cmpl $0x20, 0x30(%rsp)
jge 0x1943
movslq 0x30(%rsp), %rax
movzbl 0x70(%rsp,%rax), %edx
movslq 0x30(%rsp), %rax
movzbl 0x50(%rsp,%rax), %ecx
xorl %edx, %ecx
movb %cl, 0x50(%rsp,%rax)
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x1915
jmp 0x1945
movq 0xd8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xd8(%rsp)
movq 0xc8(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0xc8(%rsp)
movq 0xc0(%rsp), %rax
addq $0x20, %rax
movq %rax, 0xc0(%rsp)
jmp 0x1892
cmpq $0x1, 0xc8(%rsp)
jne 0x1b6b
cmpl $0x0, 0xe0(%rsp)
jne 0x19eb
cmpq $0x0, 0xf8(%rsp)
je 0x19eb
jmp 0x19ac
movl $0x0, 0x2c(%rsp)
cmpl $0x20, 0x2c(%rsp)
jge 0x19e4
movq 0xc0(%rsp), %rax
movslq 0x2c(%rsp), %rcx
movb (%rax,%rcx), %cl
movslq 0x2c(%rsp), %rax
movb %cl, 0x90(%rsp,%rax)
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x19b4
jmp 0x19e6
jmp 0x1a7d
jmp 0x19ed
movl $0x0, 0x28(%rsp)
movl 0x28(%rsp), %eax
cmpl 0xe0(%rsp), %eax
jge 0x1a2b
movq 0xc0(%rsp), %rax
movslq 0x28(%rsp), %rcx
movb (%rax,%rcx), %cl
movslq 0x28(%rsp), %rax
movb %cl, 0x90(%rsp,%rax)
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x19f5
jmp 0x1a2d
movslq 0xe0(%rsp), %rax
movb $-0x80, 0x90(%rsp,%rax)
movl 0xe0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe4(%rsp)
cmpl $0x20, 0xe4(%rsp)
jge 0x1a7b
movslq 0xe4(%rsp), %rax
movb $0x0, 0x90(%rsp,%rax)
movl 0xe4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe4(%rsp)
jmp 0x1a4e
jmp 0x1a7d
jmp 0x1a7f
movl $0x0, 0x24(%rsp)
cmpl $0x20, 0x24(%rsp)
jge 0x1abb
movslq 0x24(%rsp), %rax
movzbl 0x50(%rsp,%rax), %edx
movslq 0x24(%rsp), %rax
movzbl 0x90(%rsp,%rax), %ecx
xorl %edx, %ecx
movb %cl, 0x90(%rsp,%rax)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x1a87
jmp 0x1abd
cmpl $0x0, 0xe0(%rsp)
jne 0x1b00
movq 0x110(%rsp), %rdi
leaq 0x43(%rsp), %rdx
movq 0xd8(%rsp), %rcx
subq $0x1, %rcx
leaq 0x90(%rsp), %r9
leaq 0x70(%rsp), %rax
xorl %esi, %esi
movl $0x1, %r8d
movq %rax, (%rsp)
callq 0x2570
jmp 0x1b37
movq 0x110(%rsp), %rdi
leaq 0x43(%rsp), %rdx
movq 0xd8(%rsp), %rcx
subq $0x1, %rcx
leaq 0x90(%rsp), %r9
leaq 0x70(%rsp), %rax
xorl %esi, %esi
movl $0x2, %r8d
movq %rax, (%rsp)
callq 0x2570
jmp 0x1b39
movl $0x0, 0x20(%rsp)
cmpl $0x20, 0x20(%rsp)
jge 0x1b67
movslq 0x20(%rsp), %rax
movb 0x70(%rsp,%rax), %cl
movslq 0x20(%rsp), %rax
movb %cl, 0x50(%rsp,%rax)
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x1b41
jmp 0x1b69
jmp 0x1b6b
movq $0x1, 0xd8(%rsp)
movq 0xe8(%rsp), %rax
shrq $0x5, %rax
movq %rax, 0xc8(%rsp)
cmpq $0x1, 0xc8(%rsp)
jbe 0x1c88
jmp 0x1b9c
movl $0x0, 0x1c(%rsp)
cmpl $0x20, 0x1c(%rsp)
jge 0x1bd4
movq 0xb8(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movb (%rax,%rcx), %cl
movslq 0x1c(%rsp), %rax
movb %cl, 0x90(%rsp,%rax)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x1ba4
jmp 0x1bd6
movq 0x110(%rsp), %rdi
movq 0x108(%rsp), %rdx
movq 0xd8(%rsp), %rcx
shlq %rcx
leaq 0x90(%rsp), %r9
leaq 0x70(%rsp), %rax
movl $0x40, %esi
xorl %r8d, %r8d
movq %rax, (%rsp)
callq 0x2570
movl $0x0, 0x18(%rsp)
cmpl $0x20, 0x18(%rsp)
jge 0x1c45
movslq 0x18(%rsp), %rax
movzbl 0x70(%rsp,%rax), %edx
movslq 0x18(%rsp), %rax
movzbl 0x50(%rsp,%rax), %ecx
xorl %edx, %ecx
movb %cl, 0x50(%rsp,%rax)
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x1c17
jmp 0x1c47
movq 0xd8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xd8(%rsp)
movq 0xc8(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0xc8(%rsp)
movq 0xb8(%rsp), %rax
addq $0x20, %rax
movq %rax, 0xb8(%rsp)
jmp 0x1b8b
movl $0x0, 0xe4(%rsp)
cmpl $0x20, 0xe4(%rsp)
jge 0x1ce4
movq 0xb8(%rsp), %rax
movslq 0xe4(%rsp), %rcx
movzbl (%rax,%rcx), %eax
movslq 0xe4(%rsp), %rcx
movzbl 0x50(%rsp,%rcx), %ecx
xorl %ecx, %eax
movb %al, %cl
movslq 0xe4(%rsp), %rax
movb %cl, 0x90(%rsp,%rax)
movl 0xe4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe4(%rsp)
jmp 0x1c93
movq 0x110(%rsp), %rdi
movq 0x108(%rsp), %rdx
movq 0xd8(%rsp), %rcx
shlq %rcx
subq $0x1, %rcx
leaq 0x90(%rsp), %r9
leaq 0x70(%rsp), %rax
movl $0x40, %esi
movl $0x1, %r8d
movq %rax, (%rsp)
callq 0x2570
movl $0x0, 0x14(%rsp)
cmpl $0x10, 0x14(%rsp)
jge 0x1d59
movslq 0x14(%rsp), %rax
movb 0x70(%rsp,%rax), %dl
movq 0x120(%rsp), %rax
movslq 0x14(%rsp), %rcx
movb %dl, (%rax,%rcx)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x1d2c
jmp 0x1d5b
addq $0x118, %rsp            # imm = 0x118
retq
nopw %cs:(%rax,%rax)