// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: get_candidate_uids(asg_t*, ma_utg_t*, kvec_t_u64_warp*, ma_hit_t_alloc*, R_to_U*)
void get_candidate_uids(asg_t* nsg, ma_utg_t* nsu, kvec_t_u64_warp* u_vecs, 
ma_hit_t_alloc* reverse_sources, R_to_U* ruIndex)
{
    uint32_t k, j, rId, uId, is_Unitig, m;
    uint64_t pre;
    u_vecs->a.n = 0;
    if(nsu->m == 0) return;
    for (k = 0; k < nsu->n; k++)
    {
        rId = nsu->a[k]>>33;
        for (j = 0; j < reverse_sources[rId].length; j++)
        {
            get_R_to_U(ruIndex, Get_tn(reverse_sources[rId].buffer[j]), &uId, &is_Unitig);
            if(uId==(uint32_t)-1) continue;
            ///contained read
            if(is_Unitig == 0) get_R_to_U(ruIndex, uId, &uId, &is_Unitig);
            if(uId == (uint32_t)-1 || is_Unitig == 0) continue;
            ///need this line
            if(nsg->seq[uId].c == ALTER_LABLE) continue;
            pre = uId; 
            pre = pre | (uint64_t)(0x100000000);
            kv_push(uint64_t, u_vecs->a, pre);
        }
    }
    if(u_vecs->a.n == 0) return;
    radix_sort_arch64(u_vecs->a.a, u_vecs->a.a + u_vecs->a.n);
    for (m = 0, k = 1; k < u_vecs->a.n; k++)
    {
        if(u_vecs->a.a[k] == u_vecs->a.a[k-1])
        {
            u_vecs->a.a[m] += (uint64_t)(0x100000000);
        }
        else
        {
            m++;
            u_vecs->a.a[m] = u_vecs->a.a[k];
        }
    }

    u_vecs->a.n = m + 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, 0x8(%rsp)
movq $0x0, (%rdx)
cmpl $0x0, 0xc(%rsi)
je 0xd4bd7
movq %rdx, %rbx
cmpl $0x0, 0x10(%rsi)
je 0xd4b73
movq %r8, %r14
movabsq $0x100000000, %r8       # imm = 0x100000000
xorl %ecx, %ecx
movq %rsi, 0x10(%rsp)
movq %rdi, 0x18(%rsp)
movq 0x18(%rsi), %rax
movq %rcx, 0x20(%rsp)
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
leaq (%rax,%rax,2), %rax
movq 0x8(%rsp), %rcx
cmpl $0x0, 0xc(%rcx,%rax,8)
je 0xd4b5a
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax,8), %r15
movl $0xc, %r12d
xorl %r13d, %r13d
movq (%r15), %rax
movl (%rax,%r12), %edx
movq (%r14), %rcx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rdx, %rcx
jbe 0xd4aa7
movq 0x8(%r14), %rsi
movl (%rsi,%rdx,4), %edx
cmpl $-0x1, %edx
je 0xd4aa7
movl %edx, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
testl %edx, %edx
setns %dl
jmp 0xd4aa9
xorl %edx, %edx
cmpl $-0x1, %eax
je 0xd4b46
testb %dl, %dl
je 0xd4adc
movl %eax, %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rdx, %rcx
jbe 0xd4adc
movq 0x8(%r14), %rcx
movl (%rcx,%rdx,4), %ecx
cmpl $-0x1, %ecx
je 0xd4adc
movl %ecx, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
testl %ecx, %ecx
setns %cl
jmp 0xd4ade
xorl %ecx, %ecx
cmpl $-0x1, %eax
je 0xd4b46
testb %cl, %cl
jne 0xd4b46
movq 0x20(%rdi), %rcx
movl %eax, %ebp
cmpb $0x1, 0x4(%rcx,%rbp,8)
je 0xd4b46
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0xd4b31
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movabsq $0x100000000, %r8       # imm = 0x100000000
movq 0x18(%rsp), %rdi
movq %rax, 0x10(%rbx)
orq %r8, %rbp
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movq %rbp, (%rcx,%rax,8)
incq %r13
movl 0xc(%r15), %eax
addq $0x28, %r12
cmpq %rax, %r13
jb 0xd4a79
movq 0x20(%rsp), %rcx
incq %rcx
movq 0x10(%rsp), %rsi
movl 0x10(%rsi), %eax
cmpq %rax, %rcx
jb 0xd4a42
movq (%rbx), %rax
testq %rax, %rax
je 0xd4bd7
movq 0x10(%rbx), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x9d53f
movl $0x1, %eax
cmpq $0x2, (%rbx)
jb 0xd4bd4
movabsq $0x100000000, %rcx      # imm = 0x100000000
movq 0x10(%rbx), %rdx
xorl %eax, %eax
movl $0x1, %edi
movl $0x2, %esi
movq (%rdx,%rdi,8), %rdi
leal -0x2(%rsi), %r8d
cmpq (%rdx,%r8,8), %rdi
jne 0xd4bc3
movl %eax, %edi
addq %rcx, (%rdx,%rdi,8)
jmp 0xd4bc9
incl %eax
movq %rdi, (%rdx,%rax,8)
movl %esi, %edi
incl %esi
cmpq %rdi, (%rbx)
ja 0xd4bad
incl %eax
movq %rax, (%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq