// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/minalpherv11/ref/minalpher.c
// Function: AEAD_MGEN
static int AEAD_MGEN(
  const unsigned char     *_K,    /* I    Secret key              */
  const unsigned char     *_N,    /* I    Nonce                   */
  const unsigned char     *_C,    /* I    Ciphertext              */
  unsigned long long      _clen,  /* I    Length of Ciphertext    */

  unsigned char           *M_,    /* O    Message                 */
  unsigned long long      *mlen_  /* O    Length of Message       */
  )
{
  int d, pad, cnt;
  unsigned long long i, blocknum, len;
  const unsigned char *cp;
  unsigned char *mp, in[BLOCK_SIZE], out[BLOCK_SIZE];

  i = 1;
  cp = _C;
  mp = M_;

  pad = 0;
  cnt = 0;
  len = 0;
  blocknum = _clen/BLOCK_SIZE;

  while( blocknum > 1 ){

    Copy( in, cp, BLOCK_SIZE );
    TEM_DEC( _K, FLG_M, _N, i, 0, in, out );
    Copy( mp, out, BLOCK_SIZE );

    i += 2;
    blocknum--;
    cp += BLOCK_SIZE;
    mp += BLOCK_SIZE;
    len += BLOCK_SIZE;
  }

  Copy( in, cp, BLOCK_SIZE );
  TEM_DEC( _K, FLG_M, _N, i, 0, in, out );
  for(d=BLOCK_SIZE-1; d>=0; d--){
    if( out[d]==0x80 ){
      Copy( mp, out, d );
      *mlen_ = len + d;
      return 0;
    }
    if( out[d]!=0x00 ) break;
  }
  return -1;
}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0xc8(%rsp)
movq %rsi, 0xc0(%rsp)
movq %rdx, 0xb8(%rsp)
movq %rcx, 0xb0(%rsp)
movq %r8, 0xa8(%rsp)
movq %r9, 0xa0(%rsp)
movq $0x1, 0x88(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0xa8(%rsp), %rax
movq %rax, 0x68(%rsp)
movl $0x0, 0x98(%rsp)
movl $0x0, 0x94(%rsp)
movq $0x0, 0x78(%rsp)
movq 0xb0(%rsp), %rax
shrq $0x5, %rax
movq %rax, 0x80(%rsp)
cmpq $0x1, 0x80(%rsp)
jbe 0x2023
jmp 0x1f31
movl $0x0, 0x1c(%rsp)
cmpl $0x20, 0x1c(%rsp)
jge 0x1f63
movq 0x70(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movb (%rax,%rcx), %cl
movslq 0x1c(%rsp), %rax
movb %cl, 0x40(%rsp,%rax)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x1f39
jmp 0x1f65
movq 0xc8(%rsp), %rdi
movq 0xc0(%rsp), %rdx
movq 0x88(%rsp), %rcx
leaq 0x40(%rsp), %r9
leaq 0x20(%rsp), %rax
movl $0x40, %esi
xorl %r8d, %r8d
movq %rax, (%rsp)
callq 0x2890
movl $0x0, 0x18(%rsp)
cmpl $0x20, 0x18(%rsp)
jge 0x1fca
movslq 0x18(%rsp), %rax
movb 0x20(%rsp,%rax), %dl
movq 0x68(%rsp), %rax
movslq 0x18(%rsp), %rcx
movb %dl, (%rax,%rcx)
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x1fa0
jmp 0x1fcc
movq 0x88(%rsp), %rax
addq $0x2, %rax
movq %rax, 0x88(%rsp)
movq 0x80(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x80(%rsp)
movq 0x70(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x70(%rsp)
movq 0x68(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x68(%rsp)
movq 0x78(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x78(%rsp)
jmp 0x1f20
jmp 0x2025
movl $0x0, 0x14(%rsp)
cmpl $0x20, 0x14(%rsp)
jge 0x2057
movq 0x70(%rsp), %rax
movslq 0x14(%rsp), %rcx
movb (%rax,%rcx), %cl
movslq 0x14(%rsp), %rax
movb %cl, 0x40(%rsp,%rax)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x202d
jmp 0x2059
movq 0xc8(%rsp), %rdi
movq 0xc0(%rsp), %rdx
movq 0x88(%rsp), %rcx
leaq 0x40(%rsp), %r9
leaq 0x20(%rsp), %rax
movl $0x40, %esi
xorl %r8d, %r8d
movq %rax, (%rsp)
callq 0x2890
movl $0x1f, 0x9c(%rsp)
cmpl $0x0, 0x9c(%rsp)
jl 0x2149
movslq 0x9c(%rsp), %rax
movzbl 0x20(%rsp,%rax), %eax
cmpl $0x80, %eax
jne 0x211d
jmp 0x20bb
movl $0x0, 0x10(%rsp)
movl 0x10(%rsp), %eax
cmpl 0x9c(%rsp), %eax
jge 0x20f3
movslq 0x10(%rsp), %rax
movb 0x20(%rsp,%rax), %dl
movq 0x68(%rsp), %rax
movslq 0x10(%rsp), %rcx
movb %dl, (%rax,%rcx)
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x20c3
jmp 0x20f5
movq 0x78(%rsp), %rcx
movslq 0x9c(%rsp), %rax
addq %rax, %rcx
movq 0xa0(%rsp), %rax
movq %rcx, (%rax)
movl $0x0, 0xd4(%rsp)
jmp 0x2154
movslq 0x9c(%rsp), %rax
movzbl 0x20(%rsp,%rax), %eax
cmpl $0x0, %eax
je 0x2131
jmp 0x2149
jmp 0x2133
movl 0x9c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0x2097
movl $0xffffffff, 0xd4(%rsp) # imm = 0xFFFFFFFF
movl 0xd4(%rsp), %eax
addq $0xd8, %rsp
retq
nopw %cs:(%rax,%rax)