// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Assembly.cpp
// Function: ha_assemble()
int ha_assemble(void)
{
    // debug_mc_g_t(MC_NAME);
    // debug_mc_gg_t(MC_NAME, 0, 0);
    // quick_debug_phasing(MC_NAME);
	extern void ha_extract_print_list(const All_reads *rs, int n_rounds, const char *o);
	int r, hom_cov = -1, ovlp_loaded = 0; uint64_t tot_b, tot_e;
	if (asm_opt.load_index_from_disk && load_all_data_from_disk(&R_INF.paf, &R_INF.reverse_paf, asm_opt.output_file_name)) {
		ovlp_loaded = 1;
		fprintf(stderr, "[M::%s::%.3f*%.2f] ==> loaded corrected reads and overlaps from disk\n", __func__, yak_realtime(), yak_cpu_usage());
		if (asm_opt.extract_list) {
			ha_extract_print_list(&R_INF, asm_opt.extract_iter, asm_opt.extract_list);
			exit(0);
		}
		if (asm_opt.flag & HA_F_WRITE_EC) {
            if(asm_opt.is_sc) Output_corrected_fastq();
            else Output_corrected_reads();
        }
		if (asm_opt.flag & HA_F_WRITE_PAF) Output_PAF();
        if (asm_opt.het_cov == -1024) hap_recalculate_peaks(asm_opt.output_file_name), ovlp_loaded = 2;
	}
	if (!ovlp_loaded) {
        ha_flt_tab = ha_idx = NULL;
        if((asm_opt.flag & HA_F_VERBOSE_GFA)) load_pt_index(&ha_flt_tab, &ha_idx, &R_INF, &asm_opt, asm_opt.output_file_name), load_ct_index(&ha_ct_table, asm_opt.output_file_name);

		// construct hash table for high occurrence k-mers
		if (!(asm_opt.flag & HA_F_NO_KMER_FLT) && ha_flt_tab == NULL) 
        {
			ha_flt_tab = ha_ft_gen(&asm_opt, &R_INF, &hom_cov, 0, 0);
			ha_opt_update_cov(&asm_opt, hom_cov);
		}
		// error correction
		assert(asm_opt.number_of_round > 0);
		for (r = ha_idx?asm_opt.number_of_round-1:0; r < asm_opt.number_of_round; ++r) {
			ha_opt_reset_to_round(&asm_opt, r); // this update asm_opt.roundID and a few other fields
            tot_b = tot_e = 0;
			// ha_overlap_and_correct(r);
            ha_ec(r, asm_opt.number_of_pround, (r<asm_opt.number_of_round-1)?1:0, &tot_b, &tot_e);
			fprintf(stderr, "[M::%s::%.3f*%.2f@%.3fGB] ==> corrected reads for round %d\n", __func__, yak_realtime(),
					yak_cpu_usage(), yak_peakrss_in_gb(), r + 1);
            fprintf(stderr, "[M::%s] # bases: %lu; # corrected bases: %lu\n", __func__, tot_b, tot_e);
			// fprintf(stderr, "[M::%s] # bases: %lld; # corrected bases: %lld; # recorrected bases: %lld\n", __func__,
			// 		asm_opt.num_bases, asm_opt.num_corrected_bases, asm_opt.num_recorrected_bases);
			// fprintf(stderr, "[M::%s] size of buffer: %.3fGB\n", __func__, asm_opt.mem_buf / 1073741824.0);
		}
		if (asm_opt.flag & HA_F_WRITE_EC) {
            if(asm_opt.is_sc) Output_corrected_fastq();
            else Output_corrected_reads();
        }
		// overlap between corrected reads
		ha_opt_reset_to_round(&asm_opt, asm_opt.number_of_round);
		// ha_overlap_final();
        ha_ec_ff(1/**0**/);
        fprintf(stderr, "[M::%s::%.3f*%.2f@%.3fGB] ==> found overlaps for the final round\n", __func__, yak_realtime(), yak_cpu_usage(), yak_peakrss_in_gb());
		// fprintf(stderr, "\n[M::%s::%.3f*%.2f@%.3fGB] ==> found overlaps for the final round\n", __func__, yak_realtime(), yak_cpu_usage(), yak_peakrss_in_gb());
		// ha_print_ovlp_stat(R_INF.paf, R_INF.reverse_paf, R_INF.total_reads);
		ha_ft_destroy(ha_flt_tab);
		if (asm_opt.flag & HA_F_WRITE_PAF) Output_PAF();
		ha_triobin(&asm_opt);

        // exit(1);
	}
    if(ovlp_loaded == 2) ovlp_loaded = 0;
    ha_opt_update_cov_min(&asm_opt, asm_opt.hom_cov, MIN_N_CHAIN);

    build_string_graph_without_clean(asm_opt.min_overlap_coverage, R_INF.paf, R_INF.reverse_paf, 
        R_INF.total_reads, R_INF.read_length, asm_opt.min_overlap_Len, asm_opt.max_hang_Len, asm_opt.clean_round, 
        asm_opt.gap_fuzz, asm_opt.min_drop_rate, asm_opt.max_drop_rate, asm_opt.output_file_name, asm_opt.large_pop_bubble_size, 0, !ovlp_loaded);
	destory_All_reads(&R_INF);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
orl $-0x1, 0x14(%rsp)
leaq 0x243788(%rip), %rbx    # 0x253758
cmpl $0x0, 0xf0(%rbx)
je 0xfff8
movq 0x10(%rbx), %rdx
leaq 0x2442c4(%rip), %rdi    # 0x2542a8
leaq 0x2442c5(%rip), %rsi    # 0x2542b0
callq 0xa4465
testl %eax, %eax
jne 0x10187
leaq 0x244439(%rip), %r12    # 0x254438
andq $0x0, (%r12)
leaq 0x244425(%rip), %r13    # 0x254430
andq $0x0, (%r13)
movl (%rbx), %ecx
movb $0x1, %al
testb $0x4, %cl
je 0x10050
movq 0x10(%rbx), %r8
leaq 0x244414(%rip), %rsi    # 0x254438
leaq 0x244205(%rip), %rdx    # 0x254230
movq %r13, %rdi
movq %rbx, %rcx
callq 0xd755f
movq 0x10(%rbx), %rsi
leaq 0x24440f(%rip), %rdi    # 0x254450
callq 0xd6e4f
movl (%rbx), %ecx
cmpq $0x0, (%r13)
sete %al
testb $0x2, %cl
jne 0x1008b
testb %al, %al
je 0x1008b
leaq 0x2436f8(%rip), %r14    # 0x253758
leaq 0x2441c9(%rip), %rsi    # 0x254230
leaq 0x14(%rsp), %r15
movq %r14, %rdi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xd61b1
movq %rax, (%r13)
movl (%r15), %esi
movq %r14, %rdi
callq 0x3430
movl 0xf8(%rbx), %eax
testl %eax, %eax
jle 0x10348
movq (%r12), %rcx
leal -0x1(%rax), %r15d
testq %rcx, %rcx
cmoveq %rcx, %r15
movq 0x242f31(%rip), %rbp    # 0x252fe0
leaq 0x1d2ee6(%rip), %r14    # 0x1e2f9c
leaq 0x1d2f39(%rip), %r12    # 0x1e2ff6
cmpl %r15d, %eax
jle 0x10171
movq %rbx, %rdi
movl %r15d, %esi
callq 0x3418
andq $0x0, 0x18(%rsp)
andq $0x0, 0x20(%rsp)
movl 0xf8(%rbx), %eax
movl 0xfc(%rbx), %esi
decl %eax
xorl %edx, %edx
cmpl %r15d, %eax
setg %dl
movq %r15, %rdi
leaq 0x20(%rsp), %rcx
leaq 0x18(%rsp), %r8
callq 0xd726
movq (%rbp), %r13
callq 0xefea7
movsd %xmm0, (%rsp)
callq 0xefef4
movsd %xmm0, 0x8(%rsp)
callq 0xefedf
movaps %xmm0, %xmm2
incq %r15
movq %r13, %rdi
leaq 0x1d2e87(%rip), %rsi    # 0x1e2fba
movq %r14, %rdx
movsd (%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movl %r15d, %ecx
movb $0x3, %al
callq 0x22b0
movq (%rbp), %rdi
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %r8
movq %r12, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x22b0
movl 0xf8(%rbx), %eax
jmp 0x100bd
testb $0x8, (%rbx)
je 0x101f3
cmpq $0x0, 0x2b0(%rbx)
jne 0x101ee
callq 0xc9ba
jmp 0x101f3
movq 0x242e52(%rip), %rax    # 0x252fe0
movq (%rax), %r14
callq 0xefea7
movsd %xmm0, (%rsp)
callq 0xefef4
movaps %xmm0, %xmm1
leaq 0x1d2dac(%rip), %rsi    # 0x1e2f56
leaq 0x1d2deb(%rip), %rdx    # 0x1e2f9c
movq %r14, %rdi
movsd (%rsp), %xmm0
movb $0x2, %al
callq 0x22b0
movq 0x48(%rbx), %rdx
testq %rdx, %rdx
jne 0x10367
testb $0x8, (%rbx)
je 0x10319
cmpq $0x0, 0x2b0(%rbx)
je 0x10314
callq 0xcacd
jmp 0x10319
callq 0xcacd
movl 0xf8(%rbx), %esi
movq %rbx, %rdi
callq 0x3418
pushq $0x1
popq %r15
movl %r15d, %edi
callq 0xfb20
movq (%rbp), %r14
callq 0xefea7
movsd %xmm0, (%rsp)
callq 0xefef4
movsd %xmm0, 0x8(%rsp)
callq 0xefedf
movaps %xmm0, %xmm2
leaq 0x1d2def(%rip), %rsi    # 0x1e3024
leaq 0x1d2d60(%rip), %rdx    # 0x1e2f9c
movq %r14, %rdi
movsd (%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movb $0x3, %al
callq 0x22b0
leaq 0x2441d8(%rip), %rax    # 0x254430
movq (%rax), %rdi
callq 0xd5c37
testb $0x10, (%rbx)
je 0x1026a
callq 0xed58
leaq 0x2434e7(%rip), %rdi    # 0x253758
callq 0xc55cf
movl 0xd0(%rbx), %esi
pushq $0x64
popq %rdx
movq %rbx, %rdi
callq 0x347f
movl 0x118(%rbx), %edi
leaq 0x243f9c(%rip), %r14    # 0x254230
movq 0x24400d(%rip), %rsi    # 0x2542a8
movq 0x24400e(%rip), %rdx    # 0x2542b0
movq 0x243fd7(%rip), %rcx    # 0x254280
movq 0x243f98(%rip), %r8     # 0x254248
movslq 0x114(%rbx), %r9
movslq 0x10c(%rbx), %rax
movslq 0x104(%rbx), %r10
movslq 0x110(%rbx), %r11
movss 0x15c(%rbx), %xmm0
movss 0x160(%rbx), %xmm1
subq $0x8, %rsp
pushq %r15
pushq $0x0
pushq 0x188(%rbx)
pushq 0x10(%rbx)
pushq %r11
pushq %r10
pushq %rax
callq 0xc28fd
addq $0x40, %rsp
movq %r14, %rdi
callq 0x5891
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xc9ba
testb $0x10, (%rbx)
je 0x10323
callq 0xed58
xorl %r15d, %r15d
cmpl $0xfffffc00, 0xd4(%rbx) # imm = 0xFFFFFC00
jne 0x10276
movq 0x10(%rbx), %rdi
callq 0xf733
pushq $0x1
popq %r15
jmp 0x10276
leaq 0x1d2b96(%rip), %rdi    # 0x1e2ee5
leaq 0x1d2bab(%rip), %rsi    # 0x1e2f01
leaq 0x1d2c4b(%rip), %rcx    # 0x1e2fa8
movl $0x827, %edx            # imm = 0x827
callq 0x2110
movl 0x78(%rbx), %esi
leaq 0x243ebf(%rip), %rdi    # 0x254230
callq 0xefd48
xorl %edi, %edi
callq 0x2250