// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Assembly.cpp
// Function: ha_overlap_and_correct(int)
void ha_overlap_and_correct(int round)
{
	int i, hom_cov, het_cov, r_out = 0;
	ha_ovec_buf_t **b;
	ha_ecsave_buf_t *e;
    ha_flt_tab_hp = ha_idx_hp = NULL;

    if((ha_idx == NULL)&&(asm_opt.flag & HA_F_VERBOSE_GFA)&&(round == asm_opt.number_of_round - 1))
    {
        r_out = 1;
    }

    if(asm_opt.required_read_name) init_Debug_reads(&R_INF_FLAG, asm_opt.required_read_name); // for debugging only
	// overlap and correct reads
	CALLOC(b, asm_opt.thread_num);
	for (i = 0; i < asm_opt.thread_num; ++i)
		b[i] = ha_ovec_init(0, (round == asm_opt.number_of_round - 1),0);
    if(ha_idx) hom_cov = asm_opt.hom_cov;
	if(ha_idx == NULL) ha_idx = ha_pt_gen(&asm_opt, ha_flt_tab, round == 0? 0 : 1, 0, &R_INF, &hom_cov, &het_cov); // build the index
	///debug_adapter(&asm_opt, &R_INF);
    if (round == 0 && ha_flt_tab == 0) // then asm_opt.hom_cov hasn't been updated
		ha_opt_update_cov(&asm_opt, hom_cov);
    het_cnt = NULL;
    if(round == asm_opt.number_of_round-1 && asm_opt.is_dbg_het_cnt) CALLOC(het_cnt, R_INF.total_reads);
    // fprintf(stderr, "[M::%s-start]\n", __func__);
    // double tt0 = yak_realtime_0();
	if (asm_opt.required_read_name)
		kt_for(asm_opt.thread_num, worker_ovec_related_reads, b, R_INF.total_reads);
	else
		kt_for(asm_opt.thread_num, worker_ovec, b, R_INF.total_reads);///debug_for_fix
    // fprintf(stderr, "[M::%s-end]\n", __func__);
    // fprintf(stderr, "[M::%s::%.3f] ==> chaining\n", __func__, yak_realtime_0()-tt0);
    // exit(1);
    
    if (r_out) write_pt_index(ha_flt_tab, ha_idx, &R_INF, &asm_opt, asm_opt.output_file_name);
	ha_pt_destroy(ha_idx);
	ha_idx = NULL;

    if(het_cnt) {
        print_het_cnt_log(het_cnt); free(het_cnt); het_cnt = NULL;
    }

	// collect statistics
	for (i = 0; i < asm_opt.thread_num; ++i) {
		asm_opt.num_bases += b[i]->num_read_base;
		asm_opt.num_corrected_bases += b[i]->num_correct_base;
		asm_opt.num_recorrected_bases += b[i]->num_recorrect_base;
		asm_opt.mem_buf += ha_ovec_mem(b[i], NULL);
		ha_ovec_destroy(b[i]);
	}
	free(b);
    if (asm_opt.required_read_name) prt_dbg_rs(R_INF_FLAG.fp_r0, &R_INF_FLAG, 0); // for debugging only
    
	// save corrected reads to R_INF
	CALLOC(e, asm_opt.thread_num);
	for (i = 0; i < asm_opt.thread_num; ++i) {
		init_UC_Read(&e[i].g_read);
		e[i].first_round_read_size = e[i].second_round_read_size = 50000;
		CALLOC(e[i].first_round_read, e[i].first_round_read_size);
		CALLOC(e[i].second_round_read, e[i].second_round_read_size);
	}
	kt_for(asm_opt.thread_num, worker_ec_save, e, R_INF.total_reads);
	for (i = 0; i < asm_opt.thread_num; ++i) {
		destory_UC_Read(&e[i].g_read);
		free(e[i].first_round_read);
		free(e[i].second_round_read);
	}
	free(e);

    if (asm_opt.required_read_name) prt_dbg_rs(R_INF_FLAG.fp_r1, &R_INF_FLAG, 1); // for debugging only
    if (asm_opt.required_read_name) destory_Debug_reads(&R_INF_FLAG), exit(0); // for debugging only
    ///debug_print_pob_regions();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edi, %ebp
leaq 0x25071c(%rip), %rax    # 0x28b448
xorl %ecx, %ecx
movq %rcx, (%rax)
leaq 0x250708(%rip), %rax    # 0x28b440
movq %rcx, (%rax)
leaq 0x2506f6(%rip), %r12    # 0x28b438
movb $0x1, %r13b
cmpq %rcx, (%r12)
jne 0x3ad65
leaq 0x24fa06(%rip), %rax    # 0x28a758
testb $0x4, (%rax)
je 0x3ad65
movl 0xf8(%rax), %eax
decl %eax
cmpl %ebp, %eax
setne %r13b
leaq 0x24f9ec(%rip), %rbx    # 0x28a758
movq 0x18(%rbx), %rsi
testq %rsi, %rsi
je 0x3ad81
leaq 0x25053c(%rip), %rdi    # 0x28b2b8
callq 0x3805
movslq 0x7c(%rbx), %r15
movl $0x8, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, %r14
testq %r15, %r15
jle 0x3adc6
xorl %r15d, %r15d
movl 0xf8(%rbx), %eax
decl %eax
xorl %esi, %esi
cmpl %ebp, %eax
sete %sil
xorl %edi, %edi
xorl %edx, %edx
callq 0x39240
movq %rax, (%r14,%r15,8)
incq %r15
movslq 0x7c(%rbx), %rax
cmpq %rax, %r15
jl 0x3ad9d
cmpq $0x0, (%r12)
je 0x3add9
movl 0xd0(%rbx), %eax
movl %eax, 0x10(%rsp)
jmp 0x3ae11
leaq 0x250650(%rip), %rax    # 0x28b430
movq (%rax), %rsi
xorl %edx, %edx
testl %ebp, %ebp
setne %dl
leaq 0x14(%rsp), %rax
movq %rax, (%rsp)
leaq 0x24f95e(%rip), %rdi    # 0x28a758
leaq 0x25042f(%rip), %r8     # 0x28b230
leaq 0x10(%rsp), %r9
xorl %ecx, %ecx
callq 0x1448a
movq %rax, (%r12)
leaq 0x250618(%rip), %r15    # 0x28b430
testl %ebp, %ebp
jne 0x3ae32
cmpq $0x0, (%r15)
jne 0x3ae32
movl 0x10(%rsp), %esi
leaq 0x24f92b(%rip), %rdi    # 0x28a758
callq 0x2f59
movq $0x0, 0x2505ab(%rip) # 0x28b3e8
movl 0xf8(%rbx), %eax
decl %eax
cmpl %ebp, %eax
jne 0x3ae6a
cmpb $0x0, 0x248(%rbx)
je 0x3ae6a
movq 0x250427(%rip), %rdi    # 0x28b280
movl $0x4, %esi
callq 0x2120
movq %rax, 0x25057e(%rip)    # 0x28b3e8
cmpq $0x0, 0x18(%rbx)
movl 0x7c(%rbx), %edi
movq 0x250407(%rip), %rcx    # 0x28b280
leaq -0x910(%rip), %rax      # 0x3a570
leaq -0x1074(%rip), %rsi     # 0x39e13
cmoveq %rax, %rsi
movq %r14, %rdx
callq 0x1047b4
testb %r13b, %r13b
jne 0x3aeb2
movq (%r15), %rdi
movq (%r12), %rsi
movq 0x10(%rbx), %r8
leaq 0x250386(%rip), %rdx    # 0x28b230
movq %rbx, %rcx
callq 0x115289
movq (%r12), %rdi
callq 0x113930
movq $0x0, (%r12)
movq 0x25051e(%rip), %rdi    # 0x28b3e8
testq %rdi, %rdi
je 0x3aeeb
callq 0x3a97a
movq 0x25050d(%rip), %rdi    # 0x28b3e8
callq 0x2220
movq $0x0, 0x2504fd(%rip) # 0x28b3e8
cmpl $0x0, 0x7c(%rbx)
jle 0x3af45
xorl %r15d, %r15d
movq (%r14,%r15,8), %rdi
movq 0xf0(%rdi), %rax
addq %rax, 0x190(%rbx)
movq 0xf8(%rdi), %rax
addq %rax, 0x198(%rbx)
movq 0x100(%rdi), %rax
addq %rax, 0x1a0(%rbx)
xorl %esi, %esi
callq 0x396ea
addq %rax, 0x1a8(%rbx)
movq (%r14,%r15,8), %rdi
callq 0x395cd
incq %r15
movslq 0x7c(%rbx), %rax
cmpq %rax, %r15
jl 0x3aef4
movq %r14, %rdi
callq 0x2220
cmpq $0x0, 0x18(%rbx)
je 0x3af69
movq 0x250385(%rip), %rdi    # 0x28b2e0
leaq 0x250356(%rip), %rsi    # 0x28b2b8
xorl %edx, %edx
callq 0x3a98b
movslq 0x7c(%rbx), %r12
movl $0x38, %esi
movq %r12, %rdi
callq 0x2120
movq %rax, %r14
testq %r12, %r12
jle 0x3afd4
xorl %r13d, %r13d
movabsq $0xc3500000c350, %rbp   # imm = 0xC3500000C350
movq %r14, %r15
movq %r15, %rdi
callq 0x3372c
movq %rbp, 0x20(%r15)
movl $0xc350, %edi           # imm = 0xC350
movl $0x1, %esi
callq 0x2120
movq %rax, 0x28(%r15)
movl $0xc350, %edi           # imm = 0xC350
movl $0x1, %esi
callq 0x2120
movq %rax, 0x30(%r15)
incq %r13
movslq 0x7c(%rbx), %r12
addq $0x38, %r15
cmpq %r12, %r13
jl 0x3af92
movq 0x2502a5(%rip), %rcx    # 0x28b280
leaq 0x91(%rip), %rsi        # 0x3b073
movl %r12d, %edi
movq %r14, %rdx
callq 0x1047b4
cmpl $0x0, 0x7c(%rbx)
jle 0x3b023
xorl %r12d, %r12d
movq %r14, %r15
movq %r15, %rdi
callq 0x33667
movq 0x28(%r15), %rdi
callq 0x2220
movq 0x30(%r15), %rdi
callq 0x2220
incq %r12
movslq 0x7c(%rbx), %rax
addq $0x38, %r15
cmpq %rax, %r12
jl 0x3aff9
movq %r14, %rdi
callq 0x2220
cmpq $0x0, 0x18(%rbx)
je 0x3b04a
movq 0x2502af(%rip), %rdi    # 0x28b2e8
leaq 0x250278(%rip), %rsi    # 0x28b2b8
movl $0x1, %edx
callq 0x3a98b
cmpq $0x0, 0x18(%rbx)
jne 0x3b060
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x250251(%rip), %rdi    # 0x28b2b8
callq 0x34775
xorl %edi, %edi
callq 0x2250