// File: /workspace/github_cpp_makefile_star2_O3/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:
movq $0x0, (%rdx)
cmpl $0x0, 0xc(%rsi)
je 0xd5f75
movl 0x10(%rsi), %eax
testl %eax, %eax
je 0xd5f75
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %r14
movq %rdi, %r10
movabsq $0x100000000, %rbp      # imm = 0x100000000
xorl %r8d, %r8d
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movq %rcx, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdx, 0x18(%rsp)
movq 0x18(%rsi), %rdi
movq (%rdi,%r8,8), %rdi
shrq $0x21, %rdi
leaq (%rdi,%rdi,2), %rdi
movl 0xc(%rcx,%rdi,8), %r9d
testl %r9d, %r9d
je 0xd5efa
movq %r8, 0x20(%rsp)
leaq (%rcx,%rdi,8), %r12
movl $0xc, %r13d
xorl %r15d, %r15d
movq (%r12), %rax
movl (%rax,%r13), %eax
movq (%r14), %r8
cmpq %rax, %r8
jbe 0xd5ed5
movq 0x8(%r14), %rsi
movl (%rsi,%rax,4), %edi
cmpq %r11, %rdi
je 0xd5ed5
movl %edi, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
testl %edi, %edi
js 0xd5e66
cmpq %rax, %r8
jbe 0xd5ed5
movl (%rsi,%rax,4), %eax
cmpl $-0x2, %eax
jg 0xd5ed5
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x20(%r10), %rsi
movl %eax, %ebx
cmpb $0x1, 0x4(%rsi,%rbx,8)
je 0xd5ed5
movq (%rdx), %rdi
movq 0x10(%rdx), %rax
cmpq 0x8(%rdx), %rdi
jne 0xd5ec7
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rdx)
shlq $0x3, %rsi
movq %rax, %rdi
movq %r10, %rbp
callq 0x2370
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movq %rbp, %r10
movq 0x18(%rsp), %rdx
movabsq $0x100000000, %rbp      # imm = 0x100000000
movq %rax, 0x10(%rdx)
movq (%rdx), %rdi
movl 0xc(%r12), %r9d
orq %rbp, %rbx
leaq 0x1(%rdi), %rsi
movq %rsi, (%rdx)
movq %rbx, (%rax,%rdi,8)
incq %r15
movl %r9d, %eax
addq $0x28, %r13
cmpq %rax, %r15
jb 0xd5e25
movq 0x8(%rsp), %rsi
movl 0x10(%rsi), %eax
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %r8
incq %r8
movl %eax, %edi
cmpq %rdi, %r8
jb 0xd5df5
movq (%rdx), %rax
testq %rax, %rax
je 0xd5f67
movq 0x10(%rdx), %rdi
leaq (%rdi,%rax,8), %rsi
movq %rdx, %rbx
callq 0x9dc69
movq %rbx, %r8
movl $0x1, %eax
cmpq $0x2, (%rbx)
jb 0xd5f64
movq 0x10(%r8), %rcx
xorl %eax, %eax
movl $0x1, %esi
movl $0x2, %edx
movq (%rcx,%rsi,8), %rsi
leal -0x2(%rdx), %edi
cmpq (%rcx,%rdi,8), %rsi
jne 0xd5f53
movl %eax, %esi
addq %rbp, (%rcx,%rsi,8)
jmp 0xd5f59
incl %eax
movq %rsi, (%rcx,%rax,8)
movl %edx, %esi
incl %edx
cmpq %rsi, (%r8)
ja 0xd5f3e
incl %eax
movq %rax, (%r8)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq