// File: /workspace/github_cpp_makefile_star2_O3/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 0x25c170(%rip), %rax    # 0x296448
xorl %ecx, %ecx
movq %rcx, (%rax)
leaq 0x25c15c(%rip), %rax    # 0x296440
movq %rcx, (%rax)
leaq 0x25c14a(%rip), %r12    # 0x296438
movb $0x1, %r13b
cmpq %rcx, (%r12)
jne 0x3a311
leaq 0x25b45a(%rip), %rax    # 0x295758
testb $0x4, (%rax)
je 0x3a311
movl 0xf8(%rax), %eax
decl %eax
cmpl %ebp, %eax
setne %r13b
leaq 0x25b440(%rip), %rbx    # 0x295758
movq 0x18(%rbx), %rsi
testq %rsi, %rsi
je 0x3a32d
leaq 0x25bf90(%rip), %rdi    # 0x2962b8
callq 0x3810
movslq 0x7c(%rbx), %r15
movl $0x8, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, %r14
testq %r15, %r15
jle 0x3a372
xorl %r15d, %r15d
movl 0xf8(%rbx), %eax
decl %eax
xorl %esi, %esi
cmpl %ebp, %eax
sete %sil
xorl %edi, %edi
xorl %edx, %edx
callq 0x387f4
movq %rax, (%r14,%r15,8)
incq %r15
movslq 0x7c(%rbx), %rax
cmpq %rax, %r15
jl 0x3a349
cmpq $0x0, (%r12)
je 0x3a385
movl 0xd0(%rbx), %eax
movl %eax, 0x10(%rsp)
jmp 0x3a3bd
leaq 0x25c0a4(%rip), %rax    # 0x296430
movq (%rax), %rsi
xorl %edx, %edx
testl %ebp, %ebp
setne %dl
leaq 0x14(%rsp), %rax
movq %rax, (%rsp)
leaq 0x25b3b2(%rip), %rdi    # 0x295758
leaq 0x25be83(%rip), %r8     # 0x296230
leaq 0x10(%rsp), %r9
xorl %ecx, %ecx
callq 0x13d74
movq %rax, (%r12)
leaq 0x25c06c(%rip), %r15    # 0x296430
testl %ebp, %ebp
jne 0x3a3de
cmpq $0x0, (%r15)
jne 0x3a3de
movl 0x10(%rsp), %esi
leaq 0x25b37f(%rip), %rdi    # 0x295758
callq 0x2f59
movq $0x0, 0x25bfff(%rip) # 0x2963e8
movl 0xf8(%rbx), %eax
decl %eax
cmpl %ebp, %eax
jne 0x3a416
cmpb $0x0, 0x248(%rbx)
je 0x3a416
movq 0x25be7b(%rip), %rdi    # 0x296280
movl $0x4, %esi
callq 0x2120
movq %rax, 0x25bfd2(%rip)    # 0x2963e8
cmpq $0x0, 0x18(%rbx)
movl 0x7c(%rbx), %edi
movq 0x25be5b(%rip), %rcx    # 0x296280
leaq -0x93c(%rip), %rax      # 0x39af0
leaq -0x1099(%rip), %rsi     # 0x3939a
cmoveq %rax, %rsi
movq %r14, %rdx
callq 0x108f2c
testb %r13b, %r13b
jne 0x3a45e
movq (%r15), %rdi
movq (%r12), %rsi
movq 0x10(%rbx), %r8
leaq 0x25bdda(%rip), %rdx    # 0x296230
movq %rbx, %rcx
callq 0x11adca
movq (%r12), %rdi
callq 0x1193ff
movq $0x0, (%r12)
movq 0x25bf72(%rip), %rdi    # 0x2963e8
testq %rdi, %rdi
je 0x3a497
callq 0x39f10
movq 0x25bf61(%rip), %rdi    # 0x2963e8
callq 0x2220
movq $0x0, 0x25bf51(%rip) # 0x2963e8
movl 0x7c(%rbx), %r15d
testl %r15d, %r15d
jle 0x3a4f0
xorl %r12d, %r12d
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 0x38c68
addq %rax, 0x1a8(%rbx)
movq (%r14,%r12,8), %rdi
callq 0x38b4b
incq %r12
movslq 0x7c(%rbx), %r15
cmpq %r15, %r12
jl 0x3a4a3
movq %r14, %rdi
callq 0x2220
cmpq $0x0, 0x18(%rbx)
je 0x3a518
movq 0x25bdda(%rip), %rdi    # 0x2962e0
leaq 0x25bdab(%rip), %rsi    # 0x2962b8
xorl %edx, %edx
callq 0x39f21
movl 0x7c(%rbx), %r15d
movslq %r15d, %r12
movl $0x38, %esi
movq %r12, %rdi
callq 0x2120
movq %rax, %r14
testl %r12d, %r12d
jle 0x3a585
xorl %r13d, %r13d
movabsq $0xc3500000c350, %rbp   # imm = 0xC3500000C350
movq %r14, %r12
movq %r12, %rdi
callq 0x32e2d
movq %rbp, 0x20(%r12)
movl $0xc350, %edi           # imm = 0xC350
movl $0x1, %esi
callq 0x2120
movq %rax, 0x28(%r12)
movl $0xc350, %edi           # imm = 0xC350
movl $0x1, %esi
callq 0x2120
movq %rax, 0x30(%r12)
incq %r13
movslq 0x7c(%rbx), %r15
addq $0x38, %r12
cmpq %r15, %r13
jl 0x3a540
movq 0x25bcf4(%rip), %rcx    # 0x296280
leaq 0x91(%rip), %rsi        # 0x3a624
movl %r15d, %edi
movq %r14, %rdx
callq 0x108f2c
cmpl $0x0, 0x7c(%rbx)
jle 0x3a5d4
xorl %r12d, %r12d
movq %r14, %r15
movq %r15, %rdi
callq 0x32d68
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 0x3a5aa
movq %r14, %rdi
callq 0x2220
cmpq $0x0, 0x18(%rbx)
je 0x3a602
movq 0x25bcfe(%rip), %rdi    # 0x2962e8
leaq 0x25bcc7(%rip), %rsi    # 0x2962b8
movl $0x1, %edx
callq 0x39f21
cmpq $0x0, 0x18(%rbx)
jne 0x3a611
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x25bca0(%rip), %rdi    # 0x2962b8
callq 0x33d9e
xorl %edi, %edi
callq 0x2250