// File: chhylp123[P]hifiasm/inter.cpp
// Function: quick_rechain_propagate_transitive_reduction(ul_idx_t const*, ug_opt_t const*, All_reads*, long, double, ul_ov_t*, int, long, int*, int*, long*, int*, long*, long*, long*, long*)
void quick_rechain_propagate_transitive_reduction(const ul_idx_t *uref, const ug_opt_t *uopt, All_reads *ridx, int64_t bw, double diff, 
ul_ov_t *a, int32_t a_n, int64_t ai, int32_t *rch, int32_t *f, int64_t *p, int32_t *c_n, int64_t *t, int64_t *mm_sc, 
int64_t *mm_idx, int64_t *mm_n)
{
	if((*mm_idx) < 0) return;
	int64_t mm_idx0 = (*mm_idx), j, k, is_c, sn;
	for (j = mm_idx0 + 1; j < a_n; j++) {
		t[j] = mm_idx0 - 1;
		if(p[j] < 0) continue;
		// if(a[ai].tn == 23989) {
		// 	fprintf(stderr, "+chain[i::%ld] (id::%u)%.*s\t%c\tj::%ld\t%.*s\tconnect::%u\n", ai, a[ai].tn,
		// 		(int)Get_NAME_LENGTH(R_INF, a[ai].tn), Get_NAME(R_INF, a[ai].tn), 
		// 		"+-"[a[ai].rev], j, (int)Get_NAME_LENGTH(R_INF, a[ai].tn), Get_NAME(R_INF, a[ai].tn), rch_connect(rch[j], ai));
		// }
		if((rch[j]>>2) != ai) {
			rch[j] = (ai<<2); rch[j] += 3;
			if((a[j].el) && (if_qchain_cnn(uref, uopt, ridx, bw, diff, &(a[ai]), &(a[j]), &is_c, NULL))) {
				rch[j] = (ai<<2); rch[j] += is_c;
			}
		}
		// if(a[ai].tn == 23989) {
		// 	fprintf(stderr, "-chain[i::%ld] (id::%u)%.*s\t%c\tj::%ld\t%.*s\tconnect::%u\n", ai, a[ai].tn,
		// 		(int)Get_NAME_LENGTH(R_INF, a[ai].tn), Get_NAME(R_INF, a[ai].tn), 
		// 		"+-"[a[ai].rev], j, (int)Get_NAME_LENGTH(R_INF, a[ai].tn), Get_NAME(R_INF, a[ai].tn), rch_connect(rch[j], ai));
		// }
		if(!rch_connect(rch[j], ai)) continue;
		for (k = p[j]; k >= 0 && k > mm_idx0; k = p[k]) {
			if(t[k] == mm_idx0) {
				k = mm_idx0; break;
			} else {
				k = mm_idx0-1; break;
			}
		}
		if (k != mm_idx0) continue;
		t[j] = mm_idx0;//a[j] could reach mm_idx0;
		if(p[j] != k) {
			if(!(if_qchain_cnn(uref, uopt, ridx, bw, diff, &(a[j]), &(a[k]), &is_c, NULL))) continue;
		}
		sn = c_n[j] + 1;
		if(sn >= (*mm_n)) {//must >=
			(*mm_n) = sn; (*mm_idx) = j;
		}
	}
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
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, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movsd %xmm0, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movq 0x48(%rbp), %rax
cmpq $0x0, (%rax)
jge 0x2b2c9b
jmp 0x2b2f12
movq 0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movslq -0x34(%rbp), %rcx
cmpq %rcx, %rax
jge 0x2b2f10
movq -0x40(%rbp), %rdx
subq $0x1, %rdx
movq 0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x28(%rbp), %rax
movq -0x48(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jge 0x2b2ceb
jmp 0x2b2eff
movq 0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
movl (%rax,%rcx,4), %eax
sarl $0x2, %eax
cltq
cmpq 0x10(%rbp), %rax
je 0x2b2dbd
movq 0x10(%rbp), %rax
shlq $0x2, %rax
movl %eax, %edx
movq 0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x3, %edx
movl %edx, (%rax,%rcx,4)
movq -0x30(%rbp), %rax
imulq $0x1c, -0x48(%rbp), %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2b2dbb
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movsd -0x28(%rbp), %xmm0
movq -0x30(%rbp), %r8
imulq $0x1c, 0x10(%rbp), %rax
addq %rax, %r8
movq -0x30(%rbp), %r9
imulq $0x1c, -0x48(%rbp), %rax
addq %rax, %r9
leaq -0x58(%rbp), %rax
xorl %r10d, %r10d
movq %rax, (%rsp)
movq $0x0, 0x8(%rsp)
callq 0x2b2f20
cmpl $0x0, %eax
je 0x2b2dbb
movq 0x10(%rbp), %rax
shlq $0x2, %rax
movl %eax, %edx
movq 0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x58(%rbp), %rsi
movq 0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
movslq (%rax,%rcx,4), %rdx
addq %rsi, %rdx
movl %edx, (%rax,%rcx,4)
jmp 0x2b2dbd
movq 0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
movl (%rax,%rcx,4), %eax
sarl $0x2, %eax
cltq
cmpq 0x10(%rbp), %rax
jne 0x2b2de6
movq 0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0x3, %eax
cmpl $0x3, %eax
jne 0x2b2deb
jmp 0x2b2eff
movq 0x28(%rbp), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x50(%rbp)
movb %al, -0x61(%rbp)
jl 0x2b2e15
movq -0x50(%rbp), %rax
cmpq -0x40(%rbp), %rax
setg %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x2b2e1e
jmp 0x2b2e46
movq 0x38(%rbp), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x40(%rbp), %rax
jne 0x2b2e3a
movq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x2b2e46
movq -0x40(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x40(%rbp), %rax
je 0x2b2e55
jmp 0x2b2eff
movq -0x40(%rbp), %rdx
movq 0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x28(%rbp), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x50(%rbp), %rax
je 0x2b2ec6
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movsd -0x28(%rbp), %xmm0
movq -0x30(%rbp), %r8
imulq $0x1c, -0x48(%rbp), %rax
addq %rax, %r8
movq -0x30(%rbp), %r9
imulq $0x1c, -0x50(%rbp), %rax
addq %rax, %r9
leaq -0x58(%rbp), %rax
xorl %r10d, %r10d
movq %rax, (%rsp)
movq $0x0, 0x8(%rsp)
callq 0x2b2f20
cmpl $0x0, %eax
jne 0x2b2ec4
jmp 0x2b2eff
jmp 0x2b2ec6
movq 0x30(%rbp), %rax
movq -0x48(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl $0x1, %eax
cltq
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq 0x50(%rbp), %rcx
cmpq (%rcx), %rax
jl 0x2b2efd
movq -0x60(%rbp), %rcx
movq 0x50(%rbp), %rax
movq %rcx, (%rax)
movq -0x48(%rbp), %rcx
movq 0x48(%rbp), %rax
movq %rcx, (%rax)
jmp 0x2b2eff
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x2b2cb2
jmp 0x2b2f12
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)