// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/match/firstcodes-tab.c
// Function: gt_firstcodes_remdups
GtUword gt_firstcodes_remdups(GtUword *allfirstcodes,
                                    GtFirstcodesspacelog *fcsl,
                                    GtFirstcodestab *fct,
                                    GtUword numofsequences,
                                    Gtmarksubstring *markprefix,
                                    Gtmarksubstring *marksuffix,
                                    GtArrayGtIndexwithcode **binsearchcache,
                                    unsigned int addbscache_depth,
                                    bool withdistbits,
                                    GtLogger *logger)
{
  if (numofsequences == 0)
  {
    fct->differentcodes = 0;
  } else
  {
    GtUword numofdifferentcodes = 1UL, storeidx, readidx, previouscode,
                  idx, maxdifference = 0, cachewidth, nextstorecache, lastocc,
                  storedvalue, diff, *distbits = NULL;
    unsigned int bitsformaxdifference, bitsforcount;

    previouscode = allfirstcodes[0];
    for (idx=1UL; idx < numofsequences; idx++)
    {
      GtUword currentcode = allfirstcodes[idx];
      if (previouscode != currentcode)
      {
        numofdifferentcodes++;
        if (maxdifference < currentcode - previouscode)
        {
          maxdifference = currentcode - previouscode;
        }
        previouscode = currentcode;
      }
    }
    bitsformaxdifference = gt_determinebitspervalue(maxdifference);
    fct->differencemask = (1UL << bitsformaxdifference) - 1UL;
    gt_assert(sizeof (GtUword) * CHAR_BIT >=
              (size_t) bitsformaxdifference);
    bitsforcount = (unsigned int)
                   sizeof (GtUword) * CHAR_BIT - bitsformaxdifference;
    fct->countmax = (1UL << bitsforcount) - 1UL;
    fct->shiftforcounts = bitsformaxdifference;
    gt_logger_log(logger,
                  "maximum difference of neighbored codes "GT_WU" (%u bits)",
                  maxdifference,bitsformaxdifference);
    /*
    printf("maxdifference="GT_WU",bitsformaxdifference=%u,bitsforcount=%u\n",
            maxdifference,bitsformaxdifference,bitsforcount);
    */
    gt_firstcodes_countocc_new(fcsl,fct,bitsforcount,numofsequences);
    gt_marksubstring_mark(markprefix,allfirstcodes[0]);
    gt_marksubstring_mark(marksuffix,allfirstcodes[0]);
    *binsearchcache
      = gt_firstcodes_binsearchcache_new(numofdifferentcodes,
                                         addbscache_depth,
                                         fcsl);
    cachewidth = (*binsearchcache) == NULL
                   ? 0
                   : gt_firstcodes_binsearchcache_width(*binsearchcache);
    nextstorecache = cachewidth;
    lastocc = 1UL; /* for first code */
    storedvalue = allfirstcodes[0];
    allfirstcodes[0] = 0;
    if (withdistbits)
    {
      distbits = gt_calloc((size_t) (64+1),sizeof (*distbits));
    }
    for (storeidx = 0, readidx = 1UL; readidx < numofsequences; readidx++)
    {
      GtUword readvalue = allfirstcodes[readidx];

      if (storedvalue != readvalue)
      {
        if ((*binsearchcache) != NULL && storeidx == nextstorecache)
        {
          gt_firstcodes_binsearchcache_set_index_code(*binsearchcache,
                                                      nextstorecache,
                                                      storedvalue);
          nextstorecache += cachewidth;
        }
        gt_firstcodes_countocc_set(fct,allfirstcodes,storeidx,lastocc);
        lastocc = 1UL;
        storeidx++;
        gt_assert(storedvalue < readvalue);
        diff = readvalue - storedvalue;
        if (distbits != NULL)
        {
          distbits[gt_determinebitspervalue(diff)]++;
        }
        allfirstcodes[storeidx] = diff;
        storedvalue = readvalue;
        gt_marksubstring_mark(markprefix,readvalue);
        gt_marksubstring_mark(marksuffix,readvalue);
      } else
      {
        lastocc++;
      }
    }
    if (withdistbits)
    {
      int bits;

      gt_assert(distbits != NULL);
      for (bits = 0; bits <= 64; bits++)
      {
        if (distbits[bits] > 0)
        {
          printf("%d bits: "GT_WU"\n",bits,distbits[bits]);
        }
      }
      gt_free(distbits);
    }
    gt_firstcodes_countocc_set(fct,allfirstcodes,storeidx,lastocc);
    gt_assert(numofdifferentcodes == (GtUword) (storeidx + 1));
    if (numofdifferentcodes < numofsequences)
    {
      /* reduce the memory requirement, as the duplicated elements are not
         needed */
      gt_firstcodes_countocc_resize(fcsl,fct,numofdifferentcodes);
    }
    fct->differentcodes = numofdifferentcodes;
  }
  gt_logger_log(logger,"number of different first codes="GT_WU" (%.2f%%) "
                       "in "GT_WU" sequences",
                fct->differentcodes,
                100.00 * (double) fct->differentcodes/numofsequences,
                numofsequences);
  return fct->differentcodes;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, 0x70(%rsp)
movq %r8, 0x68(%rsp)
movq %rcx, %r13
movq %rdx, %r15
movq 0xd8(%rsp), %r14
movq %rcx, %rdx
testq %rcx, %rcx
je 0x32145d
cmpq $0x1, %r13
jne 0x321072
xorl %ebx, %ebx
movq %r13, %r10
jmp 0x3210af
movq (%rdi), %rcx
movl $0x1, %r10d
xorl %ebx, %ebx
movl $0x1, %eax
movq (%rdi,%rax,8), %rdx
movq %rdx, %r8
subq %rcx, %r8
cmpq %r8, %rbx
cmovaq %rbx, %r8
xorl %r9d, %r9d
cmpq %rcx, %rdx
setne %r9b
cmovneq %r8, %rbx
addq %r9, %r10
incq %rax
movq %rdx, %rcx
cmpq %rax, %r13
jne 0x321082
movq %r10, 0x48(%rsp)
movq %rdi, 0x30(%rsp)
movq %rsi, 0x40(%rsp)
movq %rbx, %rdi
callq 0x10af48
movq $-0x1, %rsi
movl %eax, %ecx
shlq %cl, %rsi
movq $-0x1, %rdx
notq %rsi
movq %rsi, 0x58(%r15)
cmpl $0x41, %eax
jae 0x3214dc
movl $0x40, %ebp
movl %eax, %ecx
negl %ecx
shlq %cl, %rdx
subl %eax, %ebp
notq %rdx
movq %rdx, 0x60(%r15)
movl %eax, 0x68(%r15)
leaq 0xcad20(%rip), %rsi     # 0x3ebe29
movq %r14, %rdi
movq %rbx, %rdx
movl %eax, %ecx
xorl %eax, %eax
callq 0x10906e
cmpl $0x7, %ebp
ja 0x321169
leaq 0x1(%r13), %rbx
leaq 0xcace6(%rip), %r14     # 0x3ebe0e
movq %rbx, %rdi
movq %r14, %rsi
movl $0x2b, %edx
callq 0x1092b2
movq %rax, 0x38(%r15)
movq %rbx, (%rsp)
leaq 0xcafab(%rip), %r8      # 0x3ec0f2
movq 0x40(%rsp), %rbp
movq %rbp, %rdi
movl $0x2e, %esi
movq %r14, %rdx
movl $0x1, %ecx
movl $0x1, %r9d
callq 0x320ca8
jmp 0x321176
movq $0x0, 0x38(%r15)
movq 0x40(%rsp), %rbp
movups 0x1a7583(%rip), %xmm0   # 0x4c8700
movups %xmm0, 0x20(%rsp)
movups 0x1a7567(%rip), %xmm0   # 0x4c86f0
movups %xmm0, 0x10(%rsp)
movups 0x1a754b(%rip), %xmm0   # 0x4c86e0
movups %xmm0, (%rsp)
callq 0x1060b4
movq %rax, 0x40(%r15)
testq %rax, %rax
je 0x3214e1
movl 0xc8(%rsp), %r12d
movq 0xc0(%rsp), %rbx
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%r15)
movups %xmm0, 0x70(%r15)
movq $0x0, 0x80(%r15)
movq 0x30(%rsp), %r14
movq (%r14), %rsi
movq 0x68(%rsp), %rdi
callq 0x1c08af
movq (%r14), %rsi
movq 0x70(%rsp), %rdi
callq 0x1c08af
movq 0x48(%rsp), %rdi
movl %r12d, %esi
movq %rbp, %rdx
callq 0x31e2d0
movq %rax, (%rbx)
testq %rax, %rax
je 0x321219
movq %rax, %rdi
callq 0x31e40c
movq %rax, 0x50(%rsp)
jmp 0x321222
movq $0x0, 0x50(%rsp)
movq 0x30(%rsp), %rsi
movq (%rsi), %rbp
movq $0x0, (%rsi)
cmpb $0x0, 0xd0(%rsp)
je 0x321262
leaq 0xcabcc(%rip), %rdx     # 0x3ebe0e
movl $0x41, %edi
movl $0x8, %esi
movl $0x125, %ecx            # imm = 0x125
callq 0x1093ef
movq 0x30(%rsp), %rsi
movq %rax, 0x38(%rsp)
jmp 0x32126b
movq $0x0, 0x38(%rsp)
movq %r15, 0x58(%rsp)
cmpq $0x1, %r13
movq %r13, 0x78(%rsp)
jne 0x321288
movl $0x1, %ebx
xorl %r13d, %r13d
jmp 0x321375
cmpq $0x3, %r13
movl $0x2, %ecx
cmovaeq %r13, %rcx
movl $0x1, %r15d
xorl %r13d, %r13d
movl $0x1, %ebx
movq 0x50(%rsp), %rax
movq %rax, 0x60(%rsp)
movq %rcx, 0x80(%rsp)
movq (%rsi,%r15,8), %r14
cmpq %rbp, %r14
jne 0x3212c6
incq %rbx
jmp 0x321369
movq 0xc0(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x3212fa
movq 0x60(%rsp), %r12
cmpq %r12, %r13
jne 0x3212fa
movq %r12, %rsi
movq %rbp, %rdx
callq 0x31e411
movq 0x30(%rsp), %rsi
addq 0x50(%rsp), %r12
movq %r12, 0x60(%rsp)
movq 0x58(%rsp), %rdi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x3214f0
movq %r14, %rbx
subq %rbp, %rbx
jbe 0x3214d7
movq 0x38(%rsp), %rbp
testq %rbp, %rbp
je 0x32132f
movq %rbx, %rdi
callq 0x10af48
movl %eax, %eax
incq (%rbp,%rax,8)
movq 0x30(%rsp), %rbp
movq %rbx, 0x8(%rbp,%r13,8)
incq %r13
movq 0x68(%rsp), %rdi
movq %r14, %rsi
callq 0x1c08af
movq 0x70(%rsp), %rdi
movq %r14, %rsi
callq 0x1c08af
movq %rbp, %rsi
movl $0x1, %ebx
movq %r14, %rbp
movq 0x80(%rsp), %rcx
incq %r15
cmpq %r15, %rcx
jne 0x3212b5
cmpb $0x0, 0xd0(%rsp)
movq 0x58(%rsp), %r15
je 0x3213d4
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x3214eb
leaq 0xcaaee(%rip), %r14     # 0x3ebe87
xorl %ebp, %ebp
movq (%rdi,%rbp,8), %rdx
testq %rdx, %rdx
je 0x3213b5
movq %r14, %rdi
movl %ebp, %esi
xorl %eax, %eax
callq 0x17070
movq 0x38(%rsp), %rdi
incq %rbp
cmpq $0x41, %rbp
jne 0x32139b
leaq 0xcaa49(%rip), %rsi     # 0x3ebe0e
movl $0x152, %edx            # imm = 0x152
callq 0x109670
movq 0x30(%rsp), %rsi
movq %r15, %rdi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x3214f0
incq %r13
movq 0x48(%rsp), %rdx
cmpq %r13, %rdx
jne 0x3214e6
movq 0x78(%rsp), %r13
cmpq %r13, %rdx
movq 0xd8(%rsp), %r14
jae 0x32145d
movq 0x38(%r15), %rdi
testq %rdi, %rdi
je 0x32145d
leaq 0x1(%rdx), %rbx
movq %r14, %rbp
leaq 0xca9f2(%rip), %r14     # 0x3ebe0e
movq %rbx, %rsi
movq %r14, %rdx
movl $0x9b, %ecx
callq 0x1094e6
movq %rax, 0x38(%r15)
movq %rbx, (%rsp)
leaq 0xcacb7(%rip), %r8      # 0x3ec0f2
movq 0x40(%rsp), %rdi
movl $0x9e, %esi
movq %r14, %rdx
movq %rbp, %r14
xorl %ecx, %ecx
movl $0x1, %r9d
callq 0x320ca8
movq 0x48(%rsp), %rdx
movq %rdx, %xmm1
movq 0x2f476(%rip), %xmm2    # 0x3508e0
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x2f47a(%rip), %xmm3    # 0x3508f0
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x31362(%rip), %xmm0    # 0x3527f0
movq %rdx, (%r15)
movq %r13, %xmm1
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
subpd %xmm3, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
leaq 0xcaa10(%rip), %rsi     # 0x3ebec5
movq %r14, %rdi
movq %r13, %rcx
movb $0x1, %al
callq 0x10906e
movq (%r15), %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x9344d
callq 0x93414
callq 0x934f8
callq 0x93486
callq 0x934bf