// File: /workspace/github_c_makefile_star2_O2/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
subq $0x18, %rsp
movq 0xcaae(%rip), %rax      # 0x13940
cmpq $0x30d40, %rax          # imm = 0x30D40
jb 0x6ef7
movslq 0xcaab(%rip), %rcx      # 0x1394c
leaq 0xb298(%rip), %rdx      # 0x12140
movsd (%rdx,%rcx,8), %xmm0
movsd 0x326b(%rip), %xmm1     # 0xa120
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x3270(%rip), %xmm2     # 0xa130
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 0x324f(%rip), %xmm1     # 0xa140
ucomisd %xmm3, %xmm1
jbe 0x6efe
orl $-0x1, 0xca4e(%rip)     # 0x1394c
testl %edi, %edi
je 0x6f66
xorl %eax, %eax
leaq 0xaa35(%rip), %rcx      # 0x11940
cmpq $0x100, %rax            # imm = 0x100
jae 0x6f28
movq 0x8(%rcx,%rax,8), %rdx
addq %rdx, (%rcx,%rax,8)
andq $0x0, 0x8(%rcx,%rax,8)
addq $0x2, %rax
jmp 0x6f0b
xorl %eax, %eax
leaq 0xa20f(%rip), %rcx      # 0x11140
xorpd %xmm0, %xmm0
cmpq $0xff, %rax
ja 0x6f66
movq (%rcx,%rax,8), %rdx
addq 0x8(%rcx,%rax,8), %rdx
addq 0x10(%rcx,%rax,8), %rdx
addq 0x18(%rcx,%rax,8), %rdx
movq %rdx, (%rcx,%rax,8)
movupd %xmm0, 0x8(%rcx,%rax,8)
andq $0x0, 0x18(%rcx,%rax,8)
addq $0x4, %rax
jmp 0x6f35
movslq 0xc9db(%rip), %rax      # 0x13948
leaq 0x99cc(%rip), %rdi      # 0x10940
testq %rax, %rax
js 0x700f
andq $0x0, (%rdi,%rax,8)
movq $0x0, 0x8(%rsp)
xorl %esi, %esi
callq 0x72bc
movl $0x0, %r13d
movl $0x0, %ebx
movl $0x0, %r14d
movl $0x0, %ebp
testq %rax, %rax
je 0x728a
movq %rax, %r15
cmpl $0x0, (%rax)
je 0x6fd6
leaq 0x9980(%rip), %rdi      # 0x10940
movq %r15, %rsi
callq 0x72bc
movq %rax, %rbx
movq %r15, %rdi
callq 0x1030
movq %rbx, %r15
leaq 0xc163(%rip), %rdi      # 0x13140
xorl %r13d, %r13d
xorl %esi, %esi
callq 0x72bc
testq %rax, %rax
je 0x725e
movq %rax, %rbp
cmpl $0x0, (%rax)
je 0x7066
leaq 0xc141(%rip), %rdi      # 0x13140
movq %rbp, %rsi
callq 0x72bc
movq %rbp, %r12
movq %rax, %rbp
jmp 0x705e
movq $0x0, 0x8(%rsp)
xorl %esi, %esi
callq 0x72bc
movl $0x0, %r13d
movl $0x0, %ebx
movl $0x0, %r14d
movl $0x0, %ebp
testq %rax, %rax
je 0x728a
movq %rax, %r12
cmpl $0x0, (%rax)
je 0x723f
leaq 0x98ef(%rip), %rdi      # 0x10940
movq %r12, %rsi
callq 0x72bc
movq %rax, %r15
xorl %ebp, %ebp
movq %r12, %rdi
callq 0x1030
movq %r15, %r12
leaq 0xa8d0(%rip), %rdi      # 0x11940
xorl %r13d, %r13d
xorl %esi, %esi
callq 0x72bc
testq %rax, %rax
je 0x724d
movq %rax, %r15
cmpl $0x0, (%rax)
movq %r12, 0x8(%rsp)
je 0x70ad
leaq 0xa8a9(%rip), %rdi      # 0x11940
movq %r15, %rsi
callq 0x72bc
movq %rax, %rbx
movq %r15, %rdi
callq 0x1030
movq %rbx, %r15
leaq 0xa08c(%rip), %rdi      # 0x11140
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x72bc
testq %rax, %rax
je 0x7256
movq %rax, %r12
cmpl $0x0, (%rax)
je 0x70eb
leaq 0xa06b(%rip), %rdi      # 0x11140
movq %r12, %rsi
callq 0x72bc
movq %rax, %rbx
movq %r12, %rdi
callq 0x1030
movq %rbx, %r12
movslq 0xc85a(%rip), %rax      # 0x1394c
testq %rax, %rax
js 0x7176
movq %rbp, 0x10(%rsp)
leaq 0xb03d(%rip), %rdi      # 0x12140
andq $0x0, (%rdi,%rax,8)
xorl %r14d, %r14d
xorl %esi, %esi
callq 0x72bc
testq %rax, %rax
je 0x726c
movq %rax, %rbp
cmpl $0x0, (%rax)
je 0x7140
leaq 0xb016(%rip), %rdi      # 0x12140
movq %rbp, %rsi
callq 0x72bc
movq %rax, %rbx
movq %rbp, %rdi
callq 0x1030
movq %rbx, %rbp
leaq 0xb7f9(%rip), %rdi      # 0x12940
xorl %esi, %esi
callq 0x72bc
testq %rax, %rax
je 0x7274
movq %rax, %rbx
cmpl $0x0, (%rax)
je 0x71bd
leaq 0xb7da(%rip), %rdi      # 0x12940
movq %rbx, %rsi
callq 0x72bc
movq %rbx, %r13
movq %rax, %rbx
jmp 0x71b5
leaq 0xafc3(%rip), %rdi      # 0x12140
xorl %r14d, %r14d
xorl %esi, %esi
callq 0x72bc
testq %rax, %rax
je 0x7284
movq %rax, %r13
cmpl $0x0, (%rax)
je 0x7246
movq %rbp, 0x10(%rsp)
leaq 0xaf98(%rip), %rdi      # 0x12140
movq %r13, %rsi
callq 0x72bc
movq %rax, %rbp
xorl %ebx, %ebx
movq %r13, %rdi
callq 0x1030
movq %rbp, %r13
movq 0x10(%rsp), %rbp
andl $0x0, 0xc814(%rip)      # 0x139e0
movb $0x1, 0xc811(%rip)      # 0x139e4
movq 0x8(%rsp), %rax
movq %rax, 0xc771(%rip)      # 0x13950
leaq 0xc76a(%rip), %rax      # 0x13950
movq %r15, 0xc76b(%rip)      # 0x13958
movq %r12, 0xc76c(%rip)      # 0x13960
movq %r13, 0xc76d(%rip)      # 0x13968
movq %rbp, 0xc76e(%rip)      # 0x13970
movq %rbx, 0xc76f(%rip)      # 0x13978
movl 0xc739(%rip), %ecx      # 0x13948
movl %ecx, 0xc76b(%rip)      # 0x13980
movl 0xc731(%rip), %ecx      # 0x1394c
movl %ecx, 0xc763(%rip)      # 0x13984
andq $0x0, 0xc767(%rip)      # 0x13990
andl $0x0, 0xc758(%rip)      # 0x13988
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
jmp 0x7069
xorl %ebx, %ebx
jmp 0x71c5
movq %r12, 0x8(%rsp)
xorl %ebx, %ebx
jmp 0x7259
movq %r15, %r13
xorl %r14d, %r14d
jmp 0x728a
movq %r15, 0x8(%rsp)
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %ebp, %ebp
jmp 0x728a
movq %r15, %r13
movq %r12, %rbx
jmp 0x727d
movq %r15, %r13
movq %r12, %rbx
movq %rbp, %r14
movq 0x10(%rsp), %rbp
jmp 0x728a
movq %r15, %r13
movq %r12, %rbx
movq 0x8(%rsp), %rdi
callq 0x1030
movq %rbp, %rdi
callq 0x1030
movq %r13, %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
pushq $0x1
popq %rdi
callq 0x1270