// File: /workspace/github_cpp_makefile_star2_O1/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, %rbp
movq %r8, 0x28(%rsp)
movq %rcx, %r8
movq 0x1a0(%rsp), %r15
movq 0x198(%rsp), %r10
movq 0x190(%rsp), %rax
movq 0x188(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movq 0x180(%rsp), %r13
movq 0x178(%rsp), %r11
movq 0x170(%rsp), %r12
movl 0x168(%rsp), %r14d
movl 0x160(%rsp), %r9d
leaq 0x166ddc(%rip), %rbx    # 0x28b430
movq %rdi, 0x38(%rsp)
movq %rsi, 0x40(%rsp)
movq %rdx, 0x48(%rsp)
movq %r8, 0x8(%rsp)
movq %r8, %rcx
movq %rbp, 0x68(%rsp)
movq %rbp, %r8
movq %r14, %rbp
movsd %xmm0, 0x78(%rsp)
movl %r9d, 0x1c(%rsp)
movq %r15, 0x50(%rsp)
pushq %r15
movq %r10, 0x60(%rsp)
pushq %r10
movq %rax, 0x70(%rsp)
pushq %rax
leaq 0x166d9c(%rip), %rax    # 0x28b438
pushq (%rax)
pushq (%rbx)
movq %r11, 0x98(%rsp)
pushq %r11
movq %r12, 0x50(%rsp)
pushq %r12
pushq %r14
callq 0x122b9c
addq $0x40, %rsp
leaq 0x166d85(%rip), %r15    # 0x28b448
cmpq $0x0, (%r15)
je 0x124a21
movq 0x8(%rsp), %rbx
movq (%rbx), %rdi
movq 0x10(%rbx), %rsi
callq 0x3daa2
movq (%r13), %rdi
movl 0xc(%r13), %esi
callq 0x9fc49
movq 0x10(%rsp), %r14
movq (%r14), %rdi
movl 0xc(%r14), %esi
callq 0x9fc49
movq %rbx, %rdi
movq %r13, %rsi
callq 0x12457b
movq %rbx, %rdi
movq %r14, %rsi
callq 0x12457b
xorl %r12d, %r12d
cmpq $0x0, 0x10(%rbx)
je 0x1247de
movq %rbp, 0x30(%rsp)
xorl %eax, %eax
xorl %r14d, %r14d
movq 0x8(%rsp), %rbx
movq 0x8(%rsp), %rcx
movq (%rcx), %rbp
imulq $0xa8, %rax, %r13
cmpb $0x1, 0x2c(%rbp,%r13)
jne 0x1247ae
cmpl %r12d, %r14d
je 0x1247ab
movl %r12d, %eax
imulq $0xa8, %rax, %rax
movq %rax, 0x10(%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 0x10(%rsp), %rcx
movb $0x0, 0x2c(%rax,%rcx)
incl %r12d
incl %r14d
movq %r14, %rax
movq 0x8(%rsp), %rcx
cmpq %r14, 0x10(%rcx)
ja 0x12472f
movl %r12d, %r12d
movq 0x28(%rsp), %r14
movq 0x30(%rsp), %rbp
movq 0x20(%rsp), %r10
leaq 0x166c6c(%rip), %r15    # 0x28b448
jmp 0x1247e8
movq 0x28(%rsp), %r14
movq 0x20(%rsp), %r10
movq 0x8(%rsp), %rbx
movq %r12, 0x10(%rbx)
leaq 0x166c48(%rip), %rax    # 0x28b440
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq %r14, %rcx
movq 0x68(%rsp), %r8
movsd 0x78(%rsp), %xmm0
movl 0x1c(%rsp), %r9d
pushq 0x50(%rsp)
pushq 0x60(%rsp)
pushq 0x70(%rsp)
pushq (%r15)
pushq (%rax)
pushq 0x98(%rsp)
pushq %r10
pushq %rbp
callq 0x122b9c
addq $0x40, %rsp
movq 0x10(%r14), %rax
addq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rax
jbe 0x124897
movq 0x8(%rsp), %rbx
movq (%rbx), %rdi
imulq $0xa8, %rax, %rsi
callq 0x2370
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
imulq $0xa8, %rcx, %rdi
movq %r14, %r15
movq 0x10(%r14), %r14
addq 0x10(%rbx), %r14
addq %rax, %rdi
movq %r14, %rax
subq %rcx, %rax
imulq $0xa8, %rax, %rdx
xorl %esi, %esi
callq 0x20e0
movq %r14, 0x8(%rbx)
movq %r15, %r14
movq 0x8(%rsp), %rax
movl 0x10(%rax), %ebp
cmpq $0x0, 0x10(%r14)
je 0x124916
movq %r14, %r15
movl $0x1, %r14d
xorl %r13d, %r13d
movl %ebp, %eax
imulq $0xa8, %rax, %r12
movq 0x8(%rsp), %rax
addq (%rax), %r12
movl $0xa8, %edx
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2160
imulq $0xa8, %r13, %r13
movq (%r15), %rsi
addq %r13, %rsi
movl $0xa8, %edx
movq %r12, %rdi
callq 0x2160
addq (%r15), %r13
movl $0xa8, %edx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2160
incl %ebp
movl %r14d, %r13d
incl %r14d
cmpq %r13, 0x10(%r15)
ja 0x1248b2
movl %ebp, %esi
movq 0x8(%rsp), %rbx
movq %rsi, 0x10(%rbx)
movq (%rbx), %rdi
callq 0x3daa2
movq 0x10(%rbx), %rax
xorl %ebp, %ebp
testq %rax, %rax
je 0x124a18
xorl %ecx, %ecx
xorl %r13d, %r13d
movq 0x8(%rsp), %rdx
movq (%rdx), %r15
leal 0x1(%r13), %r14d
cmpq %r14, %rax
jbe 0x12499e
imulq $0xa8, %rcx, %rsi
movl 0x10(%r15,%rsi), %edx
movl 0x20(%r15,%rsi), %ecx
movl 0x24(%r15,%rsi), %esi
imulq $0xa8, %r14, %rdi
movl 0x10(%r15,%rdi), %r8d
cmpl %edx, %r8d
jne 0x12499e
addq %r15, %rdi
movl 0x24(%rdi), %r9d
cmpl %esi, %r9d
jle 0x12498f
movl 0x20(%rdi), %ecx
movl %r8d, %edx
movl %r14d, %r13d
movl %r9d, %esi
jmp 0x124996
jne 0x124996
cmpl %ecx, 0x20(%rdi)
jbe 0x124981
incl %r14d
cmpq %r14, %rax
ja 0x124964
cmpl %r13d, %ebp
je 0x1249fc
movl %ebp, %eax
imulq $0xa8, %rax, %r12
addq %r15, %r12
movl $0xa8, %edx
leaq 0x80(%rsp), %rbx
movq %rbx, %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 %rbx, %rsi
callq 0x2160
incl %ebp
movl %r14d, %ecx
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movl %r14d, %r13d
cmpq %rcx, %rax
ja 0x12493d
movl %ebp, %ebp
movq 0x8(%rsp), %rax
movq %rbp, 0x10(%rax)
movq 0x8(%rsp), %rax
movq (%rax), %rsi
movq 0x10(%rax), %rdi
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x120acf