// File: /workspace/github_cpp_makefile_star2_O3/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)
movl %esi, 0xc(%rsp)
movq %rdi, %r12
leaq 0x25c441(%rip), %rax    # 0x296448
xorl %edx, %edx
movq %rdx, (%rax)
leaq 0x25c42d(%rip), %rax    # 0x296440
movq %rdx, (%rax)
movq %rdx, (%r8)
movq %rcx, 0x18(%rsp)
movq %rdx, (%rcx)
leaq 0x25c410(%rip), %rax    # 0x296438
movq (%rax), %rax
movb $0x1, %r13b
testq %rax, %rax
jne 0x3a050
leaq 0x25b71e(%rip), %rcx    # 0x295758
testb $0x4, (%rcx)
je 0x3a050
movslq 0xf8(%rcx), %rcx
decq %rcx
cmpq %r12, %rcx
setne %r13b
leaq 0x25b701(%rip), %rbx    # 0x295758
movq 0x18(%rbx), %rsi
testq %rsi, %rsi
je 0x3a076
leaq 0x25c251(%rip), %rdi    # 0x2962b8
callq 0x3810
leaq 0x25c3c5(%rip), %rax    # 0x296438
movq (%rax), %rax
testq %rax, %rax
je 0x3a087
movl 0xd0(%rbx), %esi
movl %esi, 0x14(%rsp)
jmp 0x3a0d7
leaq 0x25c3a2(%rip), %rax    # 0x296430
movq (%rax), %rsi
xorl %edx, %edx
testq %r12, %r12
setne %dl
leaq 0x24(%rsp), %r14
movq %r14, (%rsp)
leaq 0x25c187(%rip), %r8     # 0x296230
leaq 0x14(%rsp), %rbp
movq %rbx, %rdi
xorl %ecx, %ecx
movq %rbp, %r9
callq 0x13d74
leaq 0x25c376(%rip), %rcx    # 0x296438
movq %rax, (%rcx)
movl (%rbp), %esi
movl %esi, 0xd0(%rbx)
movl (%r14), %eax
movl %eax, 0xd4(%rbx)
leaq 0x25c352(%rip), %rbp    # 0x296430
testq %r12, %r12
jne 0x3a0f6
cmpq $0x0, (%rbp)
jne 0x3a0f6
leaq 0x25b667(%rip), %rdi    # 0x295758
callq 0x2f59
movq $0x0, 0x25c2e7(%rip) # 0x2963e8
movslq 0xf8(%rbx), %r14
decq %r14
cmpq %r12, %r14
jne 0x3a131
cmpb $0x0, 0x248(%rbx)
je 0x3a131
movq 0x25c160(%rip), %rdi    # 0x296280
movl $0x4, %esi
callq 0x2120
movq %rax, 0x25c2b7(%rip)    # 0x2963e8
testb %r13b, %r13b
jne 0x3a161
movq (%rbp), %rdi
leaq 0x25c2f7(%rip), %rax    # 0x296438
movq (%rax), %rsi
movq 0x10(%rbx), %r8
leaq 0x25c0e1(%rip), %rdx    # 0x296230
movq %rbx, %rcx
callq 0x11adca
movslq 0xf8(%rbx), %r14
decq %r14
movslq 0x7c(%rbx), %rdi
movslq 0xc(%rsp), %rdx
movq 0x25c10f(%rip), %rcx    # 0x296280
xorl %r8d, %r8d
cmpq %r12, %r14
sete %r8b
movq %r15, (%rsp)
movq %r12, %rsi
movq 0x18(%rsp), %r9
callq 0x222fe
cmpl $0x0, 0x10(%rsp)
je 0x3a1a9
leaq 0x25c29e(%rip), %r14    # 0x296438
movq (%r14), %rdi
callq 0x1193ff
movq $0x0, (%r14)
movq 0x25c238(%rip), %rdi    # 0x2963e8
testq %rdi, %rdi
je 0x3a1d1
callq 0x39f10
movq 0x25c227(%rip), %rdi    # 0x2963e8
callq 0x2220
movq $0x0, 0x25c217(%rip) # 0x2963e8
cmpq $0x0, 0x18(%rbx)
je 0x3a213
movq 0x25c101(%rip), %rdi    # 0x2962e0
leaq 0x25c0d2(%rip), %rsi    # 0x2962b8
xorl %edx, %edx
callq 0x39f21
cmpq $0x0, 0x18(%rbx)
je 0x3a213
movq 0x25c0ed(%rip), %rdi    # 0x2962e8
leaq 0x25c0b6(%rip), %rsi    # 0x2962b8
movl $0x1, %edx
callq 0x39f21
cmpq $0x0, 0x18(%rbx)
jne 0x3a222
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x25c08f(%rip), %rdi    # 0x2962b8
callq 0x33d9e
xorl %edi, %edi
callq 0x2250