// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Assembly.cpp
// Function: ha_ec(long, int, int, unsigned long*, unsigned long*)
void ha_ec(int64_t round, int num_pround, int des_idx, uint64_t *tot_b, uint64_t *tot_e)
{
	int hom_cov, het_cov, r_out = 0;
    ha_flt_tab_hp = ha_idx_hp = NULL; (*tot_b) = (*tot_e) = 0;

    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
    
    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
        asm_opt.hom_cov = hom_cov; asm_opt.het_cov = het_cov;
    }
	///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);

    if (r_out) write_pt_index(ha_flt_tab, ha_idx, &R_INF, &asm_opt, asm_opt.output_file_name);

    // Output_corrected_fastq();


    cal_ec_r(asm_opt.thread_num, round, num_pround, R_INF.total_reads, (round == (asm_opt.number_of_round-1))?1:0, tot_b, tot_e);

    // exit(1);    

    // if (r_out) write_pt_index(ha_flt_tab, ha_idx, &R_INF, &asm_opt, asm_opt.output_file_name);
    if(des_idx) {
        ha_pt_destroy(ha_idx); ha_idx = NULL;
    }
	

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

    // exit(1);


    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
	// sl_ec_r(asm_opt.thread_num, R_INF.total_reads);

    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();

    // Output_corrected_reads();

    // exit(1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %r15
movl %edx, 0x10(%rsp)
leaq 0x246d06(%rip), %rax    # 0x254448
andq $0x0, (%rax)
leaq 0x246cf3(%rip), %rax    # 0x254440
andq $0x0, (%rax)
movl %esi, 0xc(%rsp)
andq $0x0, (%r8)
movq %rdi, %r12
movq %rcx, 0x18(%rsp)
andq $0x0, (%rcx)
leaq 0x246ccc(%rip), %rax    # 0x254438
movq (%rax), %rax
movb $0x1, %r13b
testq %rax, %rax
jne 0xd794
leaq 0x245fda(%rip), %rcx    # 0x253758
testb $0x4, (%rcx)
je 0xd794
movslq 0xf8(%rcx), %rcx
decq %rcx
cmpq %r12, %rcx
setne %r13b
leaq 0x245fbd(%rip), %rbx    # 0x253758
movq 0x18(%rbx), %rsi
testq %rsi, %rsi
je 0xd7ba
leaq 0x246b0d(%rip), %rdi    # 0x2542b8
callq 0x7ab4
leaq 0x246c81(%rip), %rax    # 0x254438
movq (%rax), %rax
testq %rax, %rax
je 0xd7cb
movl 0xd0(%rbx), %esi
movl %esi, 0x14(%rsp)
jmp 0xd81b
leaq 0x246c5e(%rip), %rax    # 0x254430
movq (%rax), %rsi
xorl %edx, %edx
testq %r12, %r12
setne %dl
leaq 0x24(%rsp), %r14
movq %r14, (%rsp)
leaq 0x246a43(%rip), %r8     # 0x254230
leaq 0x14(%rsp), %rbp
movq %rbx, %rdi
xorl %ecx, %ecx
movq %rbp, %r9
callq 0xd6a80
leaq 0x246c32(%rip), %rcx    # 0x254438
movq %rax, (%rcx)
movl (%rbp), %esi
movl %esi, 0xd0(%rbx)
movl (%r14), %eax
movl %eax, 0xd4(%rbx)
leaq 0x246c0e(%rip), %rbp    # 0x254430
testq %r12, %r12
jne 0xd83a
cmpq $0x0, (%rbp)
jne 0xd83a
leaq 0x245f23(%rip), %rdi    # 0x253758
callq 0x3430
andq $0x0, 0x246ba6(%rip)    # 0x2543e8
movslq 0xf8(%rbx), %r14
decq %r14
cmpq %r12, %r14
jne 0xd870
cmpb $0x0, 0x248(%rbx)
je 0xd870
movq 0x246a1f(%rip), %rdi    # 0x254280
pushq $0x4
popq %rsi
callq 0x2120
movq %rax, 0x246b78(%rip)    # 0x2543e8
testb %r13b, %r13b
jne 0xd8a0
movq (%rbp), %rdi
leaq 0x246bb8(%rip), %rax    # 0x254438
movq (%rax), %rsi
movq 0x10(%rbx), %r8
leaq 0x2469a2(%rip), %rdx    # 0x254230
movq %rbx, %rcx
callq 0xd70bf
movslq 0xf8(%rbx), %r14
decq %r14
movslq 0x7c(%rbx), %rdi
movslq 0xc(%rsp), %rdx
movq 0x2469d0(%rip), %rcx    # 0x254280
xorl %r8d, %r8d
cmpq %r12, %r14
sete %r8b
movq %r15, (%rsp)
movq %r12, %rsi
movq 0x18(%rsp), %r9
callq 0x14d72f
cmpl $0x0, 0x10(%rsp)
je 0xd8e5
leaq 0x246b5f(%rip), %r14    # 0x254438
movq (%r14), %rdi
callq 0xd4d2f
andq $0x0, (%r14)
movq 0x246afc(%rip), %rdi    # 0x2543e8
testq %rdi, %rdi
je 0xd90a
callq 0xd58f
movq 0x246aeb(%rip), %rdi    # 0x2543e8
callq 0x2220
andq $0x0, 0x246ade(%rip)    # 0x2543e8
cmpq $0x0, 0x18(%rbx)
je 0xd94a
movq 0x2469c8(%rip), %rdi    # 0x2542e0
leaq 0x246999(%rip), %rsi    # 0x2542b8
xorl %edx, %edx
callq 0xd666
cmpq $0x0, 0x18(%rbx)
je 0xd94a
movq 0x2469b4(%rip), %rdi    # 0x2542e8
leaq 0x24697d(%rip), %rsi    # 0x2542b8
pushq $0x1
popq %rdx
callq 0xd666
cmpq $0x0, 0x18(%rbx)
jne 0xd959
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x246958(%rip), %rdi    # 0x2542b8
callq 0x7ccd
xorl %edi, %edi
callq 0x2250