// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/minalpherv11/ref/minalpher.c
// Function: MAC_GEN
int MAC_GEN(
  const unsigned char     *_K,    /* I    Secret key              */
  const unsigned char     *_M,    /* I    Message                 */
  unsigned long long      _mlen,  /* I    Length of Message       */

  unsigned char           *C_,    /* O    Tag                     */
  unsigned long long      *clen_  /* O    Length of Tag           */
  )
{
  int d, pad;
  unsigned long long i, blocknum;
  const unsigned char *mp;
  unsigned char *cp, in[BLOCK_SIZE], out[BLOCK_SIZE], t[BLOCK_SIZE], zero[NONCEBYTES];

  i = 1;
  mp = _M;
  cp = C_;

  pad = _mlen%BLOCK_SIZE;
  blocknum = _mlen/BLOCK_SIZE;
  if( (pad!=0) || (_mlen==0) ) blocknum += 1;
  Clear( t, BLOCK_SIZE );
  Clear( zero, NONCEBYTES );

  while( blocknum > 1 ){

    Copy( in, mp, BLOCK_SIZE );
    TEM_ENC( _K, FLG_MAC, zero, i, 0, in, out );
    Xor( t, out, BLOCK_SIZE );

    i++;
    blocknum--;
    mp += BLOCK_SIZE;
  }

  /* blocknum == 1 */
  if( (pad==0) && (_mlen!=0) ){
    Copy( in, mp, BLOCK_SIZE );
  }else{
    Copy( in, mp, pad );
    in[pad] = 0x80;
    for( d=pad+1; d<BLOCK_SIZE; d++ ) in[d] = 0x00;
  }

  Xor( in, t, BLOCK_SIZE );
  if( (pad==0) && (_mlen!=0) ){
    TEM_ENC( _K, FLG_MAC, zero, i-1, 1, in, out );
  }else{
    TEM_ENC( _K, FLG_MAC, zero, i-1, 2, in, out );
  }
  Copy( cp, out, TAGBYTES );
  *clen_ = TAGBYTES;

  return 0;
}

