// File: chhylp123[P]hifiasm/Assembly.cpp
// Function: ha_overlap_and_correct(int)
void ha_overlap_and_correct(int round)
{
	int i, hom_cov, het_cov, r_out = 0;
	ha_ovec_buf_t **b;
	ha_ecsave_buf_t *e;
    ha_flt_tab_hp = ha_idx_hp = NULL;

    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
	// overlap and correct reads
	CALLOC(b, asm_opt.thread_num);
	for (i = 0; i < asm_opt.thread_num; ++i)
		b[i] = ha_ovec_init(0, (round == asm_opt.number_of_round - 1),0);
    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
	///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);
    // fprintf(stderr, "[M::%s-start]\n", __func__);
    // double tt0 = yak_realtime_0();
	if (asm_opt.required_read_name)
		kt_for(asm_opt.thread_num, worker_ovec_related_reads, b, R_INF.total_reads);
	else
		kt_for(asm_opt.thread_num, worker_ovec, b, R_INF.total_reads);///debug_for_fix
    // fprintf(stderr, "[M::%s-end]\n", __func__);
    // fprintf(stderr, "[M::%s::%.3f] ==> chaining\n", __func__, yak_realtime_0()-tt0);
    // exit(1);
    
    if (r_out) write_pt_index(ha_flt_tab, ha_idx, &R_INF, &asm_opt, asm_opt.output_file_name);
	ha_pt_destroy(ha_idx);
	ha_idx = NULL;

    if(het_cnt) {
        print_het_cnt_log(het_cnt); free(het_cnt); het_cnt = NULL;
    }

	// collect statistics
	for (i = 0; i < asm_opt.thread_num; ++i) {
		asm_opt.num_bases += b[i]->num_read_base;
		asm_opt.num_corrected_bases += b[i]->num_correct_base;
		asm_opt.num_recorrected_bases += b[i]->num_recorrect_base;
		asm_opt.mem_buf += ha_ovec_mem(b[i], NULL);
		ha_ovec_destroy(b[i]);
	}
	free(b);
    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
	CALLOC(e, asm_opt.thread_num);
	for (i = 0; i < asm_opt.thread_num; ++i) {
		init_UC_Read(&e[i].g_read);
		e[i].first_round_read_size = e[i].second_round_read_size = 50000;
		CALLOC(e[i].first_round_read, e[i].first_round_read_size);
		CALLOC(e[i].second_round_read, e[i].second_round_read_size);
	}
	kt_for(asm_opt.thread_num, worker_ec_save, e, R_INF.total_reads);
	for (i = 0; i < asm_opt.thread_num; ++i) {
		destory_UC_Read(&e[i].g_read);
		free(e[i].first_round_read);
		free(e[i].second_round_read);
	}
	free(e);

    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();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x4(%rbp)
movl $0x0, -0x14(%rbp)
leaq 0x3ae5cf(%rip), %rax    # 0x3c54e8
movq $0x0, (%rax)
leaq 0x3ae5b9(%rip), %rax    # 0x3c54e0
movq $0x0, (%rax)
leaq 0x3ae5a3(%rip), %rax    # 0x3c54d8
cmpq $0x0, (%rax)
jne 0x16f6a
leaq 0x3ad8b6(%rip), %rax    # 0x3c47f8
movl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x16f6a
movl -0x4(%rbp), %eax
leaq 0x3ad8a2(%rip), %rcx    # 0x3c47f8
movl 0xf8(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x16f6a
movl $0x1, -0x14(%rbp)
leaq 0x3ad887(%rip), %rax    # 0x3c47f8
cmpq $0x0, 0x18(%rax)
je 0x16f8f
leaq 0x3ad879(%rip), %rax    # 0x3c47f8
movq 0x18(%rax), %rsi
leaq 0x3ae3ce(%rip), %rdi    # 0x3c5358
callq 0xb750
leaq 0x3ad862(%rip), %rax    # 0x3c47f8
movslq 0x7c(%rax), %rdi
movl $0x8, %esi
callq 0x2140
movq %rax, -0x20(%rbp)
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
leaq 0x3ad83f(%rip), %rcx    # 0x3c47f8
cmpl 0x7c(%rcx), %eax
jge 0x16ffe
movl -0x4(%rbp), %eax
leaq 0x3ad830(%rip), %rcx    # 0x3c47f8
movl 0xf8(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
sete %al
andb $0x1, %al
movzbl %al, %esi
xorl %edx, %edx
movl %edx, %edi
callq 0x14c90
movq %rax, %rdx
movq -0x20(%rbp), %rax
movslq -0x8(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x16faf
leaq 0x3ae4d3(%rip), %rax    # 0x3c54d8
cmpq $0x0, (%rax)
je 0x1701b
leaq 0x3ad7e6(%rip), %rax    # 0x3c47f8
movl 0xd0(%rax), %eax
movl %eax, -0xc(%rbp)
leaq 0x3ae4b6(%rip), %rax    # 0x3c54d8
cmpq $0x0, (%rax)
jne 0x17070
leaq 0x3ae4a1(%rip), %rax    # 0x3c54d0
movq (%rax), %rsi
movl -0x4(%rbp), %ecx
movl $0x1, %edx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovel %eax, %edx
leaq 0x3ad7af(%rip), %rdi    # 0x3c47f8
xorl %ecx, %ecx
leaq 0x3ae27e(%rip), %r8     # 0x3c52d0
leaq -0xc(%rbp), %r9
leaq -0x10(%rbp), %rax
movq %rax, (%rsp)
callq 0x18a180
movq %rax, %rcx
leaq 0x3ae46b(%rip), %rax    # 0x3c54d8
movq %rcx, (%rax)
cmpl $0x0, -0x4(%rbp)
jne 0x17092
leaq 0x3ae453(%rip), %rax    # 0x3c54d0
cmpq $0x0, (%rax)
jne 0x17092
movl -0xc(%rbp), %esi
leaq 0x3ad76b(%rip), %rdi    # 0x3c47f8
callq 0x3b60
movq $0x0, 0x3ae3eb(%rip) # 0x3c5488
movl -0x4(%rbp), %eax
leaq 0x3ad751(%rip), %rcx    # 0x3c47f8
movl 0xf8(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x170dc
leaq 0x3ad73d(%rip), %rax    # 0x3c47f8
cmpb $0x0, 0x248(%rax)
je 0x170dc
movq 0x3ae255(%rip), %rdi    # 0x3c5320
movl $0x4, %esi
callq 0x2140
movq %rax, 0x3ae3ac(%rip)    # 0x3c5488
leaq 0x3ad715(%rip), %rax    # 0x3c47f8
cmpq $0x0, 0x18(%rax)
je 0x1710d
leaq 0x3ad707(%rip), %rax    # 0x3c47f8
movl 0x7c(%rax), %edi
movq -0x20(%rbp), %rdx
movq 0x3ae221(%rip), %rcx    # 0x3c5320
leaq -0x1576(%rip), %rsi     # 0x15b90
callq 0x16d710
jmp 0x1712e
leaq 0x3ad6e4(%rip), %rax    # 0x3c47f8
movl 0x7c(%rax), %edi
movq -0x20(%rbp), %rdx
movq 0x3ae1fe(%rip), %rcx    # 0x3c5320
leaq -0xbc9(%rip), %rsi      # 0x16560
callq 0x16d710
cmpl $0x0, -0x14(%rbp)
je 0x17166
leaq 0x3ae395(%rip), %rax    # 0x3c54d0
movq (%rax), %rdi
leaq 0x3ae393(%rip), %rax    # 0x3c54d8
movq (%rax), %rsi
leaq 0x3ad6a9(%rip), %rax    # 0x3c47f8
movq 0x10(%rax), %r8
leaq 0x3ae176(%rip), %rdx    # 0x3c52d0
leaq 0x3ad697(%rip), %rcx    # 0x3c47f8
callq 0x18aa10
leaq 0x3ae36b(%rip), %rax    # 0x3c54d8
movq (%rax), %rdi
callq 0x187660
leaq 0x3ae35c(%rip), %rax    # 0x3c54d8
movq $0x0, (%rax)
cmpq $0x0, 0x3ae2fd(%rip)    # 0x3c5488
je 0x171b0
movq 0x3ae2f4(%rip), %rdi    # 0x3c5488
callq 0x16930
movq 0x3ae2e8(%rip), %rdi    # 0x3c5488
callq 0x2210
movq $0x0, 0x3ae2d8(%rip) # 0x3c5488
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
leaq 0x3ad637(%rip), %rcx    # 0x3c47f8
cmpl 0x7c(%rcx), %eax
jge 0x172aa
movq -0x20(%rbp), %rax
movslq -0x8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0xf0(%rax), %rcx
leaq 0x3ad614(%rip), %rax    # 0x3c47f8
addq 0x190(%rax), %rcx
leaq 0x3ad606(%rip), %rax    # 0x3c47f8
movq %rcx, 0x190(%rax)
movq -0x20(%rbp), %rax
movslq -0x8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0xf8(%rax), %rcx
leaq 0x3ad5e5(%rip), %rax    # 0x3c47f8
addq 0x198(%rax), %rcx
leaq 0x3ad5d7(%rip), %rax    # 0x3c47f8
movq %rcx, 0x198(%rax)
movq -0x20(%rbp), %rax
movslq -0x8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x100(%rax), %rcx
leaq 0x3ad5b6(%rip), %rax    # 0x3c47f8
addq 0x1a0(%rax), %rcx
leaq 0x3ad5a8(%rip), %rax    # 0x3c47f8
movq %rcx, 0x1a0(%rax)
movq -0x20(%rbp), %rax
movslq -0x8(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x15070
movq %rax, %rcx
leaq 0x3ad582(%rip), %rax    # 0x3c47f8
addq 0x1a8(%rax), %rcx
leaq 0x3ad574(%rip), %rax    # 0x3c47f8
movq %rcx, 0x1a8(%rax)
movq -0x20(%rbp), %rax
movslq -0x8(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x14f00
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x171b7
movq -0x20(%rbp), %rdi
callq 0x2210
leaq 0x3ad53e(%rip), %rax    # 0x3c47f8
cmpq $0x0, 0x18(%rax)
je 0x172d8
movq 0x3ae0b8(%rip), %rdi    # 0x3c5380
leaq 0x3ae089(%rip), %rsi    # 0x3c5358
xorl %eax, %eax
movl %eax, %edx
callq 0x16a50
leaq 0x3ad519(%rip), %rax    # 0x3c47f8
movslq 0x7c(%rax), %rdi
movl $0x38, %esi
callq 0x2140
movq %rax, -0x28(%rbp)
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
leaq 0x3ad4f6(%rip), %rcx    # 0x3c47f8
cmpl 0x7c(%rcx), %eax
jge 0x173bf
movq -0x28(%rbp), %rdi
movslq -0x8(%rbp), %rax
imulq $0x38, %rax, %rax
addq %rax, %rdi
callq 0x9850
movq -0x28(%rbp), %rax
movslq -0x8(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl $0xc350, 0x24(%rax)     # imm = 0xC350
movq -0x28(%rbp), %rax
movslq -0x8(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl $0xc350, 0x20(%rax)     # imm = 0xC350
movq -0x28(%rbp), %rax
movslq -0x8(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movslq 0x20(%rax), %rdi
movl $0x1, %esi
callq 0x2140
movq %rax, %rcx
movq -0x28(%rbp), %rax
movslq -0x8(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x28(%rax)
movq -0x28(%rbp), %rax
movslq -0x8(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movslq 0x24(%rax), %rdi
movl $0x1, %esi
callq 0x2140
movq %rax, %rcx
movq -0x28(%rbp), %rax
movslq -0x8(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x30(%rax)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x172f8
leaq 0x3ad432(%rip), %rax    # 0x3c47f8
movl 0x7c(%rax), %edi
movq -0x28(%rbp), %rdx
movq 0x3adf4c(%rip), %rcx    # 0x3c5320
leaq 0xc5(%rip), %rsi        # 0x174a0
callq 0x16d710
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
leaq 0x3ad407(%rip), %rcx    # 0x3c47f8
cmpl 0x7c(%rcx), %eax
jge 0x17445
movq -0x28(%rbp), %rdi
movslq -0x8(%rbp), %rax
imulq $0x38, %rax, %rax
addq %rax, %rdi
callq 0x9670
movq -0x28(%rbp), %rax
movslq -0x8(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x28(%rax), %rdi
callq 0x2210
movq -0x28(%rbp), %rax
movslq -0x8(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x30(%rax), %rdi
callq 0x2210
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x173e7
movq -0x28(%rbp), %rdi
callq 0x2210
leaq 0x3ad3a3(%rip), %rax    # 0x3c47f8
cmpq $0x0, 0x18(%rax)
je 0x17474
movq 0x3adf25(%rip), %rdi    # 0x3c5388
leaq 0x3adeee(%rip), %rsi    # 0x3c5358
movl $0x1, %edx
callq 0x16a50
leaq 0x3ad37d(%rip), %rax    # 0x3c47f8
cmpq $0x0, 0x18(%rax)
je 0x17495
leaq 0x3adecf(%rip), %rdi    # 0x3c5358
callq 0xbaa0
xorl %edi, %edi
callq 0x2240
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)