// File: /workspace/github_cpp_makefile_star2_O2/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 $0x28, %rsp
movl %edi, %ebp
leaq 0x246a3c(%rip), %rax    # 0x254448
andq $0x0, (%rax)
leaq 0x246a29(%rip), %rax    # 0x254440
andq $0x0, (%rax)
leaq 0x246a16(%rip), %r15    # 0x254438
movb $0x1, %cl
xorl %eax, %eax
cmpq %rax, (%r15)
jne 0xda44
leaq 0x245d26(%rip), %rax    # 0x253758
testb $0x4, (%rax)
je 0xda44
movl 0xf8(%rax), %eax
decl %eax
cmpl %ebp, %eax
setne %cl
movb %cl, 0x18(%rsp)
leaq 0x245d09(%rip), %rbx    # 0x253758
movq 0x18(%rbx), %rsi
testq %rsi, %rsi
je 0xda64
leaq 0x246859(%rip), %rdi    # 0x2542b8
callq 0x7ab4
movl 0x7c(%rbx), %r12d
movslq %r12d, %rdi
pushq $0x8
popq %rsi
callq 0x2120
movq %rax, %r14
xorl %r13d, %r13d
movslq %r12d, %rax
cmpq %rax, %r13
jge 0xdaa7
movl 0xf8(%rbx), %eax
decl %eax
xorl %esi, %esi
cmpl %ebp, %eax
sete %sil
xorl %edi, %edi
xorl %edx, %edx
callq 0xc44b
movq %rax, (%r14,%r13,8)
incq %r13
movl 0x7c(%rbx), %r12d
jmp 0xda79
cmpq $0x0, (%r15)
je 0xdab9
movl 0xd0(%rbx), %eax
movl %eax, 0x14(%rsp)
jmp 0xdaf0
leaq 0x246970(%rip), %rax    # 0x254430
movq (%rax), %rsi
xorl %edx, %edx
testl %ebp, %ebp
setne %dl
leaq 0x24(%rsp), %rax
movq %rax, (%rsp)
leaq 0x245c7e(%rip), %rdi    # 0x253758
leaq 0x24674f(%rip), %r8     # 0x254230
leaq 0x14(%rsp), %r9
xorl %ecx, %ecx
callq 0xd6a80
movq %rax, (%r15)
leaq 0x246939(%rip), %r13    # 0x254430
testl %ebp, %ebp
jne 0xdb12
cmpq $0x0, (%r13)
jne 0xdb12
movl 0x14(%rsp), %esi
leaq 0x245c4b(%rip), %rdi    # 0x253758
callq 0x3430
andq $0x0, 0x2468ce(%rip)    # 0x2543e8
movl 0xf8(%rbx), %eax
decl %eax
cmpl %ebp, %eax
jne 0xdb45
cmpb $0x0, 0x248(%rbx)
je 0xdb45
movq 0x24674a(%rip), %rdi    # 0x254280
pushq $0x4
popq %rsi
callq 0x2120
movq %rax, 0x2468a3(%rip)    # 0x2543e8
cmpq $0x0, 0x18(%rbx)
movl 0x7c(%rbx), %edi
movq 0x24672c(%rip), %rcx    # 0x254280
leaq -0x836(%rip), %rax      # 0xd325
leaq -0xdad(%rip), %rsi      # 0xcdb5
cmoveq %rax, %rsi
movq %r14, %rdx
callq 0xc67c0
cmpb $0x0, 0x18(%rsp)
jne 0xdb8f
movq (%r13), %rdi
movq (%r15), %rsi
movq 0x10(%rbx), %r8
leaq 0x2466a9(%rip), %rdx    # 0x254230
movq %rbx, %rcx
callq 0xd70bf
movq (%r15), %rdi
callq 0xd4d2f
andq $0x0, (%r15)
movq 0x246846(%rip), %rdi    # 0x2543e8
testq %rdi, %rdi
je 0xdbc0
callq 0xd58f
movq 0x246835(%rip), %rdi    # 0x2543e8
callq 0x2220
andq $0x0, 0x246828(%rip)    # 0x2543e8
xorl %r12d, %r12d
movl 0x7c(%rbx), %ebp
movslq %ebp, %r15
cmpq %r15, %r12
jge 0xdc14
movq (%r14,%r12,8), %rdi
movdqu 0x190(%rbx), %xmm0
paddq 0xf0(%rdi), %xmm0
movdqu %xmm0, 0x190(%rbx)
movq 0x100(%rdi), %rax
addq %rax, 0x1a0(%rbx)
xorl %esi, %esi
callq 0xc6d6
addq %rax, 0x1a8(%rbx)
movq (%r14,%r12,8), %rdi
callq 0xc5d1
incq %r12
jmp 0xdbc3
movq %r14, %rdi
callq 0x2220
cmpq $0x0, 0x18(%rbx)
je 0xdc3e
movq 0x2466b6(%rip), %rdi    # 0x2542e0
leaq 0x246687(%rip), %rsi    # 0x2542b8
xorl %edx, %edx
callq 0xd666
movl 0x7c(%rbx), %ebp
movslq %ebp, %r15
pushq $0x38
popq %rsi
movq %r15, %rdi
callq 0x2120
movq %rax, %r12
xorl %r13d, %r13d
movabsq $0xc3500000c350, %r14   # imm = 0xC3500000C350
pushq $0x1
popq %r15
movq %rax, 0x18(%rsp)
movslq %ebp, %rax
cmpq %rax, %r13
jge 0xdca7
movq %r12, %rdi
callq 0x6bd1
movq %r14, 0x20(%r12)
movl $0xc350, %edi           # imm = 0xC350
movq %r15, %rsi
callq 0x2120
movq %rax, 0x28(%r12)
movl $0xc350, %edi           # imm = 0xC350
movq %r15, %rsi
callq 0x2120
movq %rax, 0x30(%r12)
incq %r13
movl 0x7c(%rbx), %ebp
addq $0x38, %r12
jmp 0xdc62
movq 0x2465d2(%rip), %rcx    # 0x254280
leaq 0x8f(%rip), %rsi        # 0xdd44
movl %ebp, %edi
movq 0x18(%rsp), %r12
movq %r12, %rdx
callq 0xc67c0
xorl %r14d, %r14d
movq %r12, %r15
movslq 0x7c(%rbx), %rax
cmpq %rax, %r14
jge 0xdcf6
movq %r15, %rdi
callq 0x6b07
movq 0x28(%r15), %rdi
callq 0x2220
movq 0x30(%r15), %rdi
callq 0x2220
incq %r14
addq $0x38, %r15
jmp 0xdcca
movq %r12, %rdi
callq 0x2220
cmpq $0x0, 0x18(%rbx)
je 0xdd22
movq 0x2465dc(%rip), %rdi    # 0x2542e8
leaq 0x2465a5(%rip), %rsi    # 0x2542b8
pushq $0x1
popq %rdx
callq 0xd666
cmpq $0x0, 0x18(%rbx)
jne 0xdd31
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x246580(%rip), %rdi    # 0x2542b8
callq 0x7ccd
xorl %edi, %edi
callq 0x2250