// File: /workspace/github_cpp_makefile_star2_O3/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, 0x78(%rsp)
movq %rcx, %rbx
movq 0x1a0(%rsp), %r10
movq 0x198(%rsp), %rax
movq 0x190(%rsp), %rbp
movq 0x188(%rsp), %rcx
movq %rcx, 0x18(%rsp)
movq 0x180(%rsp), %r13
movq 0x178(%rsp), %r15
movq 0x170(%rsp), %r14
movl 0x168(%rsp), %r11d
movl 0x160(%rsp), %r9d
movq %rdi, 0x20(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdx, 0x30(%rsp)
movq %rbx, %rcx
movq %r12, 0x50(%rsp)
movq %r12, %r8
movsd %xmm0, 0x60(%rsp)
movl %r9d, 0x14(%rsp)
movq %r10, 0x38(%rsp)
pushq %r10
movq %rax, 0x48(%rsp)
pushq %rax
movq %rbp, 0x58(%rsp)
pushq %rbp
leaq 0x16be56(%rip), %rax    # 0x296438
pushq (%rax)
leaq 0x16be45(%rip), %rax    # 0x296430
pushq (%rax)
movq %r15, 0x80(%rsp)
pushq %r15
movq %r14, 0x98(%rsp)
pushq %r14
movq %r11, 0xa8(%rsp)
pushq %r11
callq 0x128a69
addq $0x40, %rsp
leaq 0x16be2d(%rip), %rax    # 0x296448
cmpq $0x0, (%rax)
je 0x12a950
movq (%rbx), %rdi
movq 0x10(%rbx), %rsi
callq 0x3cf83
movq (%r13), %rdi
movl 0xc(%r13), %esi
callq 0xa0402
movq 0x18(%rsp), %r14
movq (%r14), %rdi
movl 0xc(%r14), %esi
callq 0xa0402
movq %rbx, %rdi
movq %r13, %rsi
callq 0x12a4d1
movq %rbx, %rdi
movq %r14, %rsi
callq 0x12a4d1
movq 0x10(%rbx), %rax
xorl %r12d, %r12d
testq %rax, %rax
movq %rbx, 0x8(%rsp)
je 0x12a70e
movq (%rbx), %r13
xorl %ecx, %ecx
xorl %ebx, %ebx
imulq $0xa8, %rcx, %rbp
cmpb $0x1, 0x2c(%r13,%rbp)
jne 0x12a6f8
cmpl %r12d, %ebx
je 0x12a6f5
movl %r12d, %eax
imulq $0xa8, %rax, %r14
leaq (%r14,%r13), %r15
movl $0xa8, %edx
leaq 0x80(%rsp), %rdi
movq %r15, %rsi
callq 0x2160
addq %rbp, %r13
movl $0xa8, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x2160
movq 0x8(%rsp), %r15
addq (%r15), %rbp
movl $0xa8, %edx
movq %rbp, %rdi
leaq 0x80(%rsp), %rsi
callq 0x2160
movq (%r15), %r13
movb $0x0, 0x2c(%r13,%r14)
movq 0x10(%r15), %rax
incl %r12d
incl %ebx
movq %rbx, %rcx
cmpq %rbx, %rax
ja 0x12a681
movl %r12d, %r12d
movq 0x8(%rsp), %rbx
movq %r12, 0x10(%rbx)
leaq 0x16bd27(%rip), %rax    # 0x296440
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0x78(%rsp), %r12
movq %r12, %rcx
movq 0x50(%rsp), %r8
movsd 0x60(%rsp), %xmm0
movl 0x14(%rsp), %r9d
pushq 0x38(%rsp)
pushq 0x48(%rsp)
pushq 0x58(%rsp)
leaq 0x16bcf5(%rip), %r10    # 0x296448
pushq (%r10)
pushq (%rax)
pushq 0x80(%rsp)
pushq 0x98(%rsp)
pushq 0xa8(%rsp)
callq 0x128a69
addq $0x40, %rsp
movq 0x10(%rbx), %rbp
movq %rbx, %rcx
movq 0x10(%r12), %rbx
leaq (%rbx,%rbp), %rax
cmpq 0x8(%rcx), %rax
jbe 0x12a7d6
movq 0x8(%rsp), %r15
movq (%r15), %rdi
imulq $0xa8, %rax, %rsi
callq 0x2370
movq %rax, (%r15)
movq 0x8(%r15), %rcx
movq 0x10(%r15), %rbp
imulq $0xa8, %rcx, %rdi
addq %rax, %rdi
movq 0x10(%r12), %rbx
leaq (%rbx,%rbp), %r14
movq %r14, %rax
subq %rcx, %rax
imulq $0xa8, %rax, %rdx
xorl %esi, %esi
callq 0x20e0
movq %r14, 0x8(%r15)
testq %rbx, %rbx
je 0x12a849
movl $0x1, %ebx
movq %r12, %r14
xorl %r13d, %r13d
movl %ebp, %eax
imulq $0xa8, %rax, %r12
movq 0x8(%rsp), %rax
addq (%rax), %r12
movl $0xa8, %edx
leaq 0x80(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x2160
imulq $0xa8, %r13, %r13
movq (%r14), %rsi
addq %r13, %rsi
movl $0xa8, %edx
movq %r12, %rdi
callq 0x2160
addq (%r14), %r13
movl $0xa8, %edx
movq %r13, %rdi
movq %r15, %rsi
callq 0x2160
incl %ebp
movl %ebx, %r13d
incl %ebx
cmpq %r13, 0x10(%r14)
ja 0x12a7e6
movl %ebp, %esi
movq 0x8(%rsp), %r13
movq %rsi, 0x10(%r13)
movq (%r13), %rdi
callq 0x3cf83
movq 0x10(%r13), %rax
xorl %r14d, %r14d
testq %rax, %rax
je 0x12a94a
xorl %ecx, %ecx
xorl %ebp, %ebp
movq (%r13), %r12
leal 0x1(%rbp), %r15d
cmpq %r15, %rax
jbe 0x12a8d2
imulq $0xa8, %rcx, %rcx
leaq (%r12,%rcx), %rsi
movl 0x10(%r12,%rcx), %ecx
movl 0x20(%rsi), %edx
movl 0x24(%rsi), %esi
imulq $0xa8, %r15, %r8
cmpl %ecx, 0x10(%r12,%r8)
jne 0x12a8d2
addq %r12, %r8
movl 0x24(%r8), %edi
cmpl %esi, %edi
jle 0x12a8b8
movl 0x20(%r8), %edx
movl %r15d, %ebp
movl %edi, %esi
jmp 0x12a8c3
jne 0x12a8c3
movl 0x20(%r8), %r8d
cmpl %edx, %r8d
jbe 0x12a8cd
incl %r15d
cmpq %r15, %rax
ja 0x12a894
jmp 0x12a8d2
movl %r8d, %edx
jmp 0x12a8b1
cmpl %ebp, %r14d
je 0x12a935
movl %r14d, %eax
imulq $0xa8, %rax, %r13
addq %r12, %r13
movl $0xa8, %edx
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2160
movl %ebp, %eax
imulq $0xa8, %rax, %rbp
addq %rbp, %r12
movl $0xa8, %edx
movq %r13, %rdi
movq 0x8(%rsp), %r13
movq %r12, %rsi
callq 0x2160
addq (%r13), %rbp
movl $0xa8, %edx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x2160
movq 0x10(%r13), %rax
incl %r14d
movl %r15d, %ecx
movl %r15d, %ebp
cmpq %rcx, %rax
ja 0x12a871
movl %r14d, %r14d
movq %r14, 0x10(%r13)
jmp 0x12a957
movq 0x10(%rbx), %r14
movq %rbx, %r13
movq (%r13), %rsi
movq %r14, %rdi
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x126994