// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %rdx, 0x30(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, %r15
movzbl 0xc240(%rip), %eax      # 0x159e4
leaq 0x4(%rsp), %rsi
testq %rax, %rax
movq %rsp, %rdx
cmovneq %rdx, %rsi
movq %rsi, 0x10(%rsp)
leaq 0x2(%rax,%rax), %rsi
movq %rsi, 0x38(%rsp)
leaq (%rax,%rax,2), %rsi
addq $0x2, %rsi
movq %rsi, 0x28(%rsp)
xorl %esi, %esi
cmpl $0x2, (%rdi)
setne %sil
addl $0xff, %esi
movl %esi, 0xc(%rsp)
movq $0x0, (%rdx)
cmpl $0x0, 0xc1f0(%rip)      # 0x159e0
je 0x9958
testl %ecx, %ecx
jle 0x9a46
xorb $0x1, %al
movzbl %al, %r12d
shll $0x2, %r12d
leaq 0x3(%r12), %rax
movq %rax, 0x20(%rsp)
leaq 0x1(%r12), %r13
movq %r12, %r14
orq $0x2, %r14
movl %ecx, %eax
movq %rax, 0x40(%rsp)
xorl %ebx, %ebx
movl $0x10, %ecx
xorl %eax, %eax
movl %ecx, %ebp
movq (%rsp), %rdx
subl %eax, %ebp
jle 0x9896
movl %eax, %ecx
shlq %cl, %rdx
movq %rdx, (%rsp)
movl $0x4, %esi
movl $0x1, %edx
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x9a57
movb (%rsp,%r12), %al
movq 0x20(%rsp), %rdx
movb (%rsp,%rdx), %cl
movb %cl, (%rsp,%r12)
movb %al, (%rsp,%rdx)
movb (%rsp,%r13), %al
movb (%rsp,%r14), %cl
movb %cl, (%rsp,%r13)
movb %al, (%rsp,%r14)
movl %ebp, %ecx
shlq %cl, (%rsp)
movl $0x20, %eax
subl %ebp, %eax
jmp 0x989f
shlq %cl, %rdx
movq %rdx, (%rsp)
subl %ecx, %eax
movq 0x38(%rsp), %rcx
movzwl (%rsp,%rcx), %ecx
movslq 0x804(%r15,%rcx,4), %rdx
movl 0x404(%r15,%rdx,4), %ecx
cmpl 0xc(%rsp), %edx
jne 0x993d
movl %ecx, %ebp
movq (%rsp), %rdx
subl %eax, %ebp
jle 0x9926
movl %eax, %ecx
shlq %cl, %rdx
movq %rdx, (%rsp)
movl $0x4, %esi
movl $0x1, %edx
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x9a57
movb (%rsp,%r12), %al
movq 0x20(%rsp), %rdx
movb (%rsp,%rdx), %cl
movb %cl, (%rsp,%r12)
movb %al, (%rsp,%rdx)
movb (%rsp,%r13), %al
movb (%rsp,%r14), %cl
movb %cl, (%rsp,%r13)
movb %al, (%rsp,%r14)
movl %ebp, %ecx
shlq %cl, (%rsp)
movl $0x20, %eax
subl %ebp, %eax
jmp 0x992f
shlq %cl, %rdx
movq %rdx, (%rsp)
subl %ecx, %eax
movq 0x28(%rsp), %rcx
movzbl (%rsp,%rcx), %edx
movl $0x8, %ecx
movq 0x30(%rsp), %rsi
movb %dl, (%rsi,%rbx)
incq %rbx
cmpq %rbx, 0x40(%rsp)
jne 0x982e
jmp 0x9a46
testl %ecx, %ecx
jle 0x9a46
movl %ecx, %ebx
xorl %r14d, %r14d
movl $0x10, %ecx
xorl %eax, %eax
movl %ecx, %ebp
movq (%rsp), %rdx
subl %eax, %ebp
jle 0x99b1
movl %eax, %ecx
shlq %cl, %rdx
movq %rdx, (%rsp)
movl $0x4, %esi
movl $0x1, %edx
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x9a57
movl %ebp, %ecx
shlq %cl, (%rsp)
movl $0x20, %eax
subl %ebp, %eax
jmp 0x99ba
shlq %cl, %rdx
movq %rdx, (%rsp)
subl %ecx, %eax
movq 0x38(%rsp), %rcx
movzwl (%rsp,%rcx), %ecx
movslq 0x804(%r15,%rcx,4), %rdx
movl 0x404(%r15,%rdx,4), %ecx
cmpl 0xc(%rsp), %edx
jne 0x9a31
movl %ecx, %ebp
movq (%rsp), %rdx
subl %eax, %ebp
jle 0x9a1a
movl %eax, %ecx
shlq %cl, %rdx
movq %rdx, (%rsp)
movl $0x4, %esi
movl $0x1, %edx
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x9a57
movl %ebp, %ecx
shlq %cl, (%rsp)
movl $0x20, %eax
subl %ebp, %eax
jmp 0x9a23
shlq %cl, %rdx
movq %rdx, (%rsp)
subl %ecx, %eax
movq 0x28(%rsp), %rcx
movzbl (%rsp,%rcx), %edx
movl $0x8, %ecx
movq 0x30(%rsp), %rsi
movb %dl, (%rsi,%r14)
incq %r14
cmpq %r14, %rbx
jne 0x996c
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2237
movl $0x1, %eax
jmp 0x9a48