// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/minalpherv11/ref/minalpher.c
// Function: TEM_DEC
static void TEM_DEC(
  const unsigned char     *_K,    /* I    Secret key              */
  unsigned char           _flag,  /* I    Flag for the padding    */
  const unsigned char     *_N,    /* I    Nonce                   */
  unsigned long long      _i,     /* I    an integer              */
  unsigned long long      _j,     /* I    an integer              */
  unsigned char           *_C,    /* I    Ciphertext              */

  unsigned char           *M_     /* O    Message                 */
  )
{
  int d;
  unsigned char L[BLOCK_SIZE];

  /*-- L=(K||flag||N) + P(K||flag||N) --*/
  Copy( L, _K, KEYBYTES );
  L[KEYBYTES]   = _flag;
  L[KEYBYTES+1] = 0x00;
  L[KEYBYTES+2] = 0x00;
  for( d=0; d<NONCEBYTES; d++ ) L[d+KEYBYTES+3] = _N[d];

  minalpher_P( L, FORWARD );

  Xor( L, _K, KEYBYTES );
  L[KEYBYTES]   ^= _flag;
  L[KEYBYTES+1] ^= 0x00;
  L[KEYBYTES+2] ^= 0x00;
  for( d=0; d<NONCEBYTES; d++ ) L[d+KEYBYTES+3] ^= _N[d];

  /* M=y^{i}(y+1)^{j}L + P^{-1}(C+y^{i}(y+1)^{j}L)    --*/
  Copy( M_, _C, BLOCK_SIZE );
  TweakGen( L, _i, _j );
  Xor(  M_,  L, BLOCK_SIZE );
  minalpher_P( M_, BACKWARD );
  Xor(  M_,  L, BLOCK_SIZE );
}

// Assembly:
subq $0x78, %rsp
movb %sil, %al
movq 0x80(%rsp), %rsi
movq %rdi, 0x70(%rsp)
movb %al, 0x6f(%rsp)
movq %rdx, 0x60(%rsp)
movq %rcx, 0x58(%rsp)
movq %r8, 0x50(%rsp)
movq %r9, 0x48(%rsp)
movl $0x0, 0x1c(%rsp)
cmpl $0x10, 0x1c(%rsp)
jge 0x28ee
movq 0x70(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movb (%rax,%rcx), %cl
movslq 0x1c(%rsp), %rax
movb %cl, 0x20(%rsp,%rax)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x28c4
jmp 0x28f0
movb 0x6f(%rsp), %al
movb %al, 0x30(%rsp)
movb $0x0, 0x31(%rsp)
movb $0x0, 0x32(%rsp)
movl $0x0, 0x44(%rsp)
cmpl $0xd, 0x44(%rsp)
jge 0x293b
movq 0x60(%rsp), %rax
movslq 0x44(%rsp), %rcx
movb (%rax,%rcx), %cl
movl 0x44(%rsp), %eax
addl $0x10, %eax
addl $0x3, %eax
cltq
movb %cl, 0x20(%rsp,%rax)
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x290a
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
callq 0x2ad0
movl $0x0, 0x18(%rsp)
cmpl $0x10, 0x18(%rsp)
jge 0x2981
movq 0x70(%rsp), %rax
movslq 0x18(%rsp), %rcx
movzbl (%rax,%rcx), %edx
movslq 0x18(%rsp), %rax
movzbl 0x20(%rsp,%rax), %ecx
xorl %edx, %ecx
movb %cl, 0x20(%rsp,%rax)
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x294f
jmp 0x2983
movzbl 0x6f(%rsp), %ecx
movzbl 0x30(%rsp), %eax
xorl %ecx, %eax
movb %al, 0x30(%rsp)
movzbl 0x31(%rsp), %eax
xorl $0x0, %eax
movb %al, 0x31(%rsp)
movzbl 0x32(%rsp), %eax
xorl $0x0, %eax
movb %al, 0x32(%rsp)
movl $0x0, 0x44(%rsp)
cmpl $0xd, 0x44(%rsp)
jge 0x29ec
movq 0x60(%rsp), %rax
movslq 0x44(%rsp), %rcx
movzbl (%rax,%rcx), %edx
movl 0x44(%rsp), %eax
addl $0x10, %eax
addl $0x3, %eax
cltq
movzbl 0x20(%rsp,%rax), %ecx
xorl %edx, %ecx
movb %cl, 0x20(%rsp,%rax)
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x29b3
jmp 0x29ee
movl $0x0, 0x14(%rsp)
cmpl $0x20, 0x14(%rsp)
jge 0x2a27
movq 0x48(%rsp), %rax
movslq 0x14(%rsp), %rcx
movb (%rax,%rcx), %dl
movq 0x80(%rsp), %rax
movslq 0x14(%rsp), %rcx
movb %dl, (%rax,%rcx)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x29f6
jmp 0x2a29
leaq 0x20(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdx
callq 0x2c00
movl $0x0, 0x10(%rsp)
cmpl $0x20, 0x10(%rsp)
jge 0x2a79
movslq 0x10(%rsp), %rax
movzbl 0x20(%rsp,%rax), %esi
movq 0x80(%rsp), %rax
movslq 0x10(%rsp), %rcx
movzbl (%rax,%rcx), %edx
xorl %esi, %edx
movb %dl, (%rax,%rcx)
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x2a45
jmp 0x2a7b
movq 0x80(%rsp), %rdi
movl $0x1, %esi
callq 0x2ad0
movl $0x0, 0xc(%rsp)
cmpl $0x20, 0xc(%rsp)
jge 0x2ac9
movslq 0xc(%rsp), %rax
movzbl 0x20(%rsp,%rax), %esi
movq 0x80(%rsp), %rax
movslq 0xc(%rsp), %rcx
movzbl (%rax,%rcx), %edx
xorl %esi, %edx
movb %dl, (%rax,%rcx)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x2a95
jmp 0x2acb
addq $0x78, %rsp
retq