// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/minalpherv11/ref/minalpher.c
// Function: AEAD_CGEN
static void AEAD_CGEN(
  const unsigned char     *_K,    /* I    Secret key              */
  const unsigned char     *_N,    /* I    Nonce                   */
  const unsigned char     *_M,    /* I    Message                 */
  unsigned long long      _mlen,  /* I    Length of Message       */

  unsigned char           *C_,    /* O    Ciphertext              */
  unsigned long long      *clen_  /* O    Length of Ciphertext    */
  )
{
  int d, pad;
  unsigned long long i, blocknum;
  const unsigned char *mp;
  unsigned char *cp, in[BLOCK_SIZE], out[BLOCK_SIZE];

  i = 1;
  mp = _M;
  cp = C_;

  pad = _mlen%BLOCK_SIZE;
  blocknum = _mlen/BLOCK_SIZE+1;
  *clen_ = blocknum*BLOCK_SIZE;

  while( blocknum > 1 ){

    Copy( in, mp, BLOCK_SIZE );
    TEM_ENC( _K, FLG_M, _N, i, 0, in, out );
    Copy( cp, out, BLOCK_SIZE );

    i += 2;
    blocknum--;
    mp += BLOCK_SIZE;
    cp += BLOCK_SIZE;
  }

  /* blocknum == 1 */
  Copy( in, mp, pad );
  in[pad] = 0x80;
  for( d=pad+1; d<BLOCK_SIZE; d++ ) in[d] = 0x00;
  TEM_ENC( _K, FLG_M, _N, i, 0, in, out );
  Copy( cp, out, BLOCK_SIZE );
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xb0(%rsp)
movq %rsi, 0xa8(%rsp)
movq %rdx, 0xa0(%rsp)
movq %rcx, 0x98(%rsp)
movq %r8, 0x90(%rsp)
movq %r9, 0x88(%rsp)
movq $0x1, 0x78(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x98(%rsp), %rax
andq $0x1f, %rax
movl %eax, 0x80(%rsp)
movq 0x98(%rsp), %rax
shrq $0x5, %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rcx
shlq $0x5, %rcx
movq 0x88(%rsp), %rax
movq %rcx, (%rax)
cmpq $0x1, 0x70(%rsp)
jbe 0x1689
jmp 0x15b4
movl $0x0, 0x1c(%rsp)
cmpl $0x20, 0x1c(%rsp)
jge 0x15e6
movq 0x68(%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 0x15bc
jmp 0x15e8
movq 0xb0(%rsp), %rdi
movq 0xa8(%rsp), %rdx
movq 0x78(%rsp), %rcx
leaq 0x40(%rsp), %r9
leaq 0x20(%rsp), %rax
movl $0x40, %esi
xorl %r8d, %r8d
movq %rax, (%rsp)
callq 0x2570
movl $0x0, 0x18(%rsp)
cmpl $0x20, 0x18(%rsp)
jge 0x164a
movslq 0x18(%rsp), %rax
movb 0x20(%rsp,%rax), %dl
movq 0x60(%rsp), %rax
movslq 0x18(%rsp), %rcx
movb %dl, (%rax,%rcx)
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x1620
jmp 0x164c
movq 0x78(%rsp), %rax
addq $0x2, %rax
movq %rax, 0x78(%rsp)
movq 0x70(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x70(%rsp)
movq 0x68(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x68(%rsp)
movq 0x60(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x60(%rsp)
jmp 0x15a6
jmp 0x168b
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %eax
cmpl 0x80(%rsp), %eax
jge 0x16c3
movq 0x68(%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 0x1693
jmp 0x16c5
movslq 0x80(%rsp), %rax
movb $-0x80, 0x40(%rsp,%rax)
movl 0x80(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
cmpl $0x20, 0x84(%rsp)
jge 0x170d
movslq 0x84(%rsp), %rax
movb $0x0, 0x40(%rsp,%rax)
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
jmp 0x16e3
movq 0xb0(%rsp), %rdi
movq 0xa8(%rsp), %rdx
movq 0x78(%rsp), %rcx
leaq 0x40(%rsp), %r9
leaq 0x20(%rsp), %rax
movl $0x40, %esi
xorl %r8d, %r8d
movq %rax, (%rsp)
callq 0x2570
movl $0x0, 0x10(%rsp)
cmpl $0x20, 0x10(%rsp)
jge 0x176f
movslq 0x10(%rsp), %rax
movb 0x20(%rsp,%rax), %dl
movq 0x60(%rsp), %rax
movslq 0x10(%rsp), %rcx
movb %dl, (%rax,%rcx)
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x1745
jmp 0x1771
addq $0xb8, %rsp
retq
nopl (%rax)