// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: query_reverse_sources(asg_t*, ma_hit_t_alloc*, R_to_U*, unsigned int, unsigned int, kvec_t_u64_warp*)
void query_reverse_sources(asg_t *read_g, ma_hit_t_alloc* reverse_sources,
R_to_U* ruIndex, uint32_t qn, uint32_t self_offset, kvec_t_u64_warp* u_vecs)
{
    uint32_t i, rId, is_Unitig, cId;
    uint64_t mode;
    ///means the reads coming from different haplotype have already been purged
    if(read_g->seq[qn].c == HAP_LABLE)
    {
        cId = (uint32_t)-1;
        mode = self_offset; mode = mode << 33; mode = mode|cId; mode = mode | (uint64_t)(0x100000000);
        kv_push(uint64_t, u_vecs->a, mode);
        return;
    }


    for (i = 0; i < reverse_sources[qn].length; i++)
    {
        rId = Get_tn(reverse_sources[qn].buffer[i]);
        ///there are three cases: 
        ///1. read at primary contigs, get_R_to_U() return its corresponding contig Id  
        ///2. read at alternative contigs, get_R_to_U() return (uint32_t)-1
        ///3. read has bee deleted, get_R_to_U() return the id of read that contains it 
        if(read_g->seq[rId].del == 1)
        {
            ///get the id of read that contains it 
            get_R_to_U(ruIndex, rId, &rId, &is_Unitig);
            if(rId == (uint32_t)-1 || is_Unitig == 1 || read_g->seq[rId].del == 1) continue;
        }

        ///here rId is the id of the read coming from the different haplotype
        ///cId is the id of the corresponding contig (note here is the contig, instead of untig)
        get_R_to_U(ruIndex, rId, &cId, &is_Unitig);
        if(is_Unitig == 0) continue;
        ///if the read is at alternative contigs, cId might be (uint32_t)-1
        ///if(cId == (uint32_t)-1)
        mode = self_offset; mode = mode << 33; mode = mode|(uint64_t)(cId);
        kv_push(uint64_t, u_vecs->a, mode);
    }
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %rbx
movl %r8d, %r15d
movq %rdi, %r9
movq 0x20(%rdi), %rdi
movl %ecx, %eax
cmpb $0x2, 0x4(%rdi,%rax,8)
jne 0xe993c
shlq $0x21, %r15
movabsq $0x1ffffffff, %r14      # imm = 0x1FFFFFFFF
orq %r15, %r14
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0xe9925
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movq %r14, (%rcx,%rax,8)
jmp 0xe9a65
leaq (%rax,%rax,2), %rax
cmpl $0x0, 0xc(%rsi,%rax,8)
je 0xe9a65
movq %rdx, %r13
leaq (%rsi,%rax,8), %r10
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
shlq $0x21, %r15
movl $0xc, %ebp
xorl %r14d, %r14d
movq %rbx, 0x10(%rsp)
movq %r9, 0x8(%rsp)
movq (%r10), %rax
movl (%rax,%rbp), %edi
movq 0x20(%r9), %rcx
cmpl $0x0, (%rcx,%rdi,8)
movl %edi, %eax
js 0xe9a14
movl %eax, %eax
cmpq %rax, (%r13)
jbe 0xe99a9
movq 0x8(%r13), %rcx
movl (%rcx,%rax,4), %eax
cmpq %r11, %rax
je 0xe99a9
movl %eax, %r12d
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
testl %eax, %eax
setns %al
jmp 0xe99b1
xorl %eax, %eax
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testb %al, %al
jne 0xe9a51
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0xe99fd
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rsi
movq %r10, %rbx
callq 0x2370
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movq %rbx, %r10
movq 0x8(%rsp), %r9
movq 0x10(%rsp), %rbx
movq %rax, 0x10(%rbx)
orq %r15, %r12
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rsi
movq %rsi, (%rbx)
movq %r12, (%rcx,%rax,8)
jmp 0xe9a51
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rdi, (%r13)
jbe 0xe9a37
movq 0x8(%r13), %rsi
movl (%rsi,%rdi,4), %edi
cmpl $-0x1, %edi
je 0xe9a37
movl %edi, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shrl $0x1f, %edi
jmp 0xe9a39
xorl %edi, %edi
cmpl $-0x1, %eax
sete %sil
orb %dil, %sil
jne 0xe9a51
movl %eax, %esi
cmpl $0x0, (%rcx,%rsi,8)
jns 0xe9984
incq %r14
movl 0xc(%r10), %eax
addq $0x28, %rbp
cmpq %rax, %r14
jb 0xe996e
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq