// File: /workspace/github_c_makefile_star2_O1/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 0xd8cd(%rip), %rax      # 0x15940
cmpq $0x30d40, %rax          # imm = 0x30D40
jb 0x80d8
movslq 0xd8ca(%rip), %rcx      # 0x1594c
leaq 0xc0b7(%rip), %rdx      # 0x14140
movsd (%rdx,%rcx,8), %xmm0
movsd 0x408a(%rip), %xmm1     # 0xc120
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x408f(%rip), %xmm2     # 0xc130
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 0x406e(%rip), %xmm1     # 0xc140
ucomisd %xmm3, %xmm1
jbe 0x80e2
movl $0xffffffff, 0xd86a(%rip) # imm = 0xFFFFFFFF
testl %edi, %edi
je 0x8159
movq $-0x2, %rax
leaq 0xb84c(%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 0x80f4
movq $-0x4, %rax
leaq 0xb01f(%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 0x8125
movslq 0xd7e8(%rip), %rax      # 0x15948
leaq 0xa7d9(%rip), %rdi      # 0x12940
testq %rax, %rax
js 0x81a6
movq $0x0, (%rdi,%rax,8)
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x8472
testq %rax, %rax
je 0x81d3
movq %rax, %r14
cmpl $0x0, (%rax)
je 0x81d8
leaq 0xa7af(%rip), %rdi      # 0x12940
movq %r14, %rsi
callq 0x8472
movq %rax, %rbx
movq %r14, %rdi
callq 0x1030
jmp 0x81db
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x8472
testq %rax, %rax
je 0x81d3
movq %rax, %r14
cmpl $0x0, (%rax)
je 0x8226
leaq 0xa77d(%rip), %rdi      # 0x12940
movq %r14, %rsi
callq 0x8472
movq %rax, %rbx
xorl %r15d, %r15d
jmp 0x820b
xorl %r15d, %r15d
jmp 0x8218
movq %r14, %rbx
leaq 0xcf5e(%rip), %rdi      # 0x15140
xorl %r15d, %r15d
xorl %esi, %esi
callq 0x8472
testq %rax, %rax
je 0x8218
movq %rax, %r14
cmpl $0x0, (%rax)
je 0x822c
leaq 0xcf40(%rip), %rdi      # 0x15140
movq %r14, %rsi
callq 0x8472
movq %rax, %r15
movq %r14, %rdi
callq 0x1030
movq %r15, %r14
jmp 0x822c
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %r14d, %r14d
jmp 0x82b2
movq %r14, %rbx
xorl %r14d, %r14d
leaq 0xb70d(%rip), %rdi      # 0x13940
xorl %r15d, %r15d
xorl %esi, %esi
callq 0x8472
testq %rax, %rax
je 0x8266
movq %rax, %r12
cmpl $0x0, (%rax)
je 0x826b
leaq 0xb6ef(%rip), %rdi      # 0x13940
movq %r12, %rsi
callq 0x8472
movq %rax, %r15
movq %r12, %rdi
callq 0x1030
jmp 0x826e
xorl %r12d, %r12d
jmp 0x82af
movq %r12, %r15
leaq 0xaecb(%rip), %rdi      # 0x13140
xorl %r12d, %r12d
xorl %esi, %esi
callq 0x8472
testq %rax, %rax
je 0x82af
movq %rax, %r13
cmpl $0x0, (%rax)
je 0x8336
leaq 0xaea9(%rip), %rdi      # 0x13140
movq %r13, %rsi
callq 0x8472
movq %rax, %r12
movq %r13, %rdi
callq 0x1030
jmp 0x8339
xorl %r13d, %r13d
xorl %ebp, %ebp
xorl %ecx, %ecx
testb %cl, %cl
je 0x841a
xorl %ecx, %ecx
movl %ecx, 0xd71a(%rip)      # 0x159e0
movb $0x1, 0xd717(%rip)      # 0x159e4
movq %rbx, 0xd67c(%rip)      # 0x15950
leaq 0xd675(%rip), %rax      # 0x15950
movq %r15, 0xd676(%rip)      # 0x15958
movq %r12, 0xd677(%rip)      # 0x15960
movq %r13, 0xd678(%rip)      # 0x15968
movq %r14, 0xd679(%rip)      # 0x15970
movq %rbp, 0xd67a(%rip)      # 0x15978
movl 0xd644(%rip), %edx      # 0x15948
movl %edx, 0xd676(%rip)      # 0x15980
movl 0xd63c(%rip), %edx      # 0x1594c
movl %edx, 0xd66e(%rip)      # 0x15984
movq $0x0, 0xd66f(%rip) # 0x15990
movl %ecx, 0xd661(%rip)      # 0x15988
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %r12
movslq 0xd60c(%rip), %rax      # 0x1594c
leaq 0xbdf9(%rip), %rdi      # 0x14140
testq %rax, %rax
js 0x838b
movq $0x0, (%rdi,%rax,8)
xorl %r13d, %r13d
xorl %esi, %esi
callq 0x8472
testq %rax, %rax
je 0x82b2
movq %rax, %rbp
cmpl $0x0, (%rax)
je 0x83bd
leaq 0xbdca(%rip), %rdi      # 0x14140
movq %rbp, %rsi
callq 0x8472
movq %rax, %r13
movq %rbp, %rdi
callq 0x1030
jmp 0x83c0
xorl %r13d, %r13d
xorl %esi, %esi
callq 0x8472
testq %rax, %rax
je 0x82b2
cmpl $0x0, (%rax)
je 0x840e
leaq 0xbd96(%rip), %rdi      # 0x14140
movq %rax, (%rsp)
movq %rax, %rsi
callq 0x8472
movq %rax, %r13
xorl %ebp, %ebp
jmp 0x83f4
movq %rbp, %r13
leaq 0xc579(%rip), %rdi      # 0x14940
xorl %ebp, %ebp
xorl %esi, %esi
callq 0x8472
testq %rax, %rax
je 0x82b4
cmpl $0x0, (%rax)
je 0x8404
leaq 0xc55b(%rip), %rdi      # 0x14940
movq %rax, (%rsp)
movq %rax, %rsi
callq 0x8472
movq %rax, %rbp
movq (%rsp), %rdi
callq 0x1030
movb $0x1, %cl
jmp 0x82b6
movb $0x1, %cl
movq %rax, %rbp
jmp 0x82b6
movb $0x1, %cl
xorl %ebp, %ebp
movq %rax, %r13
jmp 0x82b6
testq %rbx, %rbx
je 0x8427
movq %rbx, %rdi
callq 0x1030
testq %r14, %r14
je 0x8434
movq %r14, %rdi
callq 0x1030
testq %r15, %r15
je 0x8441
movq %r15, %rdi
callq 0x1030
testq %r12, %r12
je 0x844e
movq %r12, %rdi
callq 0x1030
testq %r13, %r13
je 0x845b
movq %r13, %rdi
callq 0x1030
testq %rbp, %rbp
je 0x8468
movq %rbp, %rdi
callq 0x1030
movl $0x1, %edi
callq 0x1270