// File: /workspace/github_c_makefile_star2_O2/thegenemyers[P]DASCRUBBER/QV.c
// Function: Read_QVcoding
QVcoding *Read_QVcoding(FILE *input)
{ static QVcoding coding;

  // Read endian key, run chars, and short name common to all headers

  { uint16 half;
    int    len;

    if (fread(&half,sizeof(uint16),1,input) != 1)
      { EPRINTF(EPLACE,"Could not read flip byte (Read_QVcoding)\n");
        EXIT(NULL);
      }
    coding.flip = (half != 0x33cc);

    if (fread(&half,sizeof(uint16),1,input) != 1)
      { EPRINTF(EPLACE,"Could not read deletion char (Read_QVcoding)\n");
        EXIT(NULL);
      }
    if (coding.flip)
      Flip_Short(&half);
    coding.delChar = half;
    if (coding.delChar >= 256)
      coding.delChar = -1;

    if (fread(&half,sizeof(uint16),1,input) != 1)
      { EPRINTF(EPLACE,"Could not read substitution char (Read_QVcoding)\n");
        EXIT(NULL);
      }
    if (coding.flip)
      Flip_Short(&half);
    coding.subChar = half;
    if (coding.subChar >= 256)
      coding.subChar = -1;

    //  Read the short name common to all headers

    if (fread(&len,sizeof(int),1,input) != 1)
      { EPRINTF(EPLACE,"Could not read header name length (Read_QVcoding)\n");
        EXIT(NULL);
      }
    if (coding.flip)
      Flip_Long(&len);
    coding.prefix = (char *) Malloc(len+1,"Allocating header prefix");
    if (coding.prefix == NULL)
      EXIT(NULL);
    if (len > 0)
      { if (fread(coding.prefix,len,1,input) != 1)
          { EPRINTF(EPLACE,"Could not read header name (Read_QVcoding)\n");
            EXIT(NULL);
          }
      }
    coding.prefix[len] = '\0';
  }

  //  Setup endian handling

  Set_Endian(coding.flip);

  //  Read the Huffman schemes used to compress the data

  coding.delScheme  = NULL;
  coding.dRunScheme = NULL;
  coding.insScheme  = NULL;
  coding.mrgScheme  = NULL;
  coding.subScheme  = NULL;
  coding.sRunScheme = NULL;

  coding.delScheme = Read_Scheme(input);
  if (coding.delScheme == NULL)
    goto error;
  if (coding.delChar >= 0)
    { coding.dRunScheme = Read_Scheme(input);
      if (coding.dRunScheme == NULL)
        goto error;
    }
  coding.insScheme = Read_Scheme(input);
  if (coding.insScheme == NULL)
    goto error;
  coding.mrgScheme = Read_Scheme(input);
  if (coding.mrgScheme == NULL)
    goto error;
  coding.subScheme = Read_Scheme(input);
  if (coding.subScheme == NULL)
    goto error;
  if (coding.subChar >= 0)
    { coding.sRunScheme = Read_Scheme(input);
      if (coding.sRunScheme == NULL)
        goto error;
    }

  return (&coding);

error:
  if (coding.delScheme != NULL)
    free(coding.delScheme);
  if (coding.dRunScheme != NULL)
    free(coding.dRunScheme);
  if (coding.insScheme != NULL)
    free(coding.insScheme);
  if (coding.mrgScheme != NULL)
    free(coding.mrgScheme);
  if (coding.subScheme != NULL)
    free(coding.subScheme);
  if (coding.sRunScheme != NULL)
    free(coding.sRunScheme);
  EXIT(NULL);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0xa(%rsp), %rdi
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x790b
xorl %eax, %eax
leaq 0xa(%rsp), %rdi
cmpw $0x33cc, (%rdi)         # imm = 0x33CC
setne %al
movl %eax, 0xc2ea(%rip)      # 0x139d0
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x7920
cmpl $0x0, 0xc2cb(%rip)      # 0x139d0
je 0x770d
rolw $0x8, 0xa(%rsp)
leaq 0xa(%rsp), %rdi
movzwl (%rdi), %eax
cmpl $0x100, %eax            # imm = 0x100
pushq $-0x1
popq %rbp
cmovael %ebp, %eax
movl %eax, 0xc2a2(%rip)      # 0x139c8
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x7935
cmpl $0x0, 0xc28b(%rip)      # 0x139d0
je 0x774d
rolw $0x8, 0xa(%rsp)
movzwl 0xa(%rsp), %eax
cmpl $0x100, %eax            # imm = 0x100
cmovbl %eax, %ebp
movl %ebp, 0xc26c(%rip)      # 0x139cc
leaq 0xc(%rsp), %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x794a
cmpl $0x0, 0xc24c(%rip)      # 0x139d0
je 0x77a3
movd 0xc(%rsp), %xmm0
pxor %xmm1, %xmm1
punpcklbw %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3],xmm0[4],xmm1[4],xmm0[5],xmm1[5],xmm0[6],xmm1[6],xmm0[7],xmm1[7]
pshuflw $0x1b, %xmm0, %xmm0     # xmm0 = xmm0[3,2,1,0,4,5,6,7]
packuswb %xmm0, %xmm0
movd %xmm0, 0xc(%rsp)
movslq 0xc(%rsp), %r14
leaq 0x1(%r14), %rdi
leaq 0x2b97(%rip), %rsi      # 0xa34a
callq 0x1bad
movq %rax, 0xc219(%rip)      # 0x139d8
testq %rax, %rax
je 0x797b
testl %r14d, %r14d
jle 0x77ef
pushq $0x1
popq %rdx
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x795f
movq 0xc1e9(%rip), %rax      # 0x139d8
movb $0x0, (%rax,%r14)
movl 0xc1d6(%rip), %eax      # 0x139d0
movl %eax, 0xc1e0(%rip)      # 0x139e0
movb $0x1, 0xc1dd(%rip)      # 0x139e4
pxor %xmm0, %xmm0
movdqu %xmm0, 0xc185(%rip)     # 0x13998
movdqu %xmm0, 0xc18d(%rip)     # 0x139a8
movdqu %xmm0, 0xc195(%rip)     # 0x139b8
movq %rbx, %rdi
callq 0x799d
movq %rax, 0xc166(%rip)      # 0x13998
testq %rax, %rax
je 0x78c1
cmpl $0x0, 0xc186(%rip)      # 0x139c8
js 0x7858
movq %rbx, %rdi
callq 0x799d
movq %rax, 0xc165(%rip)      # 0x139b8
testq %rax, %rax
je 0x78c1
movq %rbx, %rdi
callq 0x799d
movq %rax, 0xc139(%rip)      # 0x139a0
testq %rax, %rax
je 0x78c1
movq %rbx, %rdi
callq 0x799d
movq %rax, 0xc12d(%rip)      # 0x139a8
testq %rax, %rax
je 0x78c1
movq %rbx, %rdi
callq 0x799d
movq %rax, 0xc121(%rip)      # 0x139b0
testq %rax, %rax
je 0x78c1
cmpl $0x0, 0xc131(%rip)      # 0x139cc
js 0x78b1
movq %rbx, %rdi
callq 0x799d
movq %rax, 0xc114(%rip)      # 0x139c0
testq %rax, %rax
je 0x78c1
leaq 0xc0e0(%rip), %rax      # 0x13998
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq 0xc0d0(%rip), %rdi      # 0x13998
callq 0x1030
movq 0xc0e4(%rip), %rdi      # 0x139b8
callq 0x1030
movq 0xc0c0(%rip), %rdi      # 0x139a0
callq 0x1030
movq 0xc0bc(%rip), %rdi      # 0x139a8
callq 0x1030
movq 0xc0b8(%rip), %rdi      # 0x139b0
callq 0x1030
movq 0xc0bc(%rip), %rdi      # 0x139c0
callq 0x1030
jmp 0x797b
movq 0x66e6(%rip), %rax      # 0xdff8
movq (%rax), %rcx
leaq 0x2971(%rip), %rdi      # 0xa28d
pushq $0x29
jmp 0x7972
movq 0x66d1(%rip), %rax      # 0xdff8
movq (%rax), %rcx
leaq 0x2986(%rip), %rdi      # 0xa2b7
pushq $0x2d
jmp 0x7972
movq 0x66bc(%rip), %rax      # 0xdff8
movq (%rax), %rcx
leaq 0x299f(%rip), %rdi      # 0xa2e5
pushq $0x31
jmp 0x7972
movq 0x66a7(%rip), %rax      # 0xdff8
movq (%rax), %rcx
leaq 0x29bc(%rip), %rdi      # 0xa317
pushq $0x32
jmp 0x7972
movq 0x6692(%rip), %rax      # 0xdff8
movq (%rax), %rcx
leaq 0x29f3(%rip), %rdi      # 0xa363
pushq $0x2b
popq %rsi
pushq $0x1
popq %rdx
callq 0x1280
pushq $0x1
popq %rdi
callq 0x1270