// File: /workspace/github_c_makefile_star2_O3/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, %r15
movq %rsi, 0x48(%rsp)
movq 0xc8(%rsp), %r13
testq %rcx, %rcx
je 0x316d01
cmpq $0x1, %rcx
jne 0x316d09
movl $0x1, %r12d
xorl %ebx, %ebx
jmp 0x316d46
xorl %r12d, %r12d
jmp 0x3170c4
movq (%rdi), %r8
movl $0x1, %r12d
xorl %ebx, %ebx
movl $0x1, %eax
movq (%rdi,%rax,8), %rdx
movq %rdx, %rsi
subq %r8, %rsi
cmpq %rsi, %rbx
cmovaq %rbx, %rsi
xorl %r9d, %r9d
cmpq %r8, %rdx
setne %r9b
cmovneq %rsi, %rbx
addq %r9, %r12
incq %rax
movq %rdx, %r8
cmpq %rax, %rcx
jne 0x316d19
movq %rdi, 0x38(%rsp)
movq %rcx, 0x30(%rsp)
movq %rbx, %rdi
callq 0x105e91
movl %eax, %ebp
movq $-0x1, %rdx
movl %ebp, %ecx
shlq %cl, %rdx
movq $-0x1, %rax
notq %rdx
movq %rdx, 0x58(%r15)
cmpl $0x41, %ebp
jae 0x317140
movl %ebp, %ecx
negb %cl
shlq %cl, %rax
notq %rax
movq %rax, 0x60(%r15)
movl %ebp, 0x68(%r15)
leaq 0xcb96f(%rip), %rsi     # 0x3e2705
movq %r13, %rdi
movq %rbx, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x103fe1
cmpl $0x39, %ebp
jb 0x316df8
movq 0x30(%rsp), %rax
leaq 0x1(%rax), %rbx
leaq 0xcb930(%rip), %r14     # 0x3e26ea
movq %rbx, %rdi
movq %r14, %rsi
movl $0x2b, %edx
callq 0x104226
movq %rax, 0x38(%r15)
movq %rbx, (%rsp)
leaq 0xcbbf5(%rip), %r8      # 0x3e29ce
movq 0x48(%rsp), %rdi
movl $0x2e, %esi
movq %r14, %rdx
movl $0x1, %ecx
movl $0x1, %r9d
callq 0x316945
jmp 0x316e00
movq $0x0, 0x38(%r15)
movups 0x1a68f9(%rip), %xmm0   # 0x4bd700
movups %xmm0, 0x20(%rsp)
movups 0x1a68dd(%rip), %xmm0   # 0x4bd6f0
movups %xmm0, 0x10(%rsp)
movups 0x1a68c1(%rip), %xmm0   # 0x4bd6e0
movups %xmm0, (%rsp)
callq 0x101194
movq %rax, 0x40(%r15)
testq %rax, %rax
je 0x317145
movl 0xb8(%rsp), %ebx
movq 0xb0(%rsp), %r13
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%r15)
movups %xmm0, 0x70(%r15)
movq $0x0, 0x80(%r15)
movq 0x38(%rsp), %r14
movq (%r14), %rsi
movq 0x68(%rsp), %rdi
callq 0x1b7dc9
movq (%r14), %rsi
movq 0x70(%rsp), %rdi
callq 0x1b7dc9
movq %r12, %rdi
movl %ebx, %esi
movq 0x48(%rsp), %rdx
callq 0x313f98
movq %rax, (%r13)
testq %rax, %rax
je 0x316ea2
movq %rax, %rdi
callq 0x3140b4
movq %rax, 0x50(%rsp)
jmp 0x316eab
movq $0x0, 0x50(%rsp)
movq 0x38(%rsp), %rsi
movq (%rsi), %rbp
movq $0x0, (%rsi)
cmpb $0x0, 0xc0(%rsp)
je 0x316eeb
leaq 0xcb81f(%rip), %rdx     # 0x3e26ea
movl $0x41, %edi
movl $0x8, %esi
movl $0x125, %ecx            # imm = 0x125
callq 0x10436a
movq 0x38(%rsp), %rsi
movq %rax, 0x40(%rsp)
jmp 0x316ef4
movq $0x0, 0x40(%rsp)
movq 0x30(%rsp), %rax
movq %r15, 0x58(%rsp)
cmpq $0x1, %rax
jne 0x316f11
movl $0x1, %ebx
xorl %r13d, %r13d
jmp 0x316fe6
movl $0x1, %r15d
xorl %r13d, %r13d
movl $0x1, %ebx
movq 0x50(%rsp), %rcx
movq %rcx, 0x60(%rsp)
movq (%rsi,%r15,8), %r14
cmpq %rbp, %r14
jne 0x316f3a
incq %rbx
jmp 0x316fda
movq 0xb0(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x316f6e
cmpq 0x60(%rsp), %r13
jne 0x316f6e
movq %r13, %rsi
movq %rbp, %rdx
callq 0x3140b9
movq 0x38(%rsp), %rsi
movq 0x50(%rsp), %rax
addq %r13, %rax
movq %rax, 0x60(%rsp)
movq 0x58(%rsp), %rdi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x317154
movq %r14, %rbx
subq %rbp, %rbx
jbe 0x31713b
movq 0x40(%rsp), %rbp
testq %rbp, %rbp
je 0x316fa3
movq %rbx, %rdi
callq 0x105e91
movl %eax, %eax
incq (%rbp,%rax,8)
movq 0x38(%rsp), %rbp
movq %rbx, 0x8(%rbp,%r13,8)
incq %r13
movq 0x68(%rsp), %rdi
movq %r14, %rsi
callq 0x1b7dc9
movq 0x70(%rsp), %rdi
movq %r14, %rsi
callq 0x1b7dc9
movq %rbp, %rsi
movl $0x1, %ebx
movq %r14, %rbp
movq 0x30(%rsp), %rax
incq %r15
cmpq %r15, %rax
jne 0x316f29
cmpb $0x0, 0xc0(%rsp)
movq 0x58(%rsp), %r15
je 0x317045
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x31714f
leaq 0xcb759(%rip), %r14     # 0x3e2763
xorl %ebp, %ebp
movq (%rdi,%rbp,8), %rdx
testq %rdx, %rdx
je 0x317026
movq %r14, %rdi
movl %ebp, %esi
xorl %eax, %eax
callq 0x17070
movq 0x40(%rsp), %rdi
incq %rbp
cmpq $0x41, %rbp
jne 0x31700c
leaq 0xcb6b4(%rip), %rsi     # 0x3e26ea
movl $0x152, %edx            # imm = 0x152
callq 0x1045eb
movq 0x38(%rsp), %rsi
movq %r15, %rdi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x317154
incq %r13
cmpq %r13, %r12
jne 0x31714a
movq 0x30(%rsp), %rcx
cmpq %rcx, %r12
movq 0xc8(%rsp), %r13
jae 0x3170c4
movq 0x38(%r15), %rdi
testq %rdi, %rdi
je 0x3170c4
leaq 0x1(%r12), %rbx
leaq 0xcb664(%rip), %r14     # 0x3e26ea
movq %rbx, %rsi
movq %r14, %rdx
movl $0x9b, %ecx
callq 0x104461
movq %rax, 0x38(%r15)
movq %rbx, (%rsp)
leaq 0xcb929(%rip), %r8      # 0x3e29ce
movq 0x48(%rsp), %rdi
movl $0x9e, %esi
movq %r14, %rdx
xorl %ecx, %ecx
movl $0x1, %r9d
callq 0x316945
movq 0x30(%rsp), %rcx
movq %r12, %xmm1
movq 0x3080f(%rip), %xmm2    # 0x3478e0
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x30813(%rip), %xmm3    # 0x3478f0
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x326eb(%rip), %xmm0    # 0x3497e0
movq %r12, (%r15)
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 0xcb685(%rip), %rsi     # 0x3e27a1
movq %r13, %rdi
movq %r12, %rdx
movb $0x1, %al
callq 0x103fe1
movq (%r15), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x915ac
callq 0x91573
callq 0x91657
callq 0x915e5
callq 0x9161e