// File: /workspace/github_cpp_makefile_star2_O1/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, 0x18(%rsp)
movl %esi, 0x14(%rsp)
movq %rdi, %r12
leaq 0x2509dc(%rip), %rax    # 0x28b448
xorl %edx, %edx
movq %rdx, (%rax)
leaq 0x2509c8(%rip), %rax    # 0x28b440
movq %rdx, (%rax)
movq %rdx, (%r8)
movq %rcx, 0x20(%rsp)
movq %rdx, (%rcx)
leaq 0x2509ab(%rip), %r14    # 0x28b438
movb $0x1, %r13b
cmpq %rdx, (%r14)
jne 0x3aab2
leaq 0x24fcbc(%rip), %rax    # 0x28a758
testb $0x4, (%rax)
je 0x3aab2
movslq 0xf8(%rax), %rax
decq %rax
cmpq %r12, %rax
setne %r13b
leaq 0x24fc9f(%rip), %rbx    # 0x28a758
movq 0x18(%rbx), %rsi
testq %rsi, %rsi
je 0x3aace
leaq 0x2507ef(%rip), %rdi    # 0x28b2b8
callq 0x3805
cmpq $0x0, (%r14)
je 0x3aae3
movq %r14, %rbp
movl 0xd0(%rbx), %eax
movl %eax, 0x10(%rsp)
jmp 0x3ab34
leaq 0x250946(%rip), %rax    # 0x28b430
movq (%rax), %rsi
xorl %edx, %edx
testq %r12, %r12
setne %dl
leaq 0x1c(%rsp), %rax
movq %rax, (%rsp)
leaq 0x25072b(%rip), %r8     # 0x28b230
leaq 0x10(%rsp), %r9
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x1448a
movq %r14, %rbp
movq %rax, (%r14)
leaq 0x10(%rsp), %rax
movl (%rax), %eax
movl %eax, 0xd0(%rbx)
leaq 0x1c(%rsp), %rax
movl (%rax), %eax
movl %eax, 0xd4(%rbx)
leaq 0x2508f5(%rip), %r14    # 0x28b430
testq %r12, %r12
jne 0x3ab56
cmpq $0x0, (%r14)
jne 0x3ab56
movl 0x10(%rsp), %esi
leaq 0x24fc07(%rip), %rdi    # 0x28a758
callq 0x2f59
movq $0x0, 0x250887(%rip) # 0x28b3e8
movslq 0xf8(%rbx), %rax
decq %rax
cmpq %r12, %rax
jne 0x3ab91
cmpb $0x0, 0x248(%rbx)
je 0x3ab91
movq 0x250700(%rip), %rdi    # 0x28b280
movl $0x4, %esi
callq 0x2120
movq %rax, 0x250857(%rip)    # 0x28b3e8
testb %r13b, %r13b
jne 0x3abb0
movq (%r14), %rdi
movq (%rbp), %rsi
movq 0x10(%rbx), %r8
leaq 0x250688(%rip), %rdx    # 0x28b230
movq %rbx, %rcx
callq 0x115289
movslq 0x7c(%rbx), %rdi
movslq 0x14(%rsp), %rdx
movq 0x2506c0(%rip), %rcx    # 0x28b280
movslq 0xf8(%rbx), %rax
decq %rax
xorl %r8d, %r8d
cmpq %r12, %rax
sete %r8b
movq %r15, (%rsp)
movq %r12, %rsi
movq 0x20(%rsp), %r9
callq 0x2305e
cmpl $0x0, 0x18(%rsp)
je 0x3abfd
movq (%rbp), %rdi
callq 0x113930
movq $0x0, (%rbp)
movq 0x2507e4(%rip), %rdi    # 0x28b3e8
testq %rdi, %rdi
je 0x3ac25
callq 0x3a97a
movq 0x2507d3(%rip), %rdi    # 0x28b3e8
callq 0x2220
movq $0x0, 0x2507c3(%rip) # 0x28b3e8
cmpq $0x0, 0x18(%rbx)
je 0x3ac41
movq 0x2506ad(%rip), %rdi    # 0x28b2e0
leaq 0x25067e(%rip), %rsi    # 0x28b2b8
xorl %edx, %edx
callq 0x3a98b
cmpq $0x0, 0x18(%rbx)
je 0x3ac60
movq 0x250699(%rip), %rdi    # 0x28b2e8
leaq 0x250662(%rip), %rsi    # 0x28b2b8
movl $0x1, %edx
callq 0x3a98b
cmpq $0x0, 0x18(%rbx)
jne 0x3ac76
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x25063b(%rip), %rdi    # 0x28b2b8
callq 0x34775
xorl %edi, %edi
callq 0x2250