// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Assembly.cpp
// Function: worker_ovec_related_reads(void*, long, int)
static void worker_ovec_related_reads(void *data, long i, int tid)
{
	ha_ovec_buf_t *b = ((ha_ovec_buf_t**)data)[tid];

    uint64_t k, queryNameLen;
    for (k = 0; k < R_INF_FLAG.query_num; k++)
    {
        queryNameLen = strlen(R_INF_FLAG.read_name[k]);
        if (queryNameLen != Get_NAME_LENGTH((R_INF),i)) continue;
        if (memcmp(R_INF_FLAG.read_name[k], Get_NAME((R_INF), i), Get_NAME_LENGTH((R_INF),i)) == 0)
        {
            break;
        }
    }

    if(k < R_INF_FLAG.query_num)
    {
        R_INF_FLAG.read_id[k] = i;
        int fully_cov, abnormal, q_idx = k;

        ha_get_candidates_interface(b->ab, i, &b->self_read, &b->olist, &b->olist_hp, &b->clist, 
        0.02, asm_opt.max_n_chain, 1, NULL/**&(b->k_flag)**/, &b->r_buf, &(R_INF.paf[i]), &(R_INF.reverse_paf[i]), &(b->tmp_region), &(R_INF_FLAG.candidate_count[q_idx]), &(b->sp));

        clear_Cigar_record(&b->cigar1);
        clear_Round2_alignment(&b->round2);

        correct_overlap(&b->olist, &R_INF, &b->self_read, &b->correct, &b->ovlp_read, &b->POA_Graph, &b->DAGCon,
                &b->cigar1, &b->hap, &b->round2, &b->r_buf, &(b->tmp_region.w_list), 0, 1, &fully_cov, &abnormal);

        b->num_read_base += b->self_read.length;
        b->num_correct_base += b->correct.corrected_base;
        b->num_recorrect_base += b->round2.dumy.corrected_base;

        push_cigar(R_INF.cigars, i, &b->cigar1);
        push_cigar(R_INF.second_round_cigar, i, &b->round2.cigar);

        R_INF.paf[i].is_fully_corrected = 0;
        if (fully_cov) {
            if (get_cigar_errors(&b->cigar1) == 0 && get_cigar_errors(&b->round2.cigar) == 0)
                R_INF.paf[i].is_fully_corrected = 1;
        }
        R_INF.paf[i].is_abnormal = abnormal;

        

        pthread_mutex_lock(&R_INF_FLAG.OutputMutex);

        fprintf(R_INF_FLAG.fp, "\n>%.*s, rid: %ld\n", (int)Get_NAME_LENGTH((R_INF), i), Get_NAME((R_INF), i), i);
        fprintf(R_INF_FLAG.fp, "%d-th round, len: %lu, hom_cov: %d, max_n_chain: %d\n", 
            asm_opt.number_of_round, Get_READ_LENGTH(R_INF, i), asm_opt.hom_cov, asm_opt.max_n_chain);

        fprintf(R_INF_FLAG.fp, "***************************k-mer counts (%d)***************************\n", (int)(R_INF_FLAG.candidate_count[q_idx].a.n));
        
        sort_kvec_t_u64_warp(&(R_INF_FLAG.candidate_count[q_idx]), 0);
        for (k = 0; k < R_INF_FLAG.candidate_count[q_idx].a.n; k++) 
        {
            fprintf(R_INF_FLAG.fp, "[%lu] Count(%u): %lu, filtered: %lu\n", k, 
            (uint32_t)R_INF_FLAG.candidate_count[q_idx].a.a[k], R_INF_FLAG.candidate_count[q_idx].a.a[k]>>33, 
            (R_INF_FLAG.candidate_count[q_idx].a.a[k]>>32)&(uint64_t)1);
        }

        
        fprintf(R_INF_FLAG.fp, "***************************forward ovlp***************************\n");
        for (k = 0; k < b->olist.length; k++) 
        {
            if(b->olist.list[k].is_match != 1) continue;
			fprintf(R_INF_FLAG.fp, "%.*s\n", (int)Get_NAME_LENGTH((R_INF), b->olist.list[k].y_id), Get_NAME((R_INF), b->olist.list[k].y_id));
            fprintf(R_INF_FLAG.fp, "qs: %u, qe: %u, ts: %u, te: %u, rev: %u, strong: %u, no_l_indel: %u, len: %lu\n",
            b->olist.list[k].x_pos_s, b->olist.list[k].x_pos_e, b->olist.list[k].y_pos_s, b->olist.list[k].y_pos_e, 
            b->olist.list[k].y_pos_strand, b->olist.list[k].strong, b->olist.list[k].without_large_indel,
            Get_READ_LENGTH(R_INF, b->olist.list[k].y_id));
		}

        fprintf(R_INF_FLAG.fp, "***************************reverse ovlp***************************\n");
        for (k = 0; k < b->olist.length; k++) 
        {
            if(b->olist.list[k].is_match != 2) continue;
			fprintf(R_INF_FLAG.fp, "%.*s\n", (int)Get_NAME_LENGTH((R_INF), b->olist.list[k].y_id), Get_NAME((R_INF), b->olist.list[k].y_id));
            fprintf(R_INF_FLAG.fp, "qs: %u, qe: %u, ts: %u, te: %u, rev: %u, strong: %u, no_l_indel: %u, len: %lu\n",
            b->olist.list[k].x_pos_s, b->olist.list[k].x_pos_e, b->olist.list[k].y_pos_s, b->olist.list[k].y_pos_e, 
            b->olist.list[k].y_pos_strand, b->olist.list[k].strong, b->olist.list[k].without_large_indel,
            Get_READ_LENGTH(R_INF, b->olist.list[k].y_id));
		}

        /**
        fprintf(R_INF_FLAG.fp, "***************************unmatched ovlp***************************\n");
        for (k = 0; k < b->olist.length; k++) 
        {
            if(b->olist.list[k].is_match == 1) continue;
            if(b->olist.list[k].is_match == 2) continue;
			fprintf(R_INF_FLAG.fp, "%.*s\n", (int)Get_NAME_LENGTH((R_INF), b->olist.list[k].y_id), Get_NAME((R_INF), b->olist.list[k].y_id));
            fprintf(R_INF_FLAG.fp, "qs: %u, qe: %u, ts: %u, te: %u, rev: %u, strong: %u, no_l_indel: %u, len: %lu\n",
            b->olist.list[k].x_pos_s, b->olist.list[k].x_pos_e, b->olist.list[k].y_pos_s, b->olist.list[k].y_pos_e, 
            b->olist.list[k].y_pos_strand, b->olist.list[k].strong, b->olist.list[k].without_large_indel,
            Get_READ_LENGTH(R_INF, b->olist.list[k].y_id));
		}
        **/

        R_INF.trio_flag[i] = AMBIGU;

        ///need to be fixed in r305
        // if(ha_idx_hp == NULL)
        // {
        //     R_INF.trio_flag[i] += collect_hp_regions(&b->olist, &R_INF, &(b->k_flag), RESEED_HP_RATE, Get_READ_LENGTH(R_INF, i), R_INF_FLAG.fp);
        // }
        
        fprintf(R_INF_FLAG.fp, "R_INF.trio_flag[%ld]: %u\n", i, R_INF.trio_flag[i]);
    

	    pthread_mutex_unlock(&R_INF_FLAG.OutputMutex);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, (%rsp)
movslq %edx, %rax
movq (%rdi,%rax,8), %rax
movq %rax, 0x18(%rsp)
movq 0x2474ee(%rip), %r12    # 0x2542c8
movq 0x2474d7(%rip), %rbp    # 0x2542b8
movq 0x247488(%rip), %r13    # 0x254270
movq 0x247449(%rip), %rax    # 0x254238
movq %rax, 0x10(%rsp)
xorl %r15d, %r15d
xorl %ebx, %ebx
cmpq %rbx, %r12
je 0xd316
movq (%rbp,%rbx,8), %r14
movq %r14, %rdi
callq 0x2090
movq (%rsp), %rcx
movq (%r13,%rcx,8), %rsi
movq 0x8(%r13,%rcx,8), %rcx
subq %rsi, %rcx
cmpq %rcx, %rax
jne 0xce39
addq 0x10(%rsp), %rsi
movq %r14, %rdi
movq %rax, %rdx
callq 0x21a0
testl %eax, %eax
je 0xce4b
incq %rbx
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r15
jmp 0xcdf9
movq 0x24746e(%rip), %rax    # 0x2542c0
movq (%rsp), %rcx
movq %rcx, (%rax,%rbx,8)
movq 0x18(%rsp), %r13
movq 0xe0(%r13), %rdi
leaq 0x8(%r13), %rdx
movq %rdx, 0x28(%rsp)
leaq 0xa0(%r13), %r14
leaq 0xc0(%r13), %r8
leaq 0x48(%r13), %r9
leaq 0x2468d0(%rip), %rax    # 0x253758
movl 0xe8(%rax), %eax
movq %rax, 0x8(%rsp)
leaq 0x12160(%r13), %rax
movq %rax, 0x30(%rsp)
imulq $0x18, %rcx, %rbx
movq %rbx, 0x10(%rsp)
movq %rcx, %rsi
movq 0x2473f6(%rip), %r10    # 0x2542a8
addq %rbx, %r10
movq 0x2473f4(%rip), %r11    # 0x2542b0
addq %rbx, %r11
leaq 0x121a0(%r13), %rbx
movq %r15, %rbp
sarq $0x20, %rbp
sarq $0x1b, %r15
addq 0x2473f8(%rip), %r15    # 0x2542d0
leaq 0x12250(%r13), %r12
subq $0x8, %rsp
movsd 0x1d312d(%rip), %xmm0   # 0x1e0018
movq %r14, %rcx
pushq %r12
pushq %r15
pushq %rbx
pushq %r11
pushq %r10
pushq %rax
pushq $0x0
pushq $0x1
popq %rax
pushq %rax
pushq 0x50(%rsp)
callq 0xe53a4
addq $0x50, %rsp
leaq 0x108(%r13), %r15
movq %r15, %rdi
callq 0x1b25d
leaq 0x9330(%r13), %r12
movq %r12, %rdi
callq 0x1b1e8
leaq 0x2c0(%r13), %rcx
leaq 0x28(%r13), %r8
leaq 0x148(%r13), %r9
leaq 0x200(%r13), %rax
movq %rax, 0x8(%rsp)
leaq 0x9040(%r13), %r10
leaq 0x121e8(%r13), %r11
leaq 0x24(%rsp), %rbx
movq %r14, %rdi
leaq 0x2472cc(%rip), %rsi    # 0x254230
movq 0x28(%rsp), %rdx
leaq 0x20(%rsp), %rax
pushq %rax
pushq %rbx
pushq $0x1
popq %rbx
pushq %rbx
pushq $0x0
pushq %r11
pushq 0x58(%rsp)
pushq %r12
pushq %r10
pushq %r15
pushq 0x50(%rsp)
callq 0x29192
addq $0x50, %rsp
movq 0x10(%r13), %rax
addq %rax, 0xf0(%r13)
movq 0x2e0(%r13), %rax
addq %rax, 0xf8(%r13)
movq 0x9350(%r13), %rax
addq %rax, 0x100(%r13)
movq 0x2472db(%rip), %rdi    # 0x254298
movq (%rsp), %rbx
movq %rbx, %rsi
movq %r15, %rdx
callq 0x10ab7
movq 0x2472cd(%rip), %rdi    # 0x2542a0
leaq 0x120b0(%r13), %r12
movq %rbx, %rsi
movq %r12, %rdx
callq 0x10ab7
movq 0x2472bc(%rip), %rcx    # 0x2542a8
movq 0x10(%rsp), %rax
movq %rax, %rbx
movb $0x0, 0x10(%rcx,%rax)
leaq 0x24(%rsp), %rax
cmpl $0x0, (%rax)
je 0xd030
movq %r15, %rdi
callq 0x10b4a
testl %eax, %eax
je 0xd018
movq 0x247292(%rip), %rcx    # 0x2542a8
jmp 0xd030
movq %r12, %rdi
callq 0x10b4a
movq 0x247281(%rip), %rcx    # 0x2542a8
testl %eax, %eax
jne 0xd030
movb $0x1, 0x10(%rcx,%rbx)
movb 0x20(%rsp), %al
movb %al, 0x11(%rcx,%rbx)
leaq 0x2472b1(%rip), %rdi    # 0x2542f0
callq 0x22c0
movq 0x24728d(%rip), %rdi    # 0x2542d8
movq 0x24721e(%rip), %rax    # 0x254270
movq (%rsp), %rbx
movl 0x8(%rax,%rbx,8), %edx
movq (%rax,%rbx,8), %rcx
subl %ecx, %edx
addq 0x2471d1(%rip), %rcx    # 0x254238
leaq 0x1d6058(%rip), %rsi    # 0x1e30c6
movq %rbx, %r8
xorl %eax, %eax
callq 0x22b0
movq 0x247259(%rip), %rdi    # 0x2542d8
leaq 0x2466d2(%rip), %rsi    # 0x253758
movl 0xf8(%rsi), %edx
movq 0x2471b5(%rip), %rax    # 0x254248
movq (%rax,%rbx,8), %rcx
movl 0xd0(%rsi), %r8d
movl 0xe8(%rsi), %r9d
leaq 0x1d602c(%rip), %rsi    # 0x1e30d8
xorl %eax, %eax
callq 0x22b0
movq 0x24721e(%rip), %rdi    # 0x2542d8
movq 0x24720f(%rip), %rax    # 0x2542d0
shlq $0x5, %rbp
movl (%rax,%rbp), %edx
leaq 0x1d603e(%rip), %rsi    # 0x1e310d
xorl %eax, %eax
callq 0x22b0
movq 0x2471f3(%rip), %rdi    # 0x2542d0
addq %rbp, %rdi
xorl %esi, %esi
callq 0x68eff
leaq 0x1d6068(%rip), %r15    # 0x1e3156
xorl %r12d, %r12d
movq 0x2471d8(%rip), %rcx    # 0x2542d0
movq 0x2471d9(%rip), %rax    # 0x2542d8
cmpq (%rcx,%rbp), %r12
jae 0xd137
addq %rbp, %rcx
movq 0x10(%rcx), %rcx
movq (%rcx,%r12,8), %rcx
movq %rcx, %r8
shrq $0x21, %r8
movq %rcx, %r9
shrq $0x20, %r9
andl $0x1, %r9d
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x22b0
incq %r12
jmp 0xd0f1
leaq 0x1d603d(%rip), %rdi    # 0x1e317b
pushq $0x43
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
callq 0x2410
xorl %ebp, %ebp
xorl %r15d, %r15d
movq 0x18(%rsp), %rax
cmpq 0xb0(%rax), %r15
jae 0xd207
movq (%r14), %rax
cmpb $0x1, 0x2c(%rax,%rbp)
jne 0xd1f8
movq 0x247160(%rip), %rdi    # 0x2542d8
movq 0x2470f1(%rip), %rcx    # 0x254270
movl 0x10(%rax,%rbp), %eax
leal 0x1(%rax), %edx
movl (%rcx,%rdx,8), %edx
movq (%rcx,%rax,8), %rcx
subl %ecx, %edx
addq 0x2470a2(%rip), %rcx    # 0x254238
leaq 0x1eaecd(%rip), %rsi    # 0x1f806a
xorl %eax, %eax
callq 0x22b0
movq 0x24712d(%rip), %rdi    # 0x2542d8
movq (%r14), %rax
movl 0x4(%rax,%rbp), %edx
movl 0x8(%rax,%rbp), %ecx
movl 0x14(%rax,%rbp), %r8d
movl 0x18(%rax,%rbp), %r9d
movl 0x1c(%rax,%rbp), %r10d
movsbl 0x2e(%rax,%rbp), %r11d
movzbl 0x2d(%rax,%rbp), %ebx
movq 0x247071(%rip), %r13    # 0x254248
movl 0x10(%rax,%rbp), %r12d
leaq 0x1d5fdc(%rip), %rsi    # 0x1e31bf
xorl %eax, %eax
pushq (%r13,%r12,8)
pushq %rbx
pushq %r11
pushq %r10
callq 0x22b0
addq $0x20, %rsp
incq %r15
addq $0xa8, %rbp
jmp 0xd151
movq 0x2470ca(%rip), %rcx    # 0x2542d8
leaq 0x1d5ff9(%rip), %rdi    # 0x1e320e
pushq $0x43
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
xorl %ebp, %ebp
xorl %r15d, %r15d
movq 0x18(%rsp), %rax
cmpq 0xb0(%rax), %r15
jae 0xd2db
movq (%r14), %rax
cmpb $0x2, 0x2c(%rax,%rbp)
jne 0xd2cc
movq 0x24708c(%rip), %rdi    # 0x2542d8
movq 0x24701d(%rip), %rcx    # 0x254270
movl 0x10(%rax,%rbp), %eax
leal 0x1(%rax), %edx
movl (%rcx,%rdx,8), %edx
movq (%rcx,%rax,8), %rcx
subl %ecx, %edx
addq 0x246fce(%rip), %rcx    # 0x254238
leaq 0x1eadf9(%rip), %rsi    # 0x1f806a
xorl %eax, %eax
callq 0x22b0
movq 0x247059(%rip), %rdi    # 0x2542d8
movq (%r14), %rax
movl 0x4(%rax,%rbp), %edx
movl 0x8(%rax,%rbp), %ecx
movl 0x14(%rax,%rbp), %r8d
movl 0x18(%rax,%rbp), %r9d
movl 0x1c(%rax,%rbp), %r10d
movsbl 0x2e(%rax,%rbp), %r11d
movzbl 0x2d(%rax,%rbp), %ebx
movq 0x246f9d(%rip), %r13    # 0x254248
movl 0x10(%rax,%rbp), %r12d
leaq 0x1d5f08(%rip), %rsi    # 0x1e31bf
xorl %eax, %eax
pushq (%r13,%r12,8)
pushq %rbx
pushq %r11
pushq %r10
callq 0x22b0
addq $0x20, %rsp
incq %r15
addq $0xa8, %rbp
jmp 0xd225
movq 0x246f76(%rip), %rax    # 0x254258
movq (%rsp), %rdx
movb $0x0, (%rax,%rdx)
movq 0x246fe7(%rip), %rdi    # 0x2542d8
movq 0x246f60(%rip), %rax    # 0x254258
movzbl (%rax,%rdx), %ecx
leaq 0x1d5f4f(%rip), %rsi    # 0x1e3252
xorl %eax, %eax
callq 0x22b0
leaq 0x246fdf(%rip), %rdi    # 0x2542f0
callq 0x2130
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq