// File: 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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movl $0x0, -0x2c(%rbp)
leaq 0x3ae980(%rip), %rax    # 0x3c54e8
movq $0x0, (%rax)
leaq 0x3ae96a(%rip), %rax    # 0x3c54e0
movq $0x0, (%rax)
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
leaq 0x3ae93e(%rip), %rax    # 0x3c54d8
cmpq $0x0, (%rax)
jne 0x16bd4
leaq 0x3adc51(%rip), %rax    # 0x3c47f8
movl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x16bd4
movq -0x8(%rbp), %rax
leaq 0x3adc3c(%rip), %rcx    # 0x3c47f8
movl 0xf8(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jne 0x16bd4
movl $0x1, -0x2c(%rbp)
leaq 0x3adc1d(%rip), %rax    # 0x3c47f8
cmpq $0x0, 0x18(%rax)
je 0x16bf9
leaq 0x3adc0f(%rip), %rax    # 0x3c47f8
movq 0x18(%rax), %rsi
leaq 0x3ae764(%rip), %rdi    # 0x3c5358
callq 0xb750
leaq 0x3ae8d8(%rip), %rax    # 0x3c54d8
cmpq $0x0, (%rax)
je 0x16c16
leaq 0x3adbeb(%rip), %rax    # 0x3c47f8
movl 0xd0(%rax), %eax
movl %eax, -0x24(%rbp)
leaq 0x3ae8bb(%rip), %rax    # 0x3c54d8
cmpq $0x0, (%rax)
jne 0x16c8d
leaq 0x3ae8a6(%rip), %rax    # 0x3c54d0
movq (%rax), %rsi
movq -0x8(%rbp), %rcx
movl $0x1, %edx
xorl %eax, %eax
cmpq $0x0, %rcx
cmovel %eax, %edx
leaq 0x3adbb2(%rip), %rdi    # 0x3c47f8
xorl %ecx, %ecx
leaq 0x3ae681(%rip), %r8     # 0x3c52d0
leaq -0x24(%rbp), %r9
leaq -0x28(%rbp), %rax
movq %rax, (%rsp)
callq 0x18a180
movq %rax, %rcx
leaq 0x3ae86e(%rip), %rax    # 0x3c54d8
movq %rcx, (%rax)
movl -0x24(%rbp), %ecx
leaq 0x3adb81(%rip), %rax    # 0x3c47f8
movl %ecx, 0xd0(%rax)
movl -0x28(%rbp), %ecx
leaq 0x3adb71(%rip), %rax    # 0x3c47f8
movl %ecx, 0xd4(%rax)
cmpq $0x0, -0x8(%rbp)
jne 0x16cb0
leaq 0x3ae835(%rip), %rax    # 0x3c54d0
cmpq $0x0, (%rax)
jne 0x16cb0
movl -0x24(%rbp), %esi
leaq 0x3adb4d(%rip), %rdi    # 0x3c47f8
callq 0x3b60
movq $0x0, 0x3ae7cd(%rip) # 0x3c5488
movq -0x8(%rbp), %rax
leaq 0x3adb32(%rip), %rcx    # 0x3c47f8
movl 0xf8(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jne 0x16cff
leaq 0x3adb1a(%rip), %rax    # 0x3c47f8
cmpb $0x0, 0x248(%rax)
je 0x16cff
movq 0x3ae632(%rip), %rdi    # 0x3c5320
movl $0x4, %esi
callq 0x2140
movq %rax, 0x3ae789(%rip)    # 0x3c5488
cmpl $0x0, -0x2c(%rbp)
je 0x16d37
leaq 0x3ae7c4(%rip), %rax    # 0x3c54d0
movq (%rax), %rdi
leaq 0x3ae7c2(%rip), %rax    # 0x3c54d8
movq (%rax), %rsi
leaq 0x3adad8(%rip), %rax    # 0x3c47f8
movq 0x10(%rax), %r8
leaq 0x3ae5a5(%rip), %rdx    # 0x3c52d0
leaq 0x3adac6(%rip), %rcx    # 0x3c47f8
callq 0x18aa10
leaq 0x3adaba(%rip), %rax    # 0x3c47f8
movslq 0x7c(%rax), %rdi
movq -0x8(%rbp), %rsi
movslq -0xc(%rbp), %rdx
movq 0x3ae5cf(%rip), %rcx    # 0x3c5320
movq -0x8(%rbp), %r9
leaq 0x3ada9c(%rip), %rax    # 0x3c47f8
movl 0xf8(%rax), %eax
subl $0x1, %eax
movslq %eax, %r10
xorl %eax, %eax
movl $0x1, %r8d
cmpq %r10, %r9
cmovel %r8d, %eax
movslq %eax, %r8
movq -0x18(%rbp), %r9
movq -0x20(%rbp), %rax
movq %rax, (%rsp)
callq 0x269a40
cmpl $0x0, -0x10(%rbp)
je 0x16dae
leaq 0x3ae740(%rip), %rax    # 0x3c54d8
movq (%rax), %rdi
callq 0x187660
leaq 0x3ae731(%rip), %rax    # 0x3c54d8
movq $0x0, (%rax)
cmpq $0x0, 0x3ae6d2(%rip)    # 0x3c5488
je 0x16ddb
movq 0x3ae6c9(%rip), %rdi    # 0x3c5488
callq 0x16930
movq 0x3ae6bd(%rip), %rdi    # 0x3c5488
callq 0x2210
movq $0x0, 0x3ae6ad(%rip) # 0x3c5488
leaq 0x3ada16(%rip), %rax    # 0x3c47f8
cmpq $0x0, 0x18(%rax)
je 0x16e00
movq 0x3ae590(%rip), %rdi    # 0x3c5380
leaq 0x3ae561(%rip), %rsi    # 0x3c5358
xorl %eax, %eax
movl %eax, %edx
callq 0x16a50
leaq 0x3ad9f1(%rip), %rax    # 0x3c47f8
cmpq $0x0, 0x18(%rax)
je 0x16e26
movq 0x3ae573(%rip), %rdi    # 0x3c5388
leaq 0x3ae53c(%rip), %rsi    # 0x3c5358
movl $0x1, %edx
callq 0x16a50
leaq 0x3ad9cb(%rip), %rax    # 0x3c47f8
cmpq $0x0, 0x18(%rax)
je 0x16e47
leaq 0x3ae51d(%rip), %rdi    # 0x3c5358
callq 0xbaa0
xorl %edi, %edi
callq 0x2240
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)