// Assembly:
subq $0xf8, %rsp
movq %rdi, 0xf0(%rsp)
movq %rsi, 0xe8(%rsp)
movq %rdx, 0xe0(%rsp)
movq %rcx, 0xd8(%rsp)
movq %r8, 0xd0(%rsp)
movq $0x1, 0xc0(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0xb0(%rsp)
movq 0xd8(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq 0xe0(%rsp), %rax
andq $0x1f, %rax
movl %eax, 0xc8(%rsp)
movq 0xe0(%rsp), %rax
shrq $0x5, %rax
movq %rax, 0xb8(%rsp)
cmpl $0x0, 0xc8(%rsp)
jne 0x2207
cmpq $0x0, 0xe0(%rsp)
jne 0x221b
movq 0xb8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xb8(%rsp)
jmp 0x221d
movl $0x0, 0x2c(%rsp)
cmpl $0x20, 0x2c(%rsp)
jge 0x2243
movslq 0x2c(%rsp), %rax
movb $0x0, 0x40(%rsp,%rax)
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x2225
jmp 0x2245
jmp 0x2247
movl $0x0, 0x28(%rsp)
cmpl $0xd, 0x28(%rsp)
jge 0x226d
movslq 0x28(%rsp), %rax
movb $0x0, 0x33(%rsp,%rax)
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x224f
jmp 0x226f
jmp 0x2271
cmpq $0x1, 0xb8(%rsp)
jbe 0x2368
jmp 0x2282
movl $0x0, 0x24(%rsp)
cmpl $0x20, 0x24(%rsp)
jge 0x22ba
movq 0xb0(%rsp), %rax
movslq 0x24(%rsp), %rcx
movb (%rax,%rcx), %cl
movslq 0x24(%rsp), %rax
movb %cl, 0x80(%rsp,%rax)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x228a
jmp 0x22bc
movq 0xf0(%rsp), %rdi
leaq 0x33(%rsp), %rdx
movq 0xc0(%rsp), %rcx
leaq 0x80(%rsp), %r9
leaq 0x60(%rsp), %rax
movl $0x80, %esi
xorl %r8d, %r8d
movq %rax, (%rsp)
callq 0x2570
movl $0x0, 0x20(%rsp)
cmpl $0x20, 0x20(%rsp)
jge 0x2325
movslq 0x20(%rsp), %rax
movzbl 0x60(%rsp,%rax), %edx
movslq 0x20(%rsp), %rax
movzbl 0x40(%rsp,%rax), %ecx
xorl %edx, %ecx
movb %cl, 0x40(%rsp,%rax)
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x22f7
jmp 0x2327
movq 0xc0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xc0(%rsp)
movq 0xb8(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0xb8(%rsp)
movq 0xb0(%rsp), %rax
addq $0x20, %rax
movq %rax, 0xb0(%rsp)
jmp 0x2271
cmpl $0x0, 0xc8(%rsp)
jne 0x23be
cmpq $0x0, 0xe0(%rsp)
je 0x23be
jmp 0x237f
movl $0x0, 0x1c(%rsp)
cmpl $0x20, 0x1c(%rsp)
jge 0x23b7
movq 0xb0(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movb (%rax,%rcx), %cl
movslq 0x1c(%rsp), %rax
movb %cl, 0x80(%rsp,%rax)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x2387
jmp 0x23b9
jmp 0x2450
jmp 0x23c0
movl $0x0, 0x18(%rsp)
movl 0x18(%rsp), %eax
cmpl 0xc8(%rsp), %eax
jge 0x23fe
movq 0xb0(%rsp), %rax
movslq 0x18(%rsp), %rcx
movb (%rax,%rcx), %cl
movslq 0x18(%rsp), %rax
movb %cl, 0x80(%rsp,%rax)
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x23c8
jmp 0x2400
movslq 0xc8(%rsp), %rax
movb $-0x80, 0x80(%rsp,%rax)
movl 0xc8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xcc(%rsp)
cmpl $0x20, 0xcc(%rsp)
jge 0x244e
movslq 0xcc(%rsp), %rax
movb $0x0, 0x80(%rsp,%rax)
movl 0xcc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xcc(%rsp)
jmp 0x2421
jmp 0x2450
jmp 0x2452
movl $0x0, 0x14(%rsp)
cmpl $0x20, 0x14(%rsp)
jge 0x248e
movslq 0x14(%rsp), %rax
movzbl 0x40(%rsp,%rax), %edx
movslq 0x14(%rsp), %rax
movzbl 0x80(%rsp,%rax), %ecx
xorl %edx, %ecx
movb %cl, 0x80(%rsp,%rax)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x245a
jmp 0x2490
cmpl $0x0, 0xc8(%rsp)
jne 0x24e1
cmpq $0x0, 0xe0(%rsp)
je 0x24e1
movq 0xf0(%rsp), %rdi
leaq 0x33(%rsp), %rdx
movq 0xc0(%rsp), %rcx
subq $0x1, %rcx
leaq 0x80(%rsp), %r9
leaq 0x60(%rsp), %rax
movl $0x80, %esi
movl $0x1, %r8d
movq %rax, (%rsp)
callq 0x2570
jmp 0x251b
movq 0xf0(%rsp), %rdi
leaq 0x33(%rsp), %rdx
movq 0xc0(%rsp), %rcx
subq $0x1, %rcx
leaq 0x80(%rsp), %r9
leaq 0x60(%rsp), %rax
movl $0x80, %esi
movl $0x2, %r8d
movq %rax, (%rsp)
callq 0x2570
jmp 0x251d
movl $0x0, 0x10(%rsp)
cmpl $0x10, 0x10(%rsp)
jge 0x2552
movslq 0x10(%rsp), %rax
movb 0x60(%rsp,%rax), %dl
movq 0xa8(%rsp), %rax
movslq 0x10(%rsp), %rcx
movb %dl, (%rax,%rcx)
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x2525
jmp 0x2554
movq 0xd0(%rsp), %rax
movq $0x10, (%rax)
xorl %eax, %eax
addq $0xf8, %rsp
retq
nopl (%rax)