// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %r9, %r12
movq %r8, 0x10(%rsp)
movq 0x1a0(%rsp), %r10
movq 0x198(%rsp), %rax
movq 0x190(%rsp), %rbp
movq 0x188(%rsp), %rbx
movq 0x180(%rsp), %r13
movq 0x178(%rsp), %r15
movq 0x170(%rsp), %r11
movl 0x168(%rsp), %r14d
movl 0x160(%rsp), %r9d
movq %rdi, 0x28(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
movq %rcx, 0x8(%rsp)
movq %r12, 0x58(%rsp)
movq %r12, %r8
movsd %xmm0, 0x68(%rsp)
movl %r9d, 0x1c(%rsp)
movq %r10, 0x40(%rsp)
pushq %r10
movq %rax, 0x50(%rsp)
pushq %rax
movq %rbp, 0x60(%rsp)
pushq %rbp
leaq 0x16eff2(%rip), %rax    # 0x254438
pushq (%rax)
leaq 0x16efe1(%rip), %rax    # 0x254430
pushq (%rax)
movq %r15, 0x88(%rsp)
pushq %r15
movq %r11, 0xa0(%rsp)
pushq %r11
pushq %r14
callq 0xe3b12
addq $0x40, %rsp
leaq 0x16efd1(%rip), %rax    # 0x254448
cmpq $0x0, (%rax)
je 0xe57b9
movq %r14, 0x20(%rsp)
movq %rbx, %r14
movq 0x8(%rsp), %rbx
movq (%rbx), %rdi
movq 0x10(%rbx), %rsi
callq 0x1188f
movq (%r13), %rdi
movl 0xc(%r13), %esi
callq 0x68ee7
movq (%r14), %rdi
movl 0xc(%r14), %esi
callq 0x68ee7
movq %rbx, %rdi
movq %r13, %rsi
callq 0xe533e
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe533e
xorl %r12d, %r12d
xorl %r14d, %r14d
movq 0x8(%rsp), %rbx
movl %r12d, %r12d
movl %r14d, %eax
movq 0x8(%rsp), %rcx
cmpq %r12, 0x10(%rcx)
jbe 0xe556d
movq 0x8(%rsp), %rcx
movq (%rcx), %rbp
imulq $0xa8, %r12, %r13
cmpb $0x1, 0x2c(%rbp,%r13)
jne 0xe5565
cmpl %r14d, %r12d
je 0xe5562
imulq $0xa8, %rax, %rax
movq %rax, 0x78(%rsp)
leaq (%rax,%rbp), %r15
movl $0xa8, %edx
leaq 0x80(%rsp), %rdi
movq %r15, %rsi
callq 0x2160
addq %r13, %rbp
movl $0xa8, %edx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x2160
addq (%rbx), %r13
movl $0xa8, %edx
movq %r13, %rdi
leaq 0x80(%rsp), %rsi
callq 0x2160
movq (%rbx), %rax
movq 0x78(%rsp), %rcx
movb $0x0, 0x2c(%rax,%rcx)
incl %r14d
incl %r12d
jmp 0xe54d4
movq 0x8(%rsp), %rbx
movq %rax, 0x10(%rbx)
leaq 0x16eec3(%rip), %rax    # 0x254440
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x10(%rsp), %r14
movq %r14, %rcx
movq 0x58(%rsp), %r8
movsd 0x68(%rsp), %xmm0
movl 0x1c(%rsp), %r9d
pushq 0x40(%rsp)
pushq 0x50(%rsp)
pushq 0x60(%rsp)
leaq 0x16ee91(%rip), %r10    # 0x254448
pushq (%r10)
pushq (%rax)
pushq 0x88(%rsp)
pushq 0xa0(%rsp)
pushq 0x58(%rsp)
callq 0xe3b12
addq $0x40, %rsp
movq 0x10(%rbx), %rax
movq 0x10(%r14), %r13
movq %rax, %r15
addq %r13, %rax
cmpq 0x8(%rbx), %rax
jbe 0xe563c
movq 0x8(%rsp), %rbx
movq (%rbx), %rdi
imulq $0xa8, %rax, %rsi
callq 0x2370
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
movq 0x10(%rbx), %rdx
imulq $0xa8, %rcx, %rdi
addq %rax, %rdi
movq 0x10(%rsp), %rax
movq 0x10(%rax), %r13
movq %rdx, %r15
leaq (%rdx,%r13), %r14
movq %r14, %rax
subq %rcx, %rax
imulq $0xa8, %rax, %rdx
xorl %esi, %esi
callq 0x20e0
movq %r14, 0x8(%rbx)
xorl %eax, %eax
leaq 0x80(%rsp), %r12
movq %r15, %rbx
movq 0x10(%rsp), %r15
movl %eax, %r14d
cmpq %r14, %r13
jbe 0xe56b0
addl %ebx, %eax
movl %eax, %eax
imulq $0xa8, %rax, %r13
movq 0x8(%rsp), %rax
addq (%rax), %r13
movl $0xa8, %edx
movq %r12, %rdi
movq %r13, %rsi
callq 0x2160
imulq $0xa8, %r14, %rbp
movq (%r15), %rsi
addq %rbp, %rsi
movl $0xa8, %edx
movq %r13, %rdi
callq 0x2160
addq (%r15), %rbp
movl $0xa8, %edx
movq %rbp, %rdi
movq %r12, %rsi
callq 0x2160
leal 0x1(%r14), %eax
movq 0x10(%r15), %r13
jmp 0xe564e
addl %r14d, %ebx
movq 0x8(%rsp), %rax
movq %rbx, 0x10(%rax)
movq (%rax), %rdi
movq %rbx, %rsi
callq 0x1188f
xorl %r14d, %r14d
xorl %ebx, %ebx
movl %r14d, %ecx
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movl %ebx, %edi
cmpq %rcx, %rax
jbe 0xe57ae
movq 0x8(%rsp), %rdx
movq (%rdx), %r15
imulq $0xa8, %rcx, %rsi
movl 0x10(%r15,%rsi), %ecx
movl 0x20(%r15,%rsi), %edx
movl 0x24(%r15,%rsi), %esi
movl %r14d, %r13d
leal 0x1(%r13), %r14d
movl %r14d, %r8d
cmpq %r8, %rax
jbe 0xe574b
imulq $0xa8, %r8, %r9
cmpl %ecx, 0x10(%r15,%r9)
jne 0xe574b
addq %r15, %r9
movl 0x24(%r9), %r8d
cmpl %esi, %r8d
jg 0xe573a
jne 0xe5735
movl 0x20(%r9), %r9d
cmpl %edx, %r9d
jbe 0xe5740
incl %r14d
jmp 0xe5708
movl 0x20(%r9), %edx
jmp 0xe5743
movl %r9d, %edx
movl %r14d, %r13d
movl %r8d, %esi
jmp 0xe5704
cmpl %r13d, %ebx
je 0xe57a7
imulq $0xa8, %rdi, %r12
addq %r15, %r12
movl $0xa8, %edx
leaq 0x80(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
callq 0x2160
movl %r13d, %eax
imulq $0xa8, %rax, %r13
addq %r13, %r15
movl $0xa8, %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x2160
movq 0x8(%rsp), %rax
addq (%rax), %r13
movl $0xa8, %edx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2160
incl %ebx
jmp 0xe56cc
movq 0x8(%rsp), %rax
movq %rdi, 0x10(%rax)
jmp 0xe57c2
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x8(%rsp), %rax
movq (%rax), %rsi
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe1c6f