// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x1c(%rbp), %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x2, %eax
jne 0x142620
movl $0xffffffff, -0x38(%rbp) # imm = 0xFFFFFFFF
movl -0x20(%rbp), %eax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
shlq $0x21, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl -0x38(%rbp), %ecx
orq %rcx, %rax
movq %rax, -0x40(%rbp)
movabsq $0x100000000, %rax      # imm = 0x100000000
orq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x1425fa
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x1425bf
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x48(%rbp)
jmp 0x1425ca
movl $0x2, %eax
movq %rax, -0x48(%rbp)
jmp 0x1425ca
movq -0x48(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x14278e
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
movl -0x1c(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0xc(%rcx), %eax
jae 0x14278e
movq -0x10(%rbp), %rax
movl -0x1c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x30(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x1, %eax
jne 0x1426b5
movq -0x18(%rbp), %rdi
movl -0x30(%rbp), %esi
leaq -0x30(%rbp), %rdx
leaq -0x34(%rbp), %rcx
callq 0xd3d50
cmpl $-0x1, -0x30(%rbp)
je 0x1426ae
cmpl $0x1, -0x34(%rbp)
je 0x1426ae
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x30(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x1, %eax
jne 0x1426b3
jmp 0x142780
jmp 0x1426b5
movq -0x18(%rbp), %rdi
movl -0x30(%rbp), %esi
leaq -0x38(%rbp), %rdx
leaq -0x34(%rbp), %rcx
callq 0xd3d50
cmpl $0x0, -0x34(%rbp)
jne 0x1426d4
jmp 0x142780
movl -0x20(%rbp), %eax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
shlq $0x21, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl -0x38(%rbp), %ecx
orq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x14275d
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x142722
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x50(%rbp)
jmp 0x14272d
movl $0x2, %eax
movq %rax, -0x50(%rbp)
jmp 0x14272d
movq -0x50(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x142780
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x142627
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)