// File: /workspace/github_cpp_makefile_star2_O3/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, 0x8(%rsp)
movq 0x25cf14(%rip), %rbp    # 0x2962c8
testq %rbp, %rbp
je 0x39ae1
movslq %edx, %rax
movq (%rdi,%rax,8), %rax
movq %rax, 0x10(%rsp)
movq 0x25cea0(%rip), %rax    # 0x296270
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movq 0x8(%rax,%rcx,8), %r15
subq %rdx, %r15
addq 0x25ce50(%rip), %rdx    # 0x296238
movq %rdx, 0x18(%rsp)
movq 0x25cec4(%rip), %rbx    # 0x2962b8
xorl %r13d, %r13d
xorl %r14d, %r14d
movq (%rbx,%r14,8), %r12
movq %r12, %rdi
callq 0x2090
cmpq %r15, %rax
jne 0x3941f
movq %r12, %rdi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
callq 0x21a0
testl %eax, %eax
je 0x39439
incq %r14
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r13
cmpq %r14, %rbp
jne 0x393fa
jmp 0x39ae1
movq 0x25ce80(%rip), %rax    # 0x2962c0
movq 0x8(%rsp), %rcx
movq %rcx, (%rax,%r14,8)
movq %rcx, %rsi
movq 0x10(%rsp), %rbx
movq 0xe0(%rbx), %rdi
leaq 0x8(%rbx), %rdx
movq %rdx, 0x30(%rsp)
leaq 0xa0(%rbx), %r14
leaq 0xc0(%rbx), %r8
leaq 0x48(%rbx), %r9
leaq 0x25c2de(%rip), %rax    # 0x295758
movl 0xe8(%rax), %ebp
leaq 0x12160(%rbx), %r15
movq %r15, 0x18(%rsp)
leaq (,%rcx,8), %rcx
leaq (%rcx,%rcx,2), %r10
movq 0x25ce09(%rip), %r11    # 0x2962a8
addq %r10, %r11
addq 0x25ce07(%rip), %r10    # 0x2962b0
leaq 0x121a0(%rbx), %rax
movq %rax, 0x28(%rsp)
movq %r13, %r12
sarq $0x1b, %r12
addq 0x25ce0d(%rip), %r12    # 0x2962d0
leaq 0x12250(%rbx), %rax
subq $0x8, %rsp
movsd 0x1f4b42(%rip), %xmm0   # 0x22e018
movq %r14, %rcx
pushq %rax
pushq %r12
pushq 0x40(%rsp)
pushq %r10
pushq %r11
pushq %r15
pushq $0x0
movl $0x1, %eax
pushq %rax
pushq %rbp
callq 0x12a53a
addq $0x50, %rsp
leaq 0x108(%rbx), %r12
movq %r12, %rdi
callq 0x475fb
leaq 0x9330(%rbx), %rbp
movq %rbp, %rdi
callq 0x4758d
leaq 0x2c0(%rbx), %rcx
leaq 0x28(%rbx), %r8
leaq 0x148(%rbx), %r9
leaq 0x200(%rbx), %rax
leaq 0x9040(%rbx), %r10
leaq 0x121e8(%rbx), %r11
leaq 0x20(%rsp), %r15
movq %r14, %rdi
leaq 0x25cce4(%rip), %rsi    # 0x296230
movq 0x30(%rsp), %rdx
pushq %r15
leaq 0x2c(%rsp), %r15
pushq %r15
movl $0x1, %r15d
pushq %r15
pushq $0x0
pushq %r11
pushq 0x40(%rsp)
pushq %rbp
pushq %r10
pushq %r12
pushq %rax
callq 0x582c6
addq $0x50, %rsp
movq 0x10(%rbx), %rax
movq 0x120(%rbx), %rdx
addq %rax, 0xf0(%rbx)
movq 0x2e0(%rbx), %rax
addq %rax, 0xf8(%rbx)
movq 0x9350(%rbx), %rax
addq %rax, 0x100(%rbx)
movq 0x25ccea(%rip), %rax    # 0x296298
movq 0x8(%rsp), %rcx
leaq (%rcx,%rcx,4), %r15
leaq (%rax,%r15,8), %r12
movl 0xc(%r12), %eax
movq (%r12), %rdi
cmpq %rax, %rdx
jbe 0x395f7
movl %edx, 0xc(%r12)
shlq $0x2, %rdx
movabsq $0x3fffffffc, %rbp      # imm = 0x3FFFFFFFC
andq %rbp, %rdx
movq %rdx, %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, (%r12)
movq 0x120(%rbx), %rdx
jmp 0x39601
movabsq $0x3fffffffc, %rbp      # imm = 0x3FFFFFFFC
movl %edx, 0x8(%r12)
movq 0x110(%rbx), %rsi
shlq $0x2, %rdx
callq 0x2160
movq 0x140(%rbx), %rdx
movl 0x1c(%r12), %eax
cmpq %rax, %rdx
jbe 0x39649
movl %edx, 0x1c(%r12)
movq 0x10(%r12), %rdi
movl %edx, %esi
callq 0x2370
movq %rax, %rdi
movq %rax, 0x10(%r12)
movq 0x140(%rbx), %rdx
jmp 0x3964e
movq 0x10(%r12), %rdi
movl %edx, 0x18(%r12)
movq 0x130(%rbx), %rsi
callq 0x2160
movl 0x128(%rbx), %eax
movl %eax, 0x20(%r12)
movq 0x25cc2f(%rip), %rax    # 0x2962a0
movq 0x120c8(%rbx), %rdx
leaq (%rax,%r15,8), %r15
movl 0xc(%r15), %eax
movq (%r15), %rdi
cmpq %rax, %rdx
jbe 0x396a8
movl %edx, 0xc(%r15)
shlq $0x2, %rdx
andq %rbp, %rdx
movq %rdx, %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, (%r15)
movq 0x120c8(%rbx), %rdx
movl %edx, 0x8(%r15)
movq 0x120b8(%rbx), %rsi
shlq $0x2, %rdx
callq 0x2160
movq 0x120e8(%rbx), %rdx
movl 0x1c(%r15), %eax
cmpq %rax, %rdx
jbe 0x396eb
movl %edx, 0x1c(%r15)
movq 0x10(%r15), %rdi
movl %edx, %esi
callq 0x2370
movq %rax, %rdi
movq %rax, 0x10(%r15)
movq 0x120e8(%rbx), %rdx
jmp 0x396ef
movq 0x10(%r15), %rdi
sarq $0x20, %r13
movl %edx, 0x18(%r15)
movq 0x120d8(%rbx), %rsi
callq 0x2160
movl 0x120d0(%rbx), %eax
movl %eax, 0x20(%r15)
movq 0x25cb94(%rip), %rax    # 0x2962a8
movq 0x8(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movb $0x0, 0x10(%rax,%rcx,8)
cmpl $0x0, 0x24(%rsp)
je 0x397b4
movq 0x120(%rbx), %rdx
testq %rdx, %rdx
jle 0x3976b
movq 0x110(%rbx), %rsi
xorl %edi, %edi
xorl %r8d, %r8d
movl (%rsi,%rdi,4), %r9d
movl %r9d, %r10d
andl $0x3, %r10d
shrl $0x2, %r9d
testl %r10d, %r10d
cmovel %r10d, %r9d
addl %r9d, %r8d
incq %rdi
cmpq %rdi, %rdx
jne 0x39745
testl %r8d, %r8d
jne 0x397b4
movq 0x120c8(%rbx), %rdx
testq %rdx, %rdx
jle 0x397a9
movq 0x120b8(%rbx), %rsi
xorl %edi, %edi
xorl %r8d, %r8d
movl (%rsi,%rdi,4), %r9d
movl %r9d, %r10d
andl $0x3, %r10d
shrl $0x2, %r9d
testl %r10d, %r10d
cmovel %r10d, %r9d
addl %r9d, %r8d
incq %rdi
cmpq %rdi, %rdx
jne 0x39783
testl %r8d, %r8d
jne 0x397b4
leaq (%rax,%rcx,8), %rdx
addq $0x10, %rdx
movb $0x1, (%rdx)
movb 0x20(%rsp), %dl
movb %dl, 0x11(%rax,%rcx,8)
leaq 0x25cb2d(%rip), %rdi    # 0x2962f0
callq 0x22c0
movq 0x25cb09(%rip), %rdi    # 0x2962d8
movq 0x25ca9a(%rip), %rax    # 0x296270
movq 0x8(%rsp), %rbx
movl 0x8(%rax,%rbx,8), %edx
movq (%rax,%rbx,8), %rcx
subl %ecx, %edx
addq 0x25ca4c(%rip), %rcx    # 0x296238
leaq 0x1f78e3(%rip), %rsi    # 0x2310d6
movq %rbx, %r8
xorl %eax, %eax
callq 0x22b0
movq 0x25cad4(%rip), %rdi    # 0x2962d8
leaq 0x25bf4d(%rip), %rsi    # 0x295758
movl 0xf8(%rsi), %edx
movq 0x25ca30(%rip), %rax    # 0x296248
movq (%rax,%rbx,8), %rcx
movl 0xd0(%rsi), %r8d
movl 0xe8(%rsi), %r9d
leaq 0x1f78b7(%rip), %rsi    # 0x2310e8
xorl %eax, %eax
callq 0x22b0
movq 0x25ca99(%rip), %rdi    # 0x2962d8
movq 0x25ca8a(%rip), %rax    # 0x2962d0
shlq $0x5, %r13
movl (%rax,%r13), %edx
leaq 0x1f78c8(%rip), %rsi    # 0x23111d
xorl %eax, %eax
callq 0x22b0
movq 0x25ca6d(%rip), %rdi    # 0x2962d0
addq %r13, %rdi
xorl %esi, %esi
callq 0xa041c
movq 0x25ca5c(%rip), %rax    # 0x2962d0
cmpq $0x0, (%rax,%r13)
je 0x398c4
leaq 0x1f78e4(%rip), %r15    # 0x231166
xorl %r12d, %r12d
movq 0x25ca4c(%rip), %rdi    # 0x2962d8
movq 0x10(%rax,%r13), %rax
movq (%rax,%r12,8), %rcx
movq %rcx, %r8
shrq $0x21, %r8
movq %rcx, %r9
shrq $0x20, %r9
andl $0x1, %r9d
movq %r15, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x22b0
incq %r12
movq 0x25ca12(%rip), %rax    # 0x2962d0
cmpq (%rax,%r13), %r12
jb 0x39885
movq 0x25ca0d(%rip), %rcx    # 0x2962d8
leaq 0x1f78b9(%rip), %rdi    # 0x23118b
movl $0x43, %esi
movl $0x1, %edx
callq 0x2410
movq 0x10(%rsp), %rbx
movq 0xb0(%rbx), %rax
testq %rax, %rax
je 0x399b7
xorl %r13d, %r13d
xorl %ebp, %ebp
movq (%r14), %rcx
cmpb $0x1, 0x2c(%rcx,%r13)
jne 0x399a4
movq 0x25c9c7(%rip), %rdi    # 0x2962d8
movq 0x25c958(%rip), %rax    # 0x296270
movl 0x10(%rcx,%r13), %ecx
leal 0x1(%rcx), %edx
movl (%rax,%rdx,8), %edx
movq (%rax,%rcx,8), %rcx
subl %ecx, %edx
addq 0x25c908(%rip), %rcx    # 0x296238
leaq 0x20c863(%rip), %rsi    # 0x24619a
xorl %eax, %eax
callq 0x22b0
movq 0x25c993(%rip), %rdi    # 0x2962d8
movq 0xa0(%rbx), %rax
movl 0x4(%rax,%r13), %edx
movl 0x8(%rax,%r13), %ecx
movl 0x14(%rax,%r13), %r8d
movl 0x18(%rax,%r13), %r9d
movl 0x1c(%rax,%r13), %r10d
movsbl 0x2e(%rax,%r13), %r11d
movzbl 0x2d(%rax,%r13), %ebx
movq 0x25c8d0(%rip), %r15    # 0x296248
movl 0x10(%rax,%r13), %r12d
leaq 0x1f784b(%rip), %rsi    # 0x2311cf
xorl %eax, %eax
pushq (%r15,%r12,8)
pushq %rbx
movq 0x20(%rsp), %rbx
pushq %r11
pushq %r10
callq 0x22b0
addq $0x20, %rsp
movq 0xb0(%rbx), %rax
incq %rbp
addq $0xa8, %r13
cmpq %rax, %rbp
jb 0x398fb
movq 0x25c91a(%rip), %rcx    # 0x2962d8
leaq 0x1f7859(%rip), %rdi    # 0x23121e
movl $0x43, %esi
movl $0x1, %edx
callq 0x2410
movq 0xb0(%rbx), %rax
testq %rax, %rax
je 0x39aa5
xorl %r13d, %r13d
xorl %ebp, %ebp
movq (%r14), %rcx
cmpb $0x2, 0x2c(%rcx,%r13)
jne 0x39a92
movq 0x25c8d9(%rip), %rdi    # 0x2962d8
movq 0x25c86a(%rip), %rax    # 0x296270
movl 0x10(%rcx,%r13), %ecx
leal 0x1(%rcx), %edx
movl (%rax,%rdx,8), %edx
movq (%rax,%rcx,8), %rcx
subl %ecx, %edx
addq 0x25c81a(%rip), %rcx    # 0x296238
leaq 0x20c775(%rip), %rsi    # 0x24619a
xorl %eax, %eax
callq 0x22b0
movq 0x25c8a5(%rip), %rdi    # 0x2962d8
movq 0xa0(%rbx), %rax
movl 0x4(%rax,%r13), %edx
movl 0x8(%rax,%r13), %ecx
movl 0x14(%rax,%r13), %r8d
movl 0x18(%rax,%r13), %r9d
movl 0x1c(%rax,%r13), %r10d
movsbl 0x2e(%rax,%r13), %r11d
movzbl 0x2d(%rax,%r13), %ebx
movq 0x25c7e2(%rip), %r15    # 0x296248
movl 0x10(%rax,%r13), %r12d
leaq 0x1f775d(%rip), %rsi    # 0x2311cf
xorl %eax, %eax
pushq (%r15,%r12,8)
pushq %rbx
movq 0x20(%rsp), %rbx
pushq %r11
pushq %r10
callq 0x22b0
addq $0x20, %rsp
movq 0xb0(%rbx), %rax
incq %rbp
addq $0xa8, %r13
cmpq %rax, %rbp
jb 0x399e9
movq 0x25c7ac(%rip), %rax    # 0x296258
movq 0x8(%rsp), %rdx
movb $0x0, (%rax,%rdx)
movq 0x25c81c(%rip), %rdi    # 0x2962d8
movq 0x25c795(%rip), %rax    # 0x296258
movzbl (%rax,%rdx), %ecx
leaq 0x1f7794(%rip), %rsi    # 0x231262
xorl %eax, %eax
callq 0x22b0
leaq 0x25c814(%rip), %rdi    # 0x2962f0
callq 0x2130
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq