// File: chhylp123[P]hifiasm/Assembly.cpp
// Function: ha_assemble_pair()
int ha_assemble_pair(void)
{
	extern void ha_extract_print_list(const All_reads *rs, int n_rounds, const char *o);
	int r = 0, hom_cov = -1, ovlp_loaded = 0; memset((&R_INF), 0, sizeof(R_INF));

	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) 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) {
        
        if(!append_All_reads(&R_INF, asm_opt.output_file_name, 0)) {
            fprintf(stderr, "[M::%s::] Cannot load %s.0\n", __func__, asm_opt.output_file_name); 
            exit(1);
        }

        if(!append_All_reads(&R_INF, asm_opt.output_file_name, 1)) {
            fprintf(stderr, "[M::%s::] Cannot load %s.1\n", __func__, asm_opt.output_file_name); 
            exit(1);
        }
        // Output_corrected_reads(); exit(0);

        ha_flt_tab = ha_idx = NULL; r = asm_opt.number_of_round - 1;
        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, 1);
            ha_opt_update_cov(&asm_opt, hom_cov);
        }
        // error correction
        assert(asm_opt.number_of_round > 0);
        ha_opt_reset_to_round(&asm_opt, r); // this update asm_opt.roundID and a few other fields
        ha_overlap_cal(r, 1);
        fprintf(stderr, "[M::%s] size of buffer: %.3fGB\n", __func__, asm_opt.mem_buf / 1073741824.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());
        

        if (asm_opt.flag & HA_F_WRITE_EC) Output_corrected_reads();
        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);

	}
    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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x70, %rsp
