// File: /workspace/github_c_makefile_star2_O0/singpolyma[P]mnemonicode/mnemonic.c
// Function: mn_decode_word_index
int
mn_decode_word_index (mn_index index, void *vdest, int destsize, int *offset)
{
  mn_word32 x;			/* Temporary for MN_BASE arithmetic */
  int groupofs;
  int i;
  mn_byte *dest = vdest;

  if (*offset < 0)		/* Error from previous call? report it */
    return *offset;

  if (index > MN_WORDS)	/* Word index out of range */
    {
      *offset = MN_EINDEX;
      return *offset;
    }

  if (*offset > destsize)	/* out of range? */
    {
      *offset = MN_EOVERRUN;
      return *offset;
    }

  if (index > MN_BASE && *offset % 4 != 2)
    {				/* Unexpected 24 bit remainder word */
      *offset = MN_EINDEX24;
      return *offset;
    }

  groupofs = *offset & ~3;	/* Offset of 4 byte group containing offet */
  x = 0;
  for (i = 0; i < 4; i++)
    if (groupofs + i < destsize)	/* Ignore any bytes outside buffer */
      x |= (unsigned long)dest[groupofs + i] << (i * 8);	/* assemble number */

  if (index == MN_EOF)		/* Got EOF signal */
    {
      switch (*offset % 4)
	{
	case 3:		/* group was three words and the last */
	  return MN_OK;		/*  word was a 24 bit remainder */
	case 2:		/* last group has two words */
	  if (x <= 0xFFFF)	/*  should encode 16 bit data */
	    return MN_OK;
	  else
	    {
	      *offset = MN_EREM;
	      return *offset;
	    }
	case 1:		/* last group has just one word */
	  if (x <= 0xFF)	/*  should encode 8 bits */
	    return MN_OK;
	  else
	    {
	      *offset = MN_EREM;
	      return *offset;
	    }

	case 0:		/* last group was full 3 words */
	  return MN_OK;
	}
    }
  if (*offset == destsize)	/* At EOF but didn't get MN_EOF */
    {
      *offset = MN_EOVERRUN;
      return *offset;
    }

  index--;			/* 1 based to 0 based index */

  switch (*offset % 4)
    {
    case 3:			/* Got data past 24 bit remainder */
      *offset = MN_EOVERRUN24;
      return *offset;
    case 2:
      if (index >= MN_BASE)
	{			/* 24 bit remainder */
	  x += (index - MN_BASE) * MN_BASE * MN_BASE;
	  (*offset)++;		/* *offset%4 == 3 for next time */
	}
      else
	{			/* catch invalid encodings */
	  if (index >= 1625 || (index == 1624 && x > 1312671))
	    {
	      *offset = MN_EENCODING;
	      return *offset;
	    }
	  x += index * MN_BASE * MN_BASE;
	  (*offset) += 2;	/* *offset%4 == 0 for next time */
	}
      break;
    case 1:
      x += index * MN_BASE;
      (*offset)++;
      break;
    case 0:
      x = index;
      (*offset)++;
      break;
    }

  for (i = 0; i < 4; i++)
    if (groupofs + i < destsize)	/* Don't step outside the buffer */
      {
	dest[groupofs + i] = (mn_byte) x % 256;
	x /= 256;
      }
  return MN_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
jge 0xb721
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0xba40
cmpl $0x661, -0x8(%rbp)      # imm = 0x661
jbe 0xb742
movq -0x20(%rbp), %rax
movl $0xfffffffc, (%rax)     # imm = 0xFFFFFFFC
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0xba40
movq -0x20(%rbp), %rax
movl (%rax), %eax
cmpl -0x14(%rbp), %eax
jle 0xb765
movq -0x20(%rbp), %rax
movl $0xfffffffe, (%rax)     # imm = 0xFFFFFFFE
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0xba40
cmpl $0x65a, -0x8(%rbp)      # imm = 0x65A
jbe 0xb799
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl $0x4, %ecx
cltd
idivl %ecx
cmpl $0x2, %edx
je 0xb799
movq -0x20(%rbp), %rax
movl $0xfffffffb, (%rax)     # imm = 0xFFFFFFFB
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0xba40
movq -0x20(%rbp), %rax
movl (%rax), %eax
andl $-0x4, %eax
movl %eax, -0x2c(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x0, -0x30(%rbp)
cmpl $0x4, -0x30(%rbp)
jge 0xb7f6
movl -0x2c(%rbp), %eax
addl -0x30(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xb7e9
movq -0x38(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl -0x30(%rbp), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl -0x30(%rbp), %ecx
shll $0x3, %ecx
movl %ecx, %ecx
shlq %cl, %rax
orq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0xb7eb
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xb7b4
cmpl $0x0, -0x8(%rbp)
jne 0xb8b0
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, %edx
addl $0x3, %edx
testl %eax, %eax
movl %eax, %ecx
cmovsl %edx, %ecx
andl $-0x4, %ecx
subl %ecx, %eax
movl %eax, %ecx
movq %rcx, -0x40(%rbp)
subl $0x3, %eax
ja 0xb8ae
movq -0x40(%rbp), %rax
leaq 0x7f3(%rip), %rcx       # 0xc024
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x0, -0x4(%rbp)
jmp 0xba40
cmpq $0xffff, -0x28(%rbp)    # imm = 0xFFFF
ja 0xb85c
movl $0x0, -0x4(%rbp)
jmp 0xba40
movq -0x20(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0xba40
cmpq $0xff, -0x28(%rbp)
ja 0xb88a
movl $0x0, -0x4(%rbp)
jmp 0xba40
movq -0x20(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0xba40
movl $0x0, -0x4(%rbp)
jmp 0xba40
jmp 0xb8b0
movq -0x20(%rbp), %rax
movl (%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0xb8d3
movq -0x20(%rbp), %rax
movl $0xfffffffe, (%rax)     # imm = 0xFFFFFFFE
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0xba40
movl -0x8(%rbp), %eax
decl %eax
movl %eax, -0x8(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, %edx
addl $0x3, %edx
testl %eax, %eax
movl %eax, %ecx
cmovsl %edx, %ecx
andl $-0x4, %ecx
subl %ecx, %eax
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
subl $0x3, %eax
ja 0xb9e9
movq -0x48(%rbp), %rax
leaq 0x728(%rip), %rcx       # 0xc034
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x20(%rbp), %rax
movl $0xfffffffd, (%rax)     # imm = 0xFFFFFFFD
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0xba40
cmpl $0x65a, -0x8(%rbp)      # imm = 0x65A
jb 0xb961
movl -0x8(%rbp), %eax
subl $0x65a, %eax            # imm = 0x65A
imull $0x65a, %eax, %eax      # imm = 0x65A
imull $0x65a, %eax, %eax      # imm = 0x65A
movl %eax, %eax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0xb9b7
cmpl $0x659, -0x8(%rbp)      # imm = 0x659
jae 0xb97d
cmpl $0x658, -0x8(%rbp)      # imm = 0x658
jne 0xb995
cmpq $0x14079f, -0x28(%rbp)  # imm = 0x14079F
jbe 0xb995
movq -0x20(%rbp), %rax
movl $0xfffffffa, (%rax)     # imm = 0xFFFFFFFA
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0xba40
imull $0x65a, -0x8(%rbp), %eax # imm = 0x65A
imull $0x65a, %eax, %eax      # imm = 0x65A
movl %eax, %eax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x2, %ecx
movl %ecx, (%rax)
jmp 0xb9e9
imull $0x65a, -0x8(%rbp), %eax # imm = 0x65A
movl %eax, %eax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0xb9e9
movl -0x8(%rbp), %eax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl $0x0, -0x30(%rbp)
cmpl $0x4, -0x30(%rbp)
jge 0xba39
movl -0x2c(%rbp), %eax
addl -0x30(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xba2c
movq -0x28(%rbp), %rax
movzbl %al, %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movq -0x38(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl -0x30(%rbp), %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x28(%rbp), %rax
shrq $0x8, %rax
movq %rax, -0x28(%rbp)
jmp 0xba2e
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xb9f0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw %cs:(%rax,%rax)