// File: /workspace/github_c_makefile_star2_O3/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 0xbdf4(%rip), %eax      # 0x159e4
leaq 0x4(%rsp), %rdx
testq %rax, %rax
movq %rsp, %rsi
cmoveq %rdx, %rsi
movq %rsi, 0x10(%rsp)
leaq 0x2(,%rax,2), %rdx
movq %rdx, 0x38(%rsp)
leaq (%rax,%rax,2), %rdx
addq $0x2, %rdx
movq %rdx, 0x28(%rsp)
xorl %edx, %edx
cmpl $0x2, (%rdi)
setne %dl
addl $0xff, %edx
movl %edx, 0xc(%rsp)
cmpl $0x0, 0xbda9(%rip)      # 0x159e0
je 0x9da8
testl %ecx, %ecx
jle 0x9e9a
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 %edx, %edx
movl $0x10, %ecx
xorl %ebx, %ebx
xorl %eax, %eax
movl %ecx, %ebp
subl %eax, %ebp
jle 0x9ce2
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 0x9eab
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)
movq (%rsp), %rdx
movl %ebp, %ecx
shlq %cl, %rdx
movq %rdx, (%rsp)
movl $0x20, %eax
subl %ebp, %eax
jmp 0x9ce7
shlq %cl, %rdx
subl %ecx, %eax
movq 0x38(%rsp), %rcx
movzwl (%rsp,%rcx), %ecx
movslq 0x804(%r15,%rcx,4), %rsi
movl 0x404(%r15,%rsi,4), %ecx
cmpl 0xc(%rsp), %esi
jne 0x9d8c
movl %ecx, %ebp
subl %eax, %ebp
jle 0x9d75
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 0x9eab
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)
movq (%rsp), %rdx
movl %ebp, %ecx
shlq %cl, %rdx
movq %rdx, (%rsp)
movl $0x20, %eax
subl %ebp, %eax
jmp 0x9d7e
shlq %cl, %rdx
movq %rdx, (%rsp)
subl %ecx, %eax
movq 0x28(%rsp), %rcx
movzbl (%rsp,%rcx), %esi
movl $0x8, %ecx
movq 0x30(%rsp), %rdi
movb %sil, (%rdi,%rbx)
incq %rbx
cmpq %rbx, 0x40(%rsp)
jne 0x9c77
jmp 0x9e9a
testl %ecx, %ecx
jle 0x9e9a
movl %ecx, %ebx
xorl %edx, %edx
movl $0x10, %ecx
xorl %r14d, %r14d
xorl %eax, %eax
movl %ecx, %ebp
subl %eax, %ebp
jle 0x9e06
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 0x9eab
movq (%rsp), %rdx
movl %ebp, %ecx
shlq %cl, %rdx
movq %rdx, (%rsp)
movl $0x20, %eax
subl %ebp, %eax
jmp 0x9e0b
shlq %cl, %rdx
subl %ecx, %eax
movq 0x38(%rsp), %rcx
movzwl (%rsp,%rcx), %ecx
movslq 0x804(%r15,%rcx,4), %rsi
movl 0x404(%r15,%rsi,4), %ecx
cmpl 0xc(%rsp), %esi
jne 0x9e85
movl %ecx, %ebp
subl %eax, %ebp
jle 0x9e6e
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 0x9eab
movq (%rsp), %rdx
movl %ebp, %ecx
shlq %cl, %rdx
movq %rdx, (%rsp)
movl $0x20, %eax
subl %ebp, %eax
jmp 0x9e77
shlq %cl, %rdx
movq %rdx, (%rsp)
subl %ecx, %eax
movq 0x28(%rsp), %rcx
movzbl (%rsp,%rcx), %esi
movl $0x8, %ecx
movq 0x30(%rsp), %rdi
movb %sil, (%rdi,%r14)
incq %r14
cmpq %r14, %rbx
jne 0x9dbe
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x21bf
movl $0x1, %eax
jmp 0x9e9c