movl $0x0, -0x24(%rbp)
movl $0xffffffff, -0x28(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x2c(%rbp)
leaq 0x3a98f5(%rip), %rdi    # 0x3c52d0
xorl %esi, %esi
movl $0x88, %edx
callq 0x2100
leaq 0x3a8e0a(%rip), %rax    # 0x3c47f8
cmpl $0x0, 0xf0(%rax)
je 0x1bafc
leaq 0x3a8df6(%rip), %rax    # 0x3c47f8
movq 0x10(%rax), %rdx
leaq 0x3a98c3(%rip), %rsi    # 0x3c52d0
movq %rsi, %rdi
addq $0x78, %rdi
addq $0x80, %rsi
callq 0x133660
cmpl $0x0, %eax
je 0x1bafc
movl $0x1, -0x2c(%rbp)
movq 0x3a85a9(%rip), %rax    # 0x3c3fe0
movq (%rax), %rax
movq %rax, -0x40(%rbp)
callq 0x1b7ca0
movsd %xmm0, -0x38(%rbp)
callq 0x1b7d20
movq -0x40(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0x38(%rbp), %xmm0
leaq 0x366230(%rip), %rsi    # 0x381c90
leaq 0x366339(%rip), %rdx    # 0x381da0
movb $0x2, %al
callq 0x22a0
leaq 0x3a8d83(%rip), %rax    # 0x3c47f8
cmpq $0x0, 0x48(%rax)
je 0x1baa4
leaq 0x3a8d75(%rip), %rax    # 0x3c47f8
movl 0x78(%rax), %esi
leaq 0x3a8d6b(%rip), %rax    # 0x3c47f8
movq 0x48(%rax), %rdx
leaq 0x3a9838(%rip), %rdi    # 0x3c52d0
callq 0x1b6510
xorl %edi, %edi
callq 0x2240
leaq 0x3a8d4d(%rip), %rax    # 0x3c47f8
movl (%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x1baba
callq 0x15610
leaq 0x3a8d37(%rip), %rax    # 0x3c47f8
movl (%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x1bad0
callq 0x198d0
leaq 0x3a8d21(%rip), %rax    # 0x3c47f8
cmpl $0xfffffc00, 0xd4(%rax) # imm = 0xFFFFFC00
jne 0x1bafa
leaq 0x3a8d0e(%rip), %rax    # 0x3c47f8
movq 0x10(%rax), %rdi
callq 0x1a810
movl $0x2, -0x2c(%rbp)
jmp 0x1bafc
cmpl $0x0, -0x2c(%rbp)
jne 0x1bdbf
leaq 0x3a8ceb(%rip), %rax    # 0x3c47f8
movq 0x10(%rax), %rsi
leaq 0x3a97b8(%rip), %rdi    # 0x3c52d0
xorl %edx, %edx
callq 0x8430
cmpl $0x0, %eax
jne 0x1bb58
movq 0x3a84b5(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x3a8cc3(%rip), %rax    # 0x3c47f8
movq 0x10(%rax), %rcx
leaq 0x366271(%rip), %rsi    # 0x381db1
leaq 0x366259(%rip), %rdx    # 0x381da0
movb $0x0, %al
callq 0x22a0
movl $0x1, %edi
callq 0x2240
leaq 0x3a8c99(%rip), %rax    # 0x3c47f8
movq 0x10(%rax), %rsi
leaq 0x3a9766(%rip), %rdi    # 0x3c52d0
movl $0x1, %edx
callq 0x8430
cmpl $0x0, %eax
jne 0x1bbad
movq 0x3a8460(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x3a8c6e(%rip), %rax    # 0x3c47f8
movq 0x10(%rax), %rcx
leaq 0x366238(%rip), %rsi    # 0x381dcd
leaq 0x366204(%rip), %rdx    # 0x381da0
movb $0x0, %al
callq 0x22a0
movl $0x1, %edi
callq 0x2240
leaq 0x3a9924(%rip), %rax    # 0x3c54d8
movq $0x0, (%rax)
leaq 0x3a990e(%rip), %rax    # 0x3c54d0
movq $0x0, (%rax)
leaq 0x3a8c28(%rip), %rax    # 0x3c47f8
movl 0xf8(%rax), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
leaq 0x3a8c15(%rip), %rax    # 0x3c47f8
movl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x1bc30
leaq 0x3a8c04(%rip), %rax    # 0x3c47f8
movq 0x10(%rax), %r8
leaq 0x3a98d1(%rip), %rdi    # 0x3c54d0
leaq 0x3a98d2(%rip), %rsi    # 0x3c54d8
leaq 0x3a96c3(%rip), %rdx    # 0x3c52d0
leaq 0x3a8be4(%rip), %rcx    # 0x3c47f8
callq 0x18ae40
leaq 0x3a8bd8(%rip), %rax    # 0x3c47f8
movq 0x10(%rax), %rsi
leaq 0x3a98c5(%rip), %rdi    # 0x3c54f0
callq 0x18a7a0
leaq 0x3a8bc1(%rip), %rax    # 0x3c47f8
movl (%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x1bc89
leaq 0x3a9888(%rip), %rax    # 0x3c54d0
cmpq $0x0, (%rax)
jne 0x1bc89
leaq 0x3a8ba3(%rip), %rdi    # 0x3c47f8
leaq 0x3a9674(%rip), %rsi    # 0x3c52d0
leaq -0x28(%rbp), %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x189600
movq %rax, %rcx
leaq 0x3a9859(%rip), %rax    # 0x3c54d0
movq %rcx, (%rax)
movl -0x28(%rbp), %esi
leaq 0x3a8b74(%rip), %rdi    # 0x3c47f8
callq 0x3b60
leaq 0x3a8b68(%rip), %rax    # 0x3c47f8
cmpl $0x0, 0xf8(%rax)
jle 0x1bc9b
jmp 0x1bcba
leaq 0x365f7d(%rip), %rdi    # 0x381c1f
leaq 0x365f92(%rip), %rsi    # 0x381c3b
movl $0x878, %edx            # imm = 0x878
leaq 0x366134(%rip), %rcx    # 0x381de9
callq 0x2130
movl -0x24(%rbp), %esi
leaq 0x3a8b34(%rip), %rdi    # 0x3c47f8
callq 0x3b00
movl -0x24(%rbp), %edi
movl $0x1, %esi
callq 0x177d0
movq 0x3a8303(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x3a8b11(%rip), %rax    # 0x3c47f8
cvtsi2sdq 0x1a8(%rax), %xmm0
movsd 0x365c58(%rip), %xmm1   # 0x381950
divsd %xmm1, %xmm0
leaq 0x365f5c(%rip), %rsi    # 0x381c5f
leaq 0x366096(%rip), %rdx    # 0x381da0
movb $0x1, %al
callq 0x22a0
movq 0x3a82c8(%rip), %rax    # 0x3c3fe0
movq (%rax), %rax
movq %rax, -0x58(%rbp)
callq 0x1b7ca0
movsd %xmm0, -0x48(%rbp)
callq 0x1b7d20
movsd %xmm0, -0x50(%rbp)
callq 0x1b7d00
movq -0x58(%rbp), %rdi
movsd -0x50(%rbp), %xmm1
movaps %xmm0, %xmm2
movsd -0x48(%rbp), %xmm0
leaq 0x36600e(%rip), %rsi    # 0x381d5e
leaq 0x366049(%rip), %rdx    # 0x381da0
movb $0x3, %al
callq 0x22a0
leaq 0x3a8a93(%rip), %rax    # 0x3c47f8
movl (%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x1bd74
callq 0x15610
movq 0x3a95cd(%rip), %rdi    # 0x3c5348
movq 0x3a95ce(%rip), %rsi    # 0x3c5350
movq 0x3a9597(%rip), %rdx    # 0x3c5320
callq 0x18f70
leaq 0x3a973b(%rip), %rax    # 0x3c54d0
movq (%rax), %rdi
callq 0x188df0
leaq 0x3a8a54(%rip), %rax    # 0x3c47f8
movl (%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x1bdb3
callq 0x198d0
leaq 0x3a8a3e(%rip), %rdi    # 0x3c47f8
callq 0x16a7f0
cmpl $0x2, -0x2c(%rbp)
jne 0x1bdcc
movl $0x0, -0x2c(%rbp)
leaq 0x3a8a25(%rip), %rax    # 0x3c47f8
movl 0xd0(%rax), %esi
leaq 0x3a8a18(%rip), %rdi    # 0x3c47f8
movl $0x64, %edx
callq 0x3bf0
leaq 0x3a8a07(%rip), %rax    # 0x3c47f8
movl 0x118(%rax), %edi
movq 0x3a954a(%rip), %rsi    # 0x3c5348
movq 0x3a954b(%rip), %rdx    # 0x3c5350
movq 0x3a9514(%rip), %rcx    # 0x3c5320
movq 0x3a94d5(%rip), %r8     # 0x3c52e8
leaq 0x3a89de(%rip), %rax    # 0x3c47f8
movslq 0x114(%rax), %r9
leaq 0x3a89d0(%rip), %rax    # 0x3c47f8
movslq 0x10c(%rax), %r15
leaq 0x3a89c2(%rip), %rax    # 0x3c47f8
movslq 0x104(%rax), %r14
leaq 0x3a89b4(%rip), %rax    # 0x3c47f8
movslq 0x110(%rax), %rbx
leaq 0x3a89a6(%rip), %rax    # 0x3c47f8
movss 0x15c(%rax), %xmm0
leaq 0x3a8997(%rip), %rax    # 0x3c47f8
movss 0x160(%rax), %xmm1
leaq 0x3a8988(%rip), %rax    # 0x3c47f8
movq 0x10(%rax), %r11
leaq 0x3a897d(%rip), %rax    # 0x3c47f8
movq 0x188(%rax), %r10
cmpl $0x0, -0x2c(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
xorl %r12d, %r12d
movq %r15, (%rsp)
movq %r14, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movl $0x0, 0x28(%rsp)
movl %eax, 0x30(%rsp)
callq 0x165da0
leaq 0x3a940d(%rip), %rdi    # 0x3c52d0
callq 0x73f0
xorl %eax, %eax
addq $0x70, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nopw (%rax,%rax)