// File: /workspace/github_c_makefile_star2_O2/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 $0x78, %rsp
movq %r9, 0x70(%rsp)
movq %r8, 0x68(%rsp)
movq %rdx, %r13
movq 0xc8(%rsp), %rbp
testq %rcx, %rcx
je 0x2b6672
movq %rsi, 0x48(%rsp)
movl 0xb8(%rsp), %r15d
movq (%rdi), %r8
pushq $0x1
popq %rax
xorl %ebx, %ebx
movq %rax, %r9
cmpq %rax, %rcx
je 0x2b65c3
movq (%rdi,%rax,8), %rdx
movq %rdx, %rsi
subq %r8, %rsi
cmpq %rsi, %rbx
cmovaq %rbx, %rsi
xorl %r10d, %r10d
cmpq %r8, %rdx
cmovneq %rsi, %rbx
setne %r10b
addq %r10, %r9
incq %rax
movq %rdx, %r8
jmp 0x2b6594
movq %rdi, 0x38(%rsp)
movq %r9, 0x50(%rsp)
movq %rcx, 0x30(%rsp)
movq %rbx, %rdi
callq 0x9580f
movl %eax, %r14d
pushq $-0x1
popq %rax
movq %rax, %rdx
movl %r14d, %ecx
shlq %cl, %rdx
notq %rdx
movq %rdx, 0x58(%r13)
cmpl $0x41, %r14d
jae 0x2b69ce
movl %r14d, %ecx
negb %cl
shlq %cl, %rax
notq %rax
movq %rax, 0x60(%r13)
movl %r14d, 0x68(%r13)
leaq 0xcc4d1(%rip), %rsi     # 0x382ae5
movq %rbp, %rdi
movq %rbx, %rdx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x92e71
cmpl $0x39, %r14d
jb 0x2b6679
movq 0x30(%rsp), %rax
leaq 0x1(%rax), %rbx
leaq 0xcc490(%rip), %r14     # 0x382aca
pushq $0x2b
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x93160
movq %rax, 0x38(%r13)
movq %rbx, (%rsp)
leaq 0xcc757(%rip), %r8      # 0x382dae
pushq $0x2e
popq %rsi
pushq $0x1
popq %rcx
movq 0x48(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rdx
movl %ecx, %r9d
callq 0x2b613a
jmp 0x2b6683
xorl %edx, %edx
jmp 0x2b6920
andq $0x0, 0x38(%r13)
movq 0x48(%rsp), %rbx
movups 0x186026(%rip), %xmm0   # 0x43c6b0
movups %xmm0, 0x20(%rsp)
movups 0x18600a(%rip), %xmm0   # 0x43c6a0
movups %xmm0, 0x10(%rsp)
movups 0x185fee(%rip), %xmm0   # 0x43c690
movups %xmm0, (%rsp)
callq 0x8fac7
movq %rax, 0x40(%r13)
testq %rax, %rax
je 0x2b69fc
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%r13)
movups %xmm0, 0x70(%r13)
andq $0x0, 0x80(%r13)
movq 0x38(%rsp), %r14
movq (%r14), %rsi
movq 0x68(%rsp), %rdi
callq 0x166866
movq (%r14), %rsi
movq 0x70(%rsp), %rdi
callq 0x166866
movq 0x50(%rsp), %rdi
movl %r15d, %esi
movq %rbx, %rdx
callq 0x2b3500
movq 0xb0(%rsp), %rcx
movq %rax, (%rcx)
testq %rax, %rax
movq %r13, 0x60(%rsp)
je 0x2b6720
movq %rax, %rdi
callq 0x2b360b
movq %rax, 0x58(%rsp)
jmp 0x2b6729
movq $0x0, 0x58(%rsp)
movq 0x38(%rsp), %rsi
movq (%rsi), %r13
andq $0x0, (%rsi)
cmpb $0x0, 0xc0(%rsp)
je 0x2b6762
leaq 0xcc384(%rip), %rdx     # 0x382aca
pushq $0x41
popq %rdi
pushq $0x8
popq %rsi
movl $0x125, %ecx            # imm = 0x125
callq 0x9334a
movq 0x38(%rsp), %rsi
movq %rax, 0x40(%rsp)
jmp 0x2b676b
movq $0x0, 0x40(%rsp)
movq 0x30(%rsp), %rax
pushq $0x1
popq %rbp
xorl %r15d, %r15d
movq 0x58(%rsp), %r14
movq %rbp, %rbx
cmpq %rax, %rbp
jae 0x2b6834
movq (%rsi,%rbp,8), %r12
cmpq %r13, %r12
jne 0x2b6798
incq %rbx
jmp 0x2b682c
movq 0xb0(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x2b67c2
cmpq %r14, %r15
jne 0x2b67c2
movq %r14, %rsi
movq %r13, %rdx
callq 0x2b3610
movq 0x38(%rsp), %rsi
addq 0x58(%rsp), %r14
movq 0x60(%rsp), %rdi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2b6a8a
movq %r12, %rbx
subq %r13, %rbx
jbe 0x2b6996
movq 0x40(%rsp), %r13
testq %r13, %r13
je 0x2b67f7
movq %rbx, %rdi
callq 0x9580f
movl %eax, %eax
incq (%r13,%rax,8)
movq 0x38(%rsp), %r13
movq %rbx, 0x8(%r13,%r15,8)
incq %r15
movq 0x68(%rsp), %rdi
movq %r12, %rsi
callq 0x166866
movq 0x70(%rsp), %rdi
movq %r12, %rsi
callq 0x166866
movq %r13, %rsi
pushq $0x1
popq %rbx
movq %r12, %r13
movq 0x30(%rsp), %rax
incq %rbp
jmp 0x2b677e
cmpb $0x0, 0xc0(%rsp)
movq 0x60(%rsp), %r13
movq 0xc8(%rsp), %rbp
je 0x2b68a2
cmpq $0x0, 0x40(%rsp)
je 0x2b6a59
leaq 0xcc2e5(%rip), %r14     # 0x382b43
xorl %r12d, %r12d
cmpq $0x41, %r12
je 0x2b6887
movq 0x40(%rsp), %rax
movq (%rax,%r12,8), %rdx
testq %rdx, %rdx
je 0x2b6882
movq %r14, %rdi
movl %r12d, %esi
xorl %eax, %eax
callq 0x17070
incq %r12
jmp 0x2b6861
leaq 0xcc23c(%rip), %rsi     # 0x382aca
movq 0x40(%rsp), %rdi
movl $0x152, %edx            # imm = 0x152
callq 0x936f9
movq 0x38(%rsp), %rsi
movq %r13, %rdi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2b6a8a
incq %r15
movq 0x50(%rsp), %rdx
cmpq %r15, %rdx
jne 0x2b6a28
movq 0x30(%rsp), %rcx
cmpq %rcx, %rdx
jae 0x2b6920
movq 0x38(%r13), %rdi
testq %rdi, %rdi
je 0x2b6920
leaq 0x1(%rdx), %rbx
leaq 0xcc1eb(%rip), %r14     # 0x382aca
movq %rbx, %rsi
movq %r14, %rdx
movl $0x9b, %ecx
callq 0x93472
movq %rax, 0x38(%r13)
movq %rbx, (%rsp)
leaq 0xcc4b0(%rip), %r8      # 0x382dae
pushq $0x1
popq %r9
movq 0x48(%rsp), %rdi
movl $0x9e, %esi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x2b613a
movq 0x50(%rsp), %rdx
movq 0x30(%rsp), %rcx
movq %rdx, %xmm1
movq 0x30fb3(%rip), %xmm2    # 0x2e78e0
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x30fb7(%rip), %xmm3    # 0x2e78f0
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x32e8f(%rip), %xmm0    # 0x2e97e0
movq %rdx, (%r13)
movq %rcx, %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 0xcc208(%rip), %rsi     # 0x382b81
movq %rbp, %rdi
movb $0x1, %al
callq 0x92e71
movq (%r13), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1815cb(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2e66c(%rip), %rsi     # 0x2e5013
leaq 0xcc16c(%rip), %rdx     # 0x382b1a
leaq 0xcc0ff(%rip), %rcx     # 0x382ab4
leaq 0xcc10e(%rip), %r8      # 0x382aca
movl $0x137, %r9d            # imm = 0x137
xorl %eax, %eax
callq 0x17a50
callq 0x17390
movq 0x181593(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2e634(%rip), %rsi     # 0x2e5013
leaq 0xcc091(%rip), %rdx     # 0x382a77
leaq 0xcc0c7(%rip), %rcx     # 0x382ab4
leaq 0xcc0d6(%rip), %r8      # 0x382aca
movl $0x109, %r9d            # imm = 0x109
jmp 0x2b69c2
movq 0x181565(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2e606(%rip), %rsi     # 0x2e5013
leaq 0xcc4a1(%rip), %rdx     # 0x382eb5
leaq 0xcc4bb(%rip), %rcx     # 0x382ed6
leaq 0xcc0a8(%rip), %r8      # 0x382aca
pushq $0x34
popq %r9
jmp 0x2b69c2
movq 0x181539(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2e5da(%rip), %rsi     # 0x2e5013
leaq 0xcc111(%rip), %rdx     # 0x382b51
leaq 0xcc06d(%rip), %rcx     # 0x382ab4
leaq 0xcc07c(%rip), %r8      # 0x382aca
movl $0x155, %r9d            # imm = 0x155
jmp 0x2b69c2
movq 0x181508(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2e5a9(%rip), %rsi     # 0x2e5013
leaq 0xcc0c1(%rip), %rdx     # 0x382b32
leaq 0xcc03c(%rip), %rcx     # 0x382ab4
leaq 0xcc04b(%rip), %r8      # 0x382aca
movl $0x14a, %r9d            # imm = 0x14A
jmp 0x2b69c2