// File: /workspace/github_c_makefile_star2_O2/thegenemyers[P]DASCRUBBER/QV.c
// Function: Decode
static int Decode(HScheme *scheme, FILE *in, char *read, int rlen)
{ int    *look, *lens;
  int     signal, ilen;
  uint64  icode;
  uint32 *ipart;
  uint16 *xpart;
  uint8  *cpart;
  int     j, n, c;

  if (LittleEndian)
    { ipart = ((uint32 *) (&icode));
      xpart = ((uint16 *) (&icode)) + 2;
      cpart = ((uint8  *) (&icode)) + 5;
    }
  else
    { ipart = ((uint32 *) (&icode)) + 1;
      xpart = ((uint16 *) (&icode)) + 1;
      cpart = ((uint8  *) (&icode)) + 2;
    }

  if (scheme->type == 2)
    signal  = 255;
  else
    signal  = 256;
  lens = scheme->codelens;
  look = scheme->lookup;

#define GET								\
  if (n > ilen)								\
    { icode <<= ilen;							\
      if (fread(ipart,sizeof(uint32),1,in) != 1)			\
        { EPRINTF(EPLACE,"Could not read more bits (Decode)\n");	\
          return (1);							\
        }								\
      ilen    = n-ilen;							\
      icode <<= ilen;							\
      ilen    = 32-ilen;						\
    }									\
  else									\
    { icode <<= n;							\
      ilen   -= n;							\
    }

#define GETFLIP								\
  if (n > ilen)								\
    { icode <<= ilen;							\
      if (fread(ipart,sizeof(uint32),1,in) != 1)			\
        { EPRINTF(EPLACE,"Could not read more bits (Decode)\n");	\
          return (1);							\
        }								\
      Flip_Long(ipart);							\
      ilen    = n-ilen;							\
      icode <<= ilen;							\
      ilen    = 32-ilen;						\
    }									\
  else									\
    { icode <<= n;							\
      ilen   -= n;							\
    }

  n     = 16;
  ilen  = 0;
  icode = 0;
  if (Flip)
    for (j = 0; j < rlen; j++)
      { GETFLIP
        c = look[*xpart];
        n = lens[c];
        if (c == signal)
          { GETFLIP
            c = *cpart;
            n = 8;
          }
        read[j] = (char) c;
      }
  else
    for (j = 0; j < rlen; j++)
      { GET
        c = look[*xpart];
        n = lens[c];
        if (c == signal)
          { GET
            c = *cpart;
            n = 8;
          }
        read[j] = (char) c;
      }

  return (0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, %ebx
movq %rdx, 0x18(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, %r12
movzbl 0xb3dc(%rip), %eax      # 0x139e4
leaq 0x4(%rsp), %rcx
testq %rax, %rax
movq %rsp, %r13
cmoveq %rcx, %r13
leaq 0x2(,%rax,2), %rcx
movq %rcx, 0x20(%rsp)
leaq (%rax,%rax,2), %rax
addq $0x2, %rax
movq %rax, 0x10(%rsp)
xorl %r14d, %r14d
cmpl $0x2, (%rdi)
setne %r14b
addl $0xff, %r14d
xorl %eax, %eax
testl %ebx, %ebx
cmovlel %eax, %ebx
cmpl $0x0, 0xb390(%rip)      # 0x139e0
je 0x8740
pushq $0x10
popq %rcx
xorl %edx, %edx
xorl %r15d, %r15d
cmpq %r15, %rbx
je 0x8818
movl %ecx, %ebp
subl %eax, %ebp
jle 0x86af
movl %eax, %ecx
shlq %cl, %rdx
movq %rdx, (%rsp)
movq %r13, %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq 0x8(%rsp), %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x8829
movq %r13, %rdi
callq 0x7983
movq (%rsp), %rdx
movl %ebp, %ecx
shlq %cl, %rdx
movq %rdx, (%rsp)
pushq $0x20
popq %rax
subl %ebp, %eax
jmp 0x86b4
shlq %cl, %rdx
subl %ecx, %eax
movq 0x20(%rsp), %rcx
movzwl (%rsp,%rcx), %ecx
movslq 0x804(%r12,%rcx,4), %rsi
movl 0x404(%r12,%rsi,4), %ecx
cmpl %r14d, %esi
jne 0x872f
movl %ecx, %ebp
subl %eax, %ebp
jle 0x871a
movl %eax, %ecx
shlq %cl, %rdx
movq %rdx, (%rsp)
movq %r13, %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq 0x8(%rsp), %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x8829
movq %r13, %rdi
callq 0x7983
movq (%rsp), %rdx
movl %ebp, %ecx
shlq %cl, %rdx
movq %rdx, (%rsp)
pushq $0x20
popq %rax
subl %ebp, %eax
jmp 0x8723
shlq %cl, %rdx
movq %rdx, (%rsp)
subl %ecx, %eax
movq 0x10(%rsp), %rcx
movzbl (%rsp,%rcx), %esi
pushq $0x8
popq %rcx
movq 0x18(%rsp), %rdi
movb %sil, (%rdi,%r15)
incq %r15
jmp 0x865e
pushq $0x10
popq %rcx
xorl %edx, %edx
xorl %r15d, %r15d
xorl %eax, %eax
cmpq %r15, %rbx
je 0x8818
movl %ecx, %ebp
subl %eax, %ebp
jle 0x8793
movl %eax, %ecx
shlq %cl, %rdx
movq %rdx, (%rsp)
movq %r13, %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq 0x8(%rsp), %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x8829
movq (%rsp), %rdx
movl %ebp, %ecx
shlq %cl, %rdx
movq %rdx, (%rsp)
pushq $0x20
popq %rax
subl %ebp, %eax
jmp 0x8798
shlq %cl, %rdx
subl %ecx, %eax
movq 0x20(%rsp), %rcx
movzwl (%rsp,%rcx), %ecx
movslq 0x804(%r12,%rcx,4), %rsi
movl 0x404(%r12,%rsi,4), %ecx
cmpl %r14d, %esi
jne 0x8807
movl %ecx, %ebp
subl %eax, %ebp
jle 0x87f2
movl %eax, %ecx
shlq %cl, %rdx
movq %rdx, (%rsp)
movq %r13, %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq 0x8(%rsp), %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x8829
movq (%rsp), %rdx
movl %ebp, %ecx
shlq %cl, %rdx
movq %rdx, (%rsp)
pushq $0x20
popq %rax
subl %ebp, %eax
jmp 0x87fb
shlq %cl, %rdx
movq %rdx, (%rsp)
subl %ecx, %eax
movq 0x10(%rsp), %rcx
movzbl (%rsp,%rcx), %esi
pushq $0x8
popq %rcx
movq 0x18(%rsp), %rdi
movb %sil, (%rdi,%r15)
incq %r15
jmp 0x874a
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x57c8(%rip), %rax      # 0xdff8
movq (%rax), %rcx
leaq 0x1c4a(%rip), %rdi      # 0xa484
pushq $0x22
popq %rsi
pushq $0x1
popq %rdx
callq 0x1280
pushq $0x1
popq %rax
jmp 0x881a