// File: /workspace/github_c_makefile_star2_O3/thegenemyers[P]DASCRUBBER/QV.c
// Function: Create_QVcoding
QVcoding *Create_QVcoding(int lossy)
{ static QVcoding coding;

  HScheme *delScheme, *insScheme, *mrgScheme, *subScheme;
  HScheme *dRunScheme, *sRunScheme;

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

  //  Check whether using a subtitution run char is a win

  if (totChar < 200000 || subHist[subChar] < .5*totChar)
    subChar = -1;

  //  If lossy encryption is enabled then scale insertions and merge QVs.

  if (lossy)
    { int k;

      for (k = 0; k < 256; k += 2)
        { insHist[k] += insHist[k+1];
          insHist[k+1] = 0;
        }

      for (k = 0; k < 256; k += 4)
        { mrgHist[k] += mrgHist[k+1];
          mrgHist[k] += mrgHist[k+2];
          mrgHist[k] += mrgHist[k+3];
          mrgHist[k+1] = 0;
          mrgHist[k+2] = 0;
          mrgHist[k+3] = 0;
        }
    }

  //  Build a Huffman scheme for each stream entity from the histograms

#define SCHEME_MACRO(meme,hist,label,bits)	\
  scheme = Huffman( (hist), NULL);		\
  if (scheme == NULL)				\
    goto error;					\
  if (scheme->type)				\
    { (meme) = Huffman( (hist), scheme);	\
      free(scheme);				\
    }						\
  else						\
    (meme) = scheme;

#ifdef DEBUG

#define MAKE_SCHEME(meme,hist,label,bits)	\
  SCHEME_MACRO(meme,hist,label,bits)		\
  printf("\n%s\n", (label) );			\
  Print_Histogram( (hist));			\
  Print_Table( (meme), (hist), (bits));	

#else

#define MAKE_SCHEME(meme,hist,label,bits)	\
  SCHEME_MACRO(meme,hist,label,bits)

#endif

  { HScheme *scheme;

    if (delChar < 0)
      { MAKE_SCHEME(delScheme,delHist, "Hisotgram of Deletion QVs", 8);
        dRunScheme = NULL;
      }
    else
      { delHist[delChar] = 0;
        MAKE_SCHEME(delScheme,delHist, "Hisotgram of Deletion QVs less run char", 8);
        MAKE_SCHEME(dRunScheme,delRun, "Histogram of Deletion Runs QVs", 16);
#ifdef DEBUG
        printf("\nRun char is '%c'\n",delChar);
#endif
      }

#ifdef DEBUG
    { int    k;
      uint64 count;

      count = 0;
      for (k = 0; k < 256; k++)
        count += delHist[k];
      printf("\nDelTag will require %lld bytes\n",count/4);
    }
#endif

    MAKE_SCHEME(insScheme,insHist, "Hisotgram of Insertion QVs", 8);
    MAKE_SCHEME(mrgScheme,mrgHist, "Hisotgram of Merge QVs", 8);

    if (subChar < 0)
      { MAKE_SCHEME(subScheme,subHist, "Hisotgram of Subsitution QVs", 8);
        sRunScheme = NULL;
      }
    else
      { subHist[subChar] = 0;
        MAKE_SCHEME(subScheme,subHist, "Hisotgram of Subsitution QVs less run char", 8);
        MAKE_SCHEME(sRunScheme,subRun, "Histogram of Substitution Run QVs", 16);
#ifdef DEBUG
        printf("\nRun char is '%c'\n",subChar);
#endif
      }
  }

  //  Setup endian handling

  Set_Endian(0);

  coding.delScheme  = delScheme;
  coding.insScheme  = insScheme;
  coding.mrgScheme  = mrgScheme;
  coding.subScheme  = subScheme;
  coding.dRunScheme = dRunScheme;
  coding.sRunScheme = sRunScheme;
  coding.delChar    = delChar;
  coding.subChar    = subChar;
  coding.prefix     = NULL;
  coding.flip       = 0;

  return (&coding);

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0xd4fe(%rip), %rax      # 0x15940
cmpq $0x30d40, %rax          # imm = 0x30D40
jb 0x84a7
movslq 0xd4fb(%rip), %rcx      # 0x1594c
leaq 0xbce8(%rip), %rdx      # 0x14140
movsd (%rdx,%rcx,8), %xmm0
movsd 0x3d2b(%rip), %xmm1     # 0xc190
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x3d30(%rip), %xmm2     # 0xc1a0
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movq %rax, %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
subpd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x3d0f(%rip), %xmm1     # 0xc1b0
ucomisd %xmm3, %xmm1
jbe 0x84b1
movl $0xffffffff, 0xd49b(%rip) # imm = 0xFFFFFFFF
testl %edi, %edi
je 0x8528
movq $-0x2, %rax
leaq 0xb47d(%rip), %rcx      # 0x13940
movq 0x18(%rcx,%rax,8), %rdx
addq %rdx, 0x10(%rcx,%rax,8)
movq $0x0, 0x18(%rcx,%rax,8)
addq $0x2, %rax
cmpq $0xfe, %rax
jb 0x84c3
movq $-0x4, %rax
leaq 0xac50(%rip), %rcx      # 0x13140
xorpd %xmm0, %xmm0
movq 0x20(%rcx,%rax,8), %rdx
addq 0x28(%rcx,%rax,8), %rdx
addq 0x30(%rcx,%rax,8), %rdx
addq 0x38(%rcx,%rax,8), %rdx
movq %rdx, 0x20(%rcx,%rax,8)
movupd %xmm0, 0x28(%rcx,%rax,8)
movq $0x0, 0x38(%rcx,%rax,8)
addq $0x4, %rax
cmpq $0xfc, %rax
jb 0x84f4
movslq 0xd419(%rip), %rax      # 0x15948
leaq 0xa40a(%rip), %rdi      # 0x12940
testq %rax, %rax
js 0x85ae
movq $0x0, (%rdi,%rax,8)
xorl %esi, %esi
callq 0x883c
testq %rax, %rax
je 0x8832
movq %rax, %r13
cmpl $0x0, (%rax)
je 0x8578
leaq 0xa3de(%rip), %rdi      # 0x12940
movq %r13, %rsi
callq 0x883c
movq %rax, %rbx
movq %r13, %rdi
callq 0x1030
movq %rbx, %r13
leaq 0xcbc1(%rip), %rdi      # 0x15140
xorl %ebp, %ebp
xorl %esi, %esi
callq 0x883c
testq %rax, %rax
je 0x87e1
movq %rax, %r14
cmpl $0x0, (%rax)
je 0x85ee
leaq 0xcba0(%rip), %rdi      # 0x15140
movq %r14, %rsi
callq 0x883c
movq %rax, (%rsp)
jmp 0x85e4
xorl %esi, %esi
callq 0x883c
testq %rax, %rax
je 0x8832
movq %rax, %r14
cmpl $0x0, (%rax)
je 0x87ad
leaq 0xa36f(%rip), %rdi      # 0x12940
movq %r14, %rsi
callq 0x883c
movq %rax, %r13
movq $0x0, (%rsp)
movq %r14, %rdi
callq 0x1030
jmp 0x85f2
movq %r14, (%rsp)
movq %r13, %r14
leaq 0xb344(%rip), %rdi      # 0x13940
xorl %ebp, %ebp
xorl %esi, %esi
callq 0x883c
testq %rax, %rax
je 0x87c2
movq %rax, %r15
cmpl $0x0, (%rax)
je 0x8633
leaq 0xb323(%rip), %rdi      # 0x13940
movq %r15, %rsi
callq 0x883c
movq %rax, %rbx
movq %r15, %rdi
callq 0x1030
movq %rbx, %r15
leaq 0xab06(%rip), %rdi      # 0x13140
xorl %esi, %esi
callq 0x883c
testq %rax, %rax
je 0x87ca
movq %rax, %r12
cmpl $0x0, (%rax)
je 0x866f
leaq 0xaae7(%rip), %rdi      # 0x13140
movq %r12, %rsi
callq 0x883c
movq %rax, %rbx
movq %r12, %rdi
callq 0x1030
movq %rbx, %r12
movslq 0xd2d6(%rip), %rax      # 0x1594c
leaq 0xbac3(%rip), %rdi      # 0x14140
testq %rax, %rax
js 0x86f5
movq $0x0, (%rdi,%rax,8)
xorl %esi, %esi
callq 0x883c
testq %rax, %rax
je 0x87d7
movq %rax, %rbx
cmpl $0x0, (%rax)
je 0x86bf
leaq 0xba97(%rip), %rdi      # 0x14140
movq %rbx, %rsi
callq 0x883c
movq %rax, %r13
movq %rbx, %rdi
callq 0x1030
movq %r13, %rbx
leaq 0xc27a(%rip), %rdi      # 0x14940
xorl %esi, %esi
callq 0x883c
testq %rax, %rax
je 0x87d9
movq %rax, %r13
cmpl $0x0, (%rax)
je 0x872e
leaq 0xc25b(%rip), %rdi      # 0x14940
movq %r13, %rsi
callq 0x883c
movq %r13, %rbp
movq %rax, %r13
jmp 0x8726
xorl %esi, %esi
callq 0x883c
testq %rax, %rax
je 0x87d7
movq %rax, %rbp
cmpl $0x0, (%rax)
je 0x87ba
leaq 0xba28(%rip), %rdi      # 0x14140
movq %rbp, %rsi
callq 0x883c
movq %rax, %rbx
xorl %r13d, %r13d
movq %rbp, %rdi
callq 0x1030
movq %rbx, %rbp
xorl %ecx, %ecx
movl %ecx, 0xd2a7(%rip)      # 0x159e0
movb $0x1, 0xd2a4(%rip)      # 0x159e4
movq %r14, 0xd209(%rip)      # 0x15950
leaq 0xd202(%rip), %rax      # 0x15950
movq %r15, 0xd203(%rip)      # 0x15958
movq %r12, 0xd204(%rip)      # 0x15960
movq %rbp, 0xd205(%rip)      # 0x15968
movq (%rsp), %rdx
movq %rdx, 0xd202(%rip)      # 0x15970
movq %r13, 0xd203(%rip)      # 0x15978
movl 0xd1cd(%rip), %edx      # 0x15948
movl %edx, 0xd1ff(%rip)      # 0x15980
movl 0xd1c5(%rip), %edx      # 0x1594c
movl %edx, 0xd1f7(%rip)      # 0x15984
movq $0x0, 0xd1f8(%rip) # 0x15990
movl %ecx, 0xd1ea(%rip)      # 0x15988
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq $0x0, (%rsp)
jmp 0x85f5
xorl %r13d, %r13d
jmp 0x8731
movq %r14, %r13
xorl %r12d, %r12d
jmp 0x87d3
xorl %r12d, %r12d
movq %r14, %r13
movq %r15, %rbp
xorl %ebx, %ebx
jmp 0x87ee
xorl %ebx, %ebx
movq %r14, %r13
movq %r15, %rbp
jmp 0x87ee
xorl %r12d, %r12d
xorl %ebx, %ebx
movq $0x0, (%rsp)
testq %r13, %r13
je 0x87fb
movq %r13, %rdi
callq 0x1030
cmpq $0x0, (%rsp)
je 0x880b
movq (%rsp), %rdi
callq 0x1030
testq %rbp, %rbp
je 0x8818
movq %rbp, %rdi
callq 0x1030
testq %r12, %r12
je 0x8825
movq %r12, %rdi
callq 0x1030
testq %rbx, %rbx
je 0x8832
movq %rbx, %rdi
callq 0x1030
movl $0x1, %edi
callq 0x1270