// File: chhylp123[P]hifiasm/inter.cpp
// Function: ctg_chain_graph(void*, ul_idx_t const*, ma_ug_t const*, vec_mg_lchain_t*, vec_mg_lchain_t*, vec_mg_path_dst_t*, vec_sp_node_t*, vec_mg_pathv_t*, long, ug_opt_t const*, long, double, unsigned long*, st_mt_t*, Chain_Data*, long, long, long, unsigned long)
int64_t ctg_chain_graph(void *km, const ul_idx_t *uref, const ma_ug_t *ug, vec_mg_lchain_t *lc, 
vec_mg_lchain_t *sw, vec_mg_path_dst_t *dst, vec_sp_node_t *out, vec_mg_pathv_t *path,
int64_t qlen, const ug_opt_t *uopt, int64_t bw, double ng_diff_thre, uint64_t *srt, 
st_mt_t *bf, Chain_Data* dp, int64_t max_skip, int64_t max_iter, int64_t max_dis, uint64_t id)
{
	bf->n = 0;
    if(lc->n == 0) return 0;
	int64_t i, j, lc_n = lc->n, x, m_idx; mg_lchain_t *r;


	for (i = 0; i < lc_n; i++) {
		r = &lc->a[i]; r->dist_pre = -1; 
		srt[i] = r->qe; srt[i] <<= 32; srt[i] |= (uint64_t)i; 
	}
	radix_sort_gfa64(srt, srt+lc_n); 
	for (i = 1, j = 0; i <= lc_n; i++) {
		if (i == lc_n || (srt[i]>>32) != (srt[j]>>32)) {
			if(i - j > 1) {
				for (x = j; x < i; x++) {
					srt[x] <<= 32; srt[x] >>= 32; srt[x] |= ((uint64_t)lc->a[(uint32_t)srt[x]].qs)<<32;
				}
				radix_sort_gfa64(srt+j, srt+i);
			}
			j = i;
		}
	}


	kv_resize(mg_lchain_t, *sw, (uint64_t)lc_n); sw->n = lc_n;
	for (i = 0; i < lc_n; i++) sw->a[i] = lc->a[(uint32_t)srt[i]];
	memcpy(lc->a, sw->a, lc_n *sizeof((*(lc->a))));


	resize_Chain_Data(dp, lc_n, NULL);
	int32_t *p; int64_t *f, *t; 
	t = dp->tmp; p = dp->score; f = dp->pre;

	m_idx = gl_chain_linear(uref, ug, lc, sw, qlen, uopt, bw, ng_diff_thre, bf, 
		max_skip, max_iter, max_dis, p, f, t, lc->n, id);

	// if(m_idx >= 0 && primary_chain_check(bf->a, bf->n, lc->a)) return m_idx;
	// else m_idx = -1;
	// bf->n = 0;
	return m_idx;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq 0x68(%rbp), %rax
movq 0x60(%rbp), %rax
movq 0x58(%rbp), %rax
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
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x38(%rbp)
movq %rsi, -0x40(%rbp)
movq %rdx, -0x48(%rbp)
movq %rcx, -0x50(%rbp)
movq %r8, -0x58(%rbp)
movq %r9, -0x60(%rbp)
movsd %xmm0, -0x68(%rbp)
movq 0x40(%rbp), %rax
movq $0x0, (%rax)
movq -0x50(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x2a6754
movq $0x0, -0x30(%rbp)
jmp 0x2a6b85
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x80(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x80(%rbp), %rax
jge 0x2a67e3
movq -0x50(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x70(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
movq -0x98(%rbp), %rax
movslq 0x18(%rax), %rdx
movq 0x38(%rbp), %rax
movq -0x70(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x38(%rbp), %rax
movq -0x70(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
shlq $0x20, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x70(%rbp), %rdx
movq 0x38(%rbp), %rax
movq -0x70(%rbp), %rcx
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x2a6768
movq 0x38(%rbp), %rdi
movq 0x38(%rbp), %rsi
movq -0x80(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x27a9b0
movq $0x1, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x80(%rbp), %rax
jg 0x2a6933
movq -0x70(%rbp), %rax
cmpq -0x80(%rbp), %rax
je 0x2a684c
movq 0x38(%rbp), %rax
movq -0x70(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq 0x38(%rbp), %rcx
movq -0x78(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
je 0x2a6920
movq -0x70(%rbp), %rax
subq -0x78(%rbp), %rax
cmpq $0x1, %rax
jle 0x2a6918
movq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
cmpq -0x70(%rbp), %rax
jge 0x2a68f5
movq 0x38(%rbp), %rax
movq -0x88(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
shlq $0x20, %rdx
movq %rdx, (%rax,%rcx,8)
movq 0x38(%rbp), %rax
movq -0x88(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
shrq $0x20, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq 0x38(%rbp), %rcx
movq -0x88(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movslq 0x14(%rax), %rdx
shlq $0x20, %rdx
movq 0x38(%rbp), %rax
movq -0x88(%rbp), %rcx
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x2a6869
movq 0x38(%rbp), %rdi
movq -0x78(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq 0x38(%rbp), %rsi
movq -0x70(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x27a9b0
movq -0x70(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x2a6922
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x2a680b
jmp 0x2a6935
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
cmpq -0x80(%rbp), %rax
jae 0x2a6a09
movq -0x80(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x10(%rax)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rcx
shrq %rcx
movq -0x58(%rbp), %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rcx
shrq $0x2, %rcx
movq -0x58(%rbp), %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rcx
shrq $0x4, %rcx
movq -0x58(%rbp), %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rcx
shrq $0x8, %rcx
movq -0x58(%rbp), %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rcx
shrq $0x10, %rcx
movq -0x58(%rbp), %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x10(%rax)
movq -0x58(%rbp), %rax
movq (%rax), %rdi
movq -0x58(%rbp), %rax
imulq $0x28, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, (%rax)
jmp 0x2a6a0b
movq -0x80(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x8(%rax)
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x80(%rbp), %rax
jge 0x2a6a6c
movq -0x50(%rbp), %rax
movq (%rax), %rsi
movq 0x38(%rbp), %rax
movq -0x70(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
imulq $0x28, %rax, %rax
addq %rax, %rsi
movq -0x58(%rbp), %rax
movq (%rax), %rdi
imulq $0x28, -0x70(%rbp), %rax
addq %rax, %rdi
movl $0x28, %edx
callq 0x2180
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x2a6a1f
movq -0x50(%rbp), %rax
movq (%rax), %rdi
movq -0x58(%rbp), %rax
movq (%rax), %rsi
imulq $0x28, -0x80(%rbp), %rdx
callq 0x2180
movq 0x48(%rbp), %rdi
movq -0x80(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x226f0
movq 0x48(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0xb0(%rbp)
movq 0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
movq 0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x58(%rbp), %rcx
movq 0x20(%rbp), %r8
movq 0x28(%rbp), %r9
movq 0x30(%rbp), %rax
movq %rax, -0xc8(%rbp)
movsd -0x68(%rbp), %xmm0
movq 0x40(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq 0x50(%rbp), %r13
movq 0x58(%rbp), %r12
movq 0x60(%rbp), %r15
movq -0xa0(%rbp), %r14
movq -0xa8(%rbp), %rbx
movq -0xb0(%rbp), %r11
movq -0x50(%rbp), %rax
movq 0x8(%rax), %r10
movq 0x68(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, (%rsp)
movq -0xc0(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0xb8(%rbp), %rax
movq %r13, 0x10(%rsp)
movq %r12, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movq %r14, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
movq %r11, 0x38(%rsp)
movq %r10, 0x40(%rsp)
movq %rax, 0x48(%rsp)
callq 0x2a3f70
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax,%rax)