// File: /workspace/github_c_makefile_star2_O3/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 %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x2(%rsp), %rdi
movl $0x2, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x8eb7
xorl %eax, %eax
leaq 0x2(%rsp), %rdi
cmpw $0x33cc, (%rdi)         # imm = 0x33CC
setne %al
movl %eax, 0xcd78(%rip)      # 0x159d0
movl $0x2, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x8ebc
cmpl $0x0, 0xcd55(%rip)      # 0x159d0
je 0x8c83
rolw $0x8, 0x2(%rsp)
leaq 0x2(%rsp), %rdi
movzwl (%rdi), %eax
cmpl $0x100, %eax            # imm = 0x100
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmovbl %eax, %ecx
movl %ecx, 0xcd2a(%rip)      # 0x159c8
movl $0x2, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x8ec1
cmpl $0x0, 0xcd0f(%rip)      # 0x159d0
je 0x8cc9
rolw $0x8, 0x2(%rsp)
movzwl 0x2(%rsp), %eax
cmpl $0x100, %eax            # imm = 0x100
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmovbl %eax, %ecx
movl %ecx, 0xcceb(%rip)      # 0x159cc
leaq 0x4(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x8ec6
cmpl $0x0, 0xccc7(%rip)      # 0x159d0
je 0x8d28
movd 0x4(%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, 0x4(%rsp)
movslq 0x4(%rsp), %r14
leaq 0x1(%r14), %rdi
leaq 0x3682(%rip), %rsi      # 0xc3ba
callq 0x2af5
movq %rax, 0xcc94(%rip)      # 0x159d8
testq %rax, %rax
je 0x8ead
testl %r14d, %r14d
jle 0x8d76
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x8ecb
movq 0xcc62(%rip), %rax      # 0x159d8
movb $0x0, (%rax,%r14)
movl 0xcc4f(%rip), %eax      # 0x159d0
movl %eax, 0xcc59(%rip)      # 0x159e0
movb $0x1, 0xcc56(%rip)      # 0x159e4
pxor %xmm0, %xmm0
movdqu %xmm0, 0xcbfe(%rip)     # 0x15998
movdqu %xmm0, 0xcc06(%rip)     # 0x159a8
movdqu %xmm0, 0xcc0e(%rip)     # 0x159b8
movq %rbx, %rdi
callq 0x8ed0
movq %rax, 0xcbdf(%rip)      # 0x15998
testq %rax, %rax
je 0x8e58
cmpl $0x0, 0xcbff(%rip)      # 0x159c8
js 0x8ddf
movq %rbx, %rdi
callq 0x8ed0
movq %rax, 0xcbde(%rip)      # 0x159b8
testq %rax, %rax
je 0x8e47
movq %rbx, %rdi
callq 0x8ed0
movq %rax, 0xcbb2(%rip)      # 0x159a0
testq %rax, %rax
je 0x8e47
movq %rbx, %rdi
callq 0x8ed0
movq %rax, 0xcba6(%rip)      # 0x159a8
testq %rax, %rax
je 0x8e47
movq %rbx, %rdi
callq 0x8ed0
movq %rax, 0xcb9a(%rip)      # 0x159b0
testq %rax, %rax
je 0x8e47
cmpl $0x0, 0xcbaa(%rip)      # 0x159cc
js 0x8e38
movq %rbx, %rdi
callq 0x8ed0
movq %rax, 0xcb8d(%rip)      # 0x159c0
testq %rax, %rax
je 0x8e47
leaq 0xcb59(%rip), %rax      # 0x15998
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq 0xcb4a(%rip), %rdi      # 0x15998
testq %rdi, %rdi
je 0x8e58
callq 0x1030
movq 0xcb59(%rip), %rdi      # 0x159b8
testq %rdi, %rdi
je 0x8e69
callq 0x1030
movq 0xcb30(%rip), %rdi      # 0x159a0
testq %rdi, %rdi
je 0x8e7a
callq 0x1030
movq 0xcb27(%rip), %rdi      # 0x159a8
testq %rdi, %rdi
je 0x8e8b
callq 0x1030
movq 0xcb1e(%rip), %rdi      # 0x159b0
testq %rdi, %rdi
je 0x8e9c
callq 0x1030
movq 0xcb1d(%rip), %rdi      # 0x159c0
testq %rdi, %rdi
je 0x8ead
callq 0x1030
movl $0x1, %edi
callq 0x1270
callq 0x2075
callq 0x209a
callq 0x20bf
callq 0x20e4
callq 0x2109