// File: chhylp123[P]hifiasm/anchor.cpp
// Function: ha_get_candidates_interface(ha_abuf_s*, long, UC_Read*, overlap_region_alloc*, overlap_region_alloc*, Candidates_list*, double, int, int, kvec_t_u8_warp*, kvec_t_u64_warp*, ma_hit_t_alloc*, ma_hit_t_alloc*, overlap_region*, kvec_t_u64_warp*, st_mt_t*)
void ha_get_candidates_interface(ha_abuf_t *ab, int64_t rid, UC_Read *ucr, overlap_region_alloc *overlap_list, overlap_region_alloc *overlap_list_hp, Candidates_list *cl, double bw_thres, 
								 int max_n_chain, int keep_whole_chain, kvec_t_u8_warp* k_flag, kvec_t_u64_warp* chain_idx, ma_hit_t_alloc* paf, ma_hit_t_alloc* rev_paf, overlap_region* f_cigar,
								 kvec_t_u64_warp* dbg_ct, st_mt_t *sp)
{
	extern void *ha_flt_tab;
	extern ha_pt_t *ha_idx;
	extern void *ha_flt_tab_hp;
	extern ha_pt_t *ha_idx_hp;

	ha_get_new_candidates(ab, rid, ucr, overlap_list, cl, bw_thres, max_n_chain, keep_whole_chain, k_flag, chain_idx, ha_flt_tab, ha_idx, f_cigar, dbg_ct, sp);

	if(ha_idx_hp)
	{
		uint32_t i, k, y_id, overlapLen, max_i;
		int shared_seed;
		overlap_region t;
		overlap_region_sort_y_id(overlap_list->list, overlap_list->length);
		ma_hit_sort_tn(paf->buffer, paf->length);
		ma_hit_sort_tn(rev_paf->buffer, rev_paf->length);
		lable_matched_ovlp(overlap_list, paf);
		lable_matched_ovlp(overlap_list, rev_paf);

		for (i = 0, k = 0; i < overlap_list->length; ++i) 
		{
			if(overlap_list->list[i].is_match == 1)
			{
				if(k != i)
				{
					t = overlap_list->list[k];
					overlap_list->list[k] = overlap_list->list[i];
					overlap_list->list[i] = t;
					overlap_list->list[k].is_match = 0;
				}
				k++;
			}
		}
		overlap_list->length = k;


		ha_get_new_candidates(ab, rid, ucr, overlap_list_hp, cl, bw_thres, max_n_chain, keep_whole_chain, k_flag, chain_idx, ha_flt_tab_hp, ha_idx_hp, f_cigar, dbg_ct, sp);	
		
		if(overlap_list->length + overlap_list_hp->length > overlap_list->size)
		{
			overlap_list->list = (overlap_region*)realloc(overlap_list->list, 
				sizeof(overlap_region)*(overlap_list->length + overlap_list_hp->length));
			memset(overlap_list->list + overlap_list->size, 0, sizeof(overlap_region)*
				(overlap_list->length + overlap_list_hp->length - overlap_list->size));
			overlap_list->size = overlap_list->length + overlap_list_hp->length;
		}
		
		for (i = 0, k = overlap_list->length; i < overlap_list_hp->length; i++, k++)
		{
			t = overlap_list->list[k];
			overlap_list->list[k] = overlap_list_hp->list[i];
			overlap_list_hp->list[i] = t;
		}
		overlap_list->length = k;
		
		overlap_region_sort_y_id(overlap_list->list, overlap_list->length);

		i = k = 0;
		while (i < overlap_list->length)
		{
			y_id = overlap_list->list[i].y_id;
			shared_seed = overlap_list->list[i].shared_seed;
			overlapLen = overlap_list->list[i].overlapLen;
			max_i = i;
			i++;
			while (i < overlap_list->length && overlap_list->list[i].y_id == y_id)
			{
				if((overlap_list->list[i].shared_seed > shared_seed) || 
				  ((overlap_list->list[i].shared_seed == shared_seed) && (overlap_list->list[i].overlapLen <= overlapLen)))
				{
					y_id = overlap_list->list[i].y_id;
					shared_seed = overlap_list->list[i].shared_seed;
					overlapLen = overlap_list->list[i].overlapLen;
					max_i = i;
				}
				i++;
			}

			if(k != max_i)
			{
				t = overlap_list->list[k];
				overlap_list->list[k] = overlap_list->list[max_i];
				overlap_list->list[max_i] = t;
			}
			k++;
		}

		overlap_list->length = k;
	}
	
	ks_introsort_or_xs(overlap_list->length, overlap_list->list);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq 0x50(%rbp), %rax
movq 0x48(%rbp), %rax
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movq %rcx, -0x48(%rbp)
movq %r8, -0x50(%rbp)
movq %r9, -0x58(%rbp)
movsd %xmm0, -0x60(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x58(%rbp), %r8
movsd -0x60(%rbp), %xmm0
movl 0x10(%rbp), %r9d
movl 0x18(%rbp), %r13d
movq 0x20(%rbp), %r12
movq 0x28(%rbp), %r15
leaq 0x221ffd(%rip), %rax    # 0x3c54d0
movq (%rax), %r14
leaq 0x221ffb(%rip), %rax    # 0x3c54d8
movq (%rax), %rbx
movq 0x40(%rbp), %r11
movq 0x48(%rbp), %r10
movq 0x50(%rbp), %rax
movl %r13d, (%rsp)
movq %r12, 0x8(%rsp)
movq %r15, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movq %r11, 0x28(%rsp)
movq %r10, 0x30(%rsp)
movq %rax, 0x38(%rsp)
callq 0x1a0920
leaq 0x221fc9(%rip), %rax    # 0x3c54e8
cmpq $0x0, (%rax)
je 0x1a3a8c
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x1dfd0
movq 0x30(%rbp), %rax
movq (%rax), %rdi
movq 0x30(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %esi
callq 0xcd020
movq 0x38(%rbp), %rax
movq (%rax), %rdi
movq 0x38(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %esi
callq 0xcd020
movq -0x48(%rbp), %rdi
movq 0x30(%rbp), %rsi
callq 0x1a3320
movq -0x48(%rbp), %rdi
movq 0x38(%rbp), %rsi
callq 0x1a3320
movl $0x0, -0x64(%rbp)
movl $0x0, -0x68(%rbp)
movl -0x64(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x1a367a
movq -0x48(%rbp), %rax
movq (%rax), %rax
movl -0x64(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movzbl 0x2c(%rax), %eax
cmpl $0x1, %eax
jne 0x1a366a
movl -0x68(%rbp), %eax
cmpl -0x64(%rbp), %eax
je 0x1a3661
movq -0x48(%rbp), %rax
movq (%rax), %rsi
movl -0x68(%rbp), %eax
imulq $0xa8, %rax, %rax
addq %rax, %rsi
leaq -0x120(%rbp), %rdi
movl $0xa8, %edx
callq 0x2180
movq -0x48(%rbp), %rax
movq (%rax), %rsi
movl -0x64(%rbp), %eax
imulq $0xa8, %rax, %rax
addq %rax, %rsi
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movl -0x68(%rbp), %eax
imulq $0xa8, %rax, %rax
addq %rax, %rdi
movl $0xa8, %edx
callq 0x2180
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movl -0x64(%rbp), %eax
imulq $0xa8, %rax, %rax
addq %rax, %rdi
leaq -0x120(%rbp), %rsi
movl $0xa8, %edx
callq 0x2180
movq -0x48(%rbp), %rax
movq (%rax), %rax
movl -0x68(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x2c(%rax)
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x1a366c
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x1a358f
movl -0x68(%rbp), %eax
movl %eax, %ecx
movq -0x48(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x58(%rbp), %r8
movsd -0x60(%rbp), %xmm0
movl 0x10(%rbp), %r9d
movl 0x18(%rbp), %r13d
movq 0x20(%rbp), %r12
movq 0x28(%rbp), %r15
leaq 0x221e29(%rip), %rax    # 0x3c54e0
movq (%rax), %r14
leaq 0x221e27(%rip), %rax    # 0x3c54e8
movq (%rax), %rbx
movq 0x40(%rbp), %r11
movq 0x48(%rbp), %r10
movq 0x50(%rbp), %rax
movl %r13d, (%rsp)
movq %r12, 0x8(%rsp)
movq %r15, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movq %r11, 0x28(%rsp)
movq %r10, 0x30(%rsp)
movq %rax, 0x38(%rsp)
callq 0x1a0920
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x50(%rbp), %rcx
addq 0x10(%rcx), %rax
movq -0x48(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jbe 0x1a379b
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x50(%rbp), %rcx
addq 0x10(%rcx), %rax
imulq $0xa8, %rax, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movq -0x48(%rbp), %rax
imulq $0xa8, 0x8(%rax), %rax
addq %rax, %rdi
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x50(%rbp), %rcx
addq 0x10(%rcx), %rax
movq -0x48(%rbp), %rcx
subq 0x8(%rcx), %rax
imulq $0xa8, %rax, %rdx
xorl %esi, %esi
callq 0x2100
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x50(%rbp), %rax
addq 0x10(%rax), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0x0, -0x64(%rbp)
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, -0x68(%rbp)
movl -0x64(%rbp), %eax
movq -0x50(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x1a3851
movq -0x48(%rbp), %rax
movq (%rax), %rsi
movl -0x68(%rbp), %eax
imulq $0xa8, %rax, %rax
addq %rax, %rsi
leaq -0x120(%rbp), %rdi
movl $0xa8, %edx
callq 0x2180
movq -0x50(%rbp), %rax
movq (%rax), %rsi
movl -0x64(%rbp), %eax
imulq $0xa8, %rax, %rax
addq %rax, %rsi
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movl -0x68(%rbp), %eax
imulq $0xa8, %rax, %rax
addq %rax, %rdi
movl $0xa8, %edx
callq 0x2180
movq -0x50(%rbp), %rax
movq (%rax), %rdi
movl -0x64(%rbp), %eax
imulq $0xa8, %rax, %rax
addq %rax, %rdi
leaq -0x120(%rbp), %rsi
movl $0xa8, %edx
callq 0x2180
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x1a37ad
movl -0x68(%rbp), %eax
movl %eax, %ecx
movq -0x48(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x1dfd0
movl $0x0, -0x68(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x1a3a7f
movq -0x48(%rbp), %rax
movq (%rax), %rax
movl -0x64(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, -0x6c(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rax
movl -0x64(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x24(%rax), %eax
movl %eax, -0x78(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rax
movl -0x64(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
movl %eax, -0x70(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
movl %eax, %ecx
movq -0x48(%rbp), %rdx
xorl %eax, %eax
cmpq 0x10(%rdx), %rcx
movb %al, -0x121(%rbp)
jae 0x1a3928
movq -0x48(%rbp), %rax
movq (%rax), %rax
movl -0x64(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
cmpl -0x6c(%rbp), %eax
sete %al
movb %al, -0x121(%rbp)
movb -0x121(%rbp), %al
testb $0x1, %al
jne 0x1a3937
jmp 0x1a39ed
movq -0x48(%rbp), %rax
movq (%rax), %rax
movl -0x64(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x24(%rax), %eax
cmpl -0x78(%rbp), %eax
jg 0x1a398b
movq -0x48(%rbp), %rax
movq (%rax), %rax
movl -0x64(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x24(%rax), %eax
cmpl -0x78(%rbp), %eax
jne 0x1a39df
movq -0x48(%rbp), %rax
movq (%rax), %rax
movl -0x64(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
cmpl -0x70(%rbp), %eax
ja 0x1a39df
movq -0x48(%rbp), %rax
movq (%rax), %rax
movl -0x64(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, -0x6c(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rax
movl -0x64(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x24(%rax), %eax
movl %eax, -0x78(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rax
movl -0x64(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
movl %eax, -0x70(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x1a38ee
movl -0x68(%rbp), %eax
cmpl -0x74(%rbp), %eax
je 0x1a3a71
movq -0x48(%rbp), %rax
movq (%rax), %rsi
movl -0x68(%rbp), %eax
imulq $0xa8, %rax, %rax
addq %rax, %rsi
leaq -0x120(%rbp), %rdi
movl $0xa8, %edx
callq 0x2180
movq -0x48(%rbp), %rax
movq (%rax), %rsi
movl -0x74(%rbp), %eax
imulq $0xa8, %rax, %rax
addq %rax, %rsi
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movl -0x68(%rbp), %eax
imulq $0xa8, %rax, %rax
addq %rax, %rdi
movl $0xa8, %edx
callq 0x2180
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movl -0x74(%rbp), %eax
imulq $0xa8, %rax, %rax
addq %rax, %rdi
leaq -0x120(%rbp), %rsi
movl $0xa8, %edx
callq 0x2180
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x1a3880
movl -0x68(%rbp), %eax
movl %eax, %ecx
movq -0x48(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x48(%rbp), %rax
movq (%rax), %rsi
callq 0x19d6c0
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)