// File: /workspace/github_cpp_makefile_star2_O1/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 0x25149b(%rip), %rax    # 0x28b2c8
movq %rax, 0x10(%rsp)
testq %rax, %rax
setne %r13b
je 0x3a561
movslq %edx, %rax
movq (%rdi,%rax,8), %rax
movq %rax, 0x18(%rsp)
movq 0x251466(%rip), %rax    # 0x28b2b8
movq %rax, 0x28(%rsp)
movq 0x251412(%rip), %rax    # 0x28b270
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movq 0x8(%rax,%rcx,8), %r15
subq %rdx, %r15
addq 0x2513c2(%rip), %rdx    # 0x28b238
movq %rdx, 0x20(%rsp)
movq 0x10(%rsp), %rbp
negq %rbp
movl $0x1, %ebx
xorl %r14d, %r14d
movq 0x28(%rsp), %rax
movq -0x8(%rax,%rbx,8), %r12
movq %r12, %rdi
callq 0x2090
cmpq %r15, %rax
jne 0x39eb6
movq %r12, %rdi
movq 0x20(%rsp), %rsi
movq %r15, %rdx
callq 0x21a0
testl %eax, %eax
je 0x39ee1
cmpq 0x10(%rsp), %rbx
setb %r13b
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r14
leaq (%rbx,%rbp), %rax
incq %rax
incq %rbx
cmpq $0x1, %rax
jne 0x39e8b
jmp 0x3a561
testb $0x1, %r13b
je 0x3a561
movq 0x2513ce(%rip), %rax    # 0x28b2c0
movq 0x8(%rsp), %rcx
movq %rcx, -0x8(%rax,%rbx,8)
movq %rcx, %rsi
movq 0x18(%rsp), %r13
movq 0xe0(%r13), %rdi
leaq 0x8(%r13), %rdx
movq %rdx, 0x20(%rsp)
leaq 0xa0(%r13), %rcx
movq %rcx, 0x10(%rsp)
leaq 0xc0(%r13), %r8
leaq 0x48(%r13), %r9
leaq 0x250826(%rip), %rax    # 0x28a758
movl 0xe8(%rax), %ebx
leaq 0x12160(%r13), %rax
movq %rax, 0x28(%rsp)
leaq (,%rsi,8), %r10
leaq (%r10,%r10,2), %r10
movq 0x251351(%rip), %r11    # 0x28b2a8
addq %r10, %r11
addq 0x25134f(%rip), %r10    # 0x28b2b0
leaq 0x121a0(%r13), %r15
movq %r14, %r12
sarq $0x1b, %r12
addq 0x25135a(%rip), %r12    # 0x28b2d0
leaq 0x12250(%r13), %rbp
subq $0x8, %rsp
movsd 0x1e808f(%rip), %xmm0   # 0x222018
pushq %rbp
pushq %r12
pushq %r15
pushq %r10
pushq %r11
pushq %rax
pushq $0x0
movl $0x1, %r15d
pushq %r15
pushq %rbx
callq 0x1245e4
addq $0x50, %rsp
leaq 0x108(%r13), %r12
movq %r12, %rdi
callq 0x48007
leaq 0x9330(%r13), %rbp
movq %rbp, %rdi
callq 0x47f99
leaq 0x2c0(%r13), %rcx
leaq 0x28(%r13), %r8
leaq 0x148(%r13), %r9
leaq 0x200(%r13), %rax
leaq 0x9040(%r13), %r10
leaq 0x121e8(%r13), %r11
leaq 0x30(%rsp), %rbx
movq 0x10(%rsp), %rdi
leaq 0x251233(%rip), %rsi    # 0x28b230
movq 0x20(%rsp), %rdx
pushq %rbx
leaq 0x3c(%rsp), %rbx
pushq %rbx
pushq %r15
pushq $0x0
pushq %r11
pushq 0x50(%rsp)
pushq %rbp
pushq %r10
pushq %r12
pushq %rax
callq 0x58e58
addq $0x50, %rsp
movq 0x10(%r13), %rax
movq 0x120(%r13), %rsi
addq %rax, 0xf0(%r13)
movq 0x2e0(%r13), %rax
addq %rax, 0xf8(%r13)
movq 0x9350(%r13), %rax
addq %rax, 0x100(%r13)
movq 0x251241(%rip), %rax    # 0x28b298
movq 0x8(%rsp), %rcx
leaq (%rcx,%rcx,4), %r15
leaq (%rax,%r15,8), %r12
movl 0xc(%r12), %eax
cmpq %rax, %rsi
jbe 0x3a091
movl %esi, 0xc(%r12)
movq (%r12), %rdi
shlq $0x2, %rsi
movabsq $0x3fffffffc, %rax      # imm = 0x3FFFFFFFC
andq %rax, %rsi
callq 0x2370
movq %rax, (%r12)
movq 0x120(%r13), %rdx
movl %edx, 0x8(%r12)
movq (%r12), %rdi
movq 0x110(%r13), %rsi
shlq $0x2, %rdx
callq 0x2160
movq 0x140(%r13), %rax
movl 0x1c(%r12), %ecx
cmpq %rcx, %rax
jbe 0x3a0d8
movl %eax, 0x1c(%r12)
movq 0x10(%r12), %rdi
movl %eax, %esi
callq 0x2370
movq %rax, 0x10(%r12)
movq 0x140(%r13), %rdx
movl %edx, 0x18(%r12)
movq 0x10(%r12), %rdi
movq 0x130(%r13), %rsi
callq 0x2160
movl 0x128(%r13), %eax
movl %eax, 0x20(%r12)
movq 0x251198(%rip), %rax    # 0x28b2a0
movq 0x120c8(%r13), %rsi
leaq (%rax,%r15,8), %r15
movl 0xc(%r15), %eax
cmpq %rax, %rsi
jbe 0x3a13c
movl %esi, 0xc(%r15)
movq (%r15), %rdi
shlq $0x2, %rsi
movabsq $0x3fffffffc, %rax      # imm = 0x3FFFFFFFC
andq %rax, %rsi
callq 0x2370
movq %rax, (%r15)
movq 0x120c8(%r13), %rdx
movl %edx, 0x8(%r15)
movq (%r15), %rdi
movq 0x120b8(%r13), %rsi
shlq $0x2, %rdx
callq 0x2160
movq 0x120e8(%r13), %rax
movl 0x1c(%r15), %ecx
cmpq %rcx, %rax
jbe 0x3a17d
movl %eax, 0x1c(%r15)
movq 0x10(%r15), %rdi
movl %eax, %esi
callq 0x2370
movq %rax, 0x10(%r15)
sarq $0x20, %r14
movq 0x120e8(%r13), %rdx
movl %edx, 0x18(%r15)
movq 0x10(%r15), %rdi
movq 0x120d8(%r13), %rsi
callq 0x2160
movl 0x120d0(%r13), %eax
movl %eax, 0x20(%r15)
movq 0x2510fa(%rip), %rax    # 0x28b2a8
movq 0x8(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movb $0x0, 0x10(%rax,%rcx,8)
cmpl $0x0, 0x34(%rsp)
je 0x3a24e
movq 0x120(%r13), %rdx
testq %rdx, %rdx
jle 0x3a205
movq 0x110(%r13), %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 0x3a1df
testl %r8d, %r8d
jne 0x3a24e
movq 0x120c8(%r13), %rdx
testq %rdx, %rdx
jle 0x3a243
movq 0x120b8(%r13), %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 0x3a21d
testl %r8d, %r8d
jne 0x3a24e
leaq (%rax,%rcx,8), %rdx
addq $0x10, %rdx
movb $0x1, (%rdx)
movb 0x30(%rsp), %dl
movb %dl, 0x11(%rax,%rcx,8)
leaq 0x251093(%rip), %rdi    # 0x28b2f0
callq 0x22c0
movq 0x25106f(%rip), %rdi    # 0x28b2d8
movq 0x251000(%rip), %rax    # 0x28b270
movq 0x8(%rsp), %rbx
movl 0x8(%rax,%rbx,8), %edx
movq (%rax,%rbx,8), %rcx
subl %ecx, %edx
addq 0x250fb2(%rip), %rcx    # 0x28b238
leaq 0x1eae09(%rip), %rsi    # 0x225096
movq %rbx, %r8
xorl %eax, %eax
callq 0x22b0
movq 0x25103a(%rip), %rdi    # 0x28b2d8
leaq 0x2504b3(%rip), %rsi    # 0x28a758
movl 0xf8(%rsi), %edx
movq 0x250f96(%rip), %rax    # 0x28b248
movq (%rax,%rbx,8), %rcx
movl 0xd0(%rsi), %r8d
movl 0xe8(%rsi), %r9d
leaq 0x1eaddd(%rip), %rsi    # 0x2250a8
xorl %eax, %eax
callq 0x22b0
movq 0x250fff(%rip), %rdi    # 0x28b2d8
movq 0x250ff0(%rip), %rax    # 0x28b2d0
shlq $0x5, %r14
movl (%rax,%r14), %edx
leaq 0x1eadee(%rip), %rsi    # 0x2250dd
xorl %eax, %eax
callq 0x22b0
movq 0x250fd3(%rip), %rdi    # 0x28b2d0
addq %r14, %rdi
xorl %esi, %esi
callq 0x9fc63
movq 0x250fc2(%rip), %rax    # 0x28b2d0
cmpq $0x0, (%rax,%r14)
je 0x3a35e
leaq 0x1eae0a(%rip), %r15    # 0x225126
xorl %r12d, %r12d
movq 0x250fb2(%rip), %rdi    # 0x28b2d8
movq 0x10(%rax,%r14), %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 0x250f78(%rip), %rax    # 0x28b2d0
cmpq (%rax,%r14), %r12
jb 0x3a31f
movq 0x250f73(%rip), %rcx    # 0x28b2d8
leaq 0x1eaddf(%rip), %rdi    # 0x22514b
movl $0x43, %esi
movl $0x1, %edx
callq 0x2410
cmpq $0x0, 0xb0(%r13)
movq 0x10(%rsp), %r14
je 0x3a444
xorl %ebx, %ebx
xorl %ebp, %ebp
movq (%r14), %rax
cmpb $0x1, 0x2c(%rax,%rbx)
jne 0x3a42d
movq 0x250f31(%rip), %rdi    # 0x28b2d8
movq 0x250ec2(%rip), %rcx    # 0x28b270
movl 0x10(%rax,%rbx), %eax
leal 0x1(%rax), %edx
movl (%rcx,%rdx,8), %edx
movq (%rcx,%rax,8), %rcx
subl %ecx, %edx
addq 0x250e73(%rip), %rcx    # 0x28b238
leaq 0x1ffaea(%rip), %rsi    # 0x239eb6
xorl %eax, %eax
callq 0x22b0
movq 0x250efe(%rip), %rdi    # 0x28b2d8
movq (%r14), %rax
movl 0x4(%rax,%rbx), %edx
movl 0x8(%rax,%rbx), %ecx
movl 0x14(%rax,%rbx), %r8d
movl 0x18(%rax,%rbx), %r9d
movl 0x1c(%rax,%rbx), %r10d
movsbl 0x2e(%rax,%rbx), %r11d
movzbl 0x2d(%rax,%rbx), %r13d
movq 0x250e41(%rip), %r15    # 0x28b248
movl 0x10(%rax,%rbx), %r12d
leaq 0x1ead7c(%rip), %rsi    # 0x22518f
xorl %eax, %eax
pushq (%r15,%r12,8)
pushq %r13
movq 0x28(%rsp), %r13
pushq %r11
pushq %r10
callq 0x22b0
addq $0x20, %rsp
incq %rbp
addq $0xa8, %rbx
cmpq 0xb0(%r13), %rbp
jb 0x3a392
movq 0x250e8d(%rip), %rcx    # 0x28b2d8
leaq 0x1ead8c(%rip), %rdi    # 0x2251de
movl $0x43, %esi
movl $0x1, %edx
callq 0x2410
cmpq $0x0, 0xb0(%r13)
je 0x3a525
xorl %ebx, %ebx
xorl %ebp, %ebp
movq (%r14), %rax
cmpb $0x2, 0x2c(%rax,%rbx)
jne 0x3a50e
movq 0x250e50(%rip), %rdi    # 0x28b2d8
movq 0x250de1(%rip), %rcx    # 0x28b270
movl 0x10(%rax,%rbx), %eax
leal 0x1(%rax), %edx
movl (%rcx,%rdx,8), %edx
movq (%rcx,%rax,8), %rcx
subl %ecx, %edx
addq 0x250d92(%rip), %rcx    # 0x28b238
leaq 0x1ffa09(%rip), %rsi    # 0x239eb6
xorl %eax, %eax
callq 0x22b0
movq 0x250e1d(%rip), %rdi    # 0x28b2d8
movq (%r14), %rax
movl 0x4(%rax,%rbx), %edx
movl 0x8(%rax,%rbx), %ecx
movl 0x14(%rax,%rbx), %r8d
movl 0x18(%rax,%rbx), %r9d
movl 0x1c(%rax,%rbx), %r10d
movsbl 0x2e(%rax,%rbx), %r11d
movzbl 0x2d(%rax,%rbx), %r13d
movq 0x250d60(%rip), %r15    # 0x28b248
movl 0x10(%rax,%rbx), %r12d
leaq 0x1eac9b(%rip), %rsi    # 0x22518f
xorl %eax, %eax
pushq (%r15,%r12,8)
pushq %r13
movq 0x28(%rsp), %r13
pushq %r11
pushq %r10
callq 0x22b0
addq $0x20, %rsp
incq %rbp
addq $0xa8, %rbx
cmpq 0xb0(%r13), %rbp
jb 0x3a473
movq 0x250d2c(%rip), %rax    # 0x28b258
movq 0x8(%rsp), %rdx
movb $0x0, (%rax,%rdx)
movq 0x250d9c(%rip), %rdi    # 0x28b2d8
movq 0x250d15(%rip), %rax    # 0x28b258
movzbl (%rax,%rdx), %ecx
leaq 0x1eacd4(%rip), %rsi    # 0x225222
xorl %eax, %eax
callq 0x22b0
leaq 0x250d94(%rip), %rdi    # 0x28b2f0
callq 0x2130
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq