// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movsd %xmm0, 0x38(%rsp)
movq %rcx, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq 0xc8(%rsp), %rax
movq (%rax), %r13
testq %r13, %r13
js 0x173c81
movq 0xb8(%rsp), %rdx
movq 0xa8(%rsp), %r12
movq 0x98(%rsp), %rsi
movq 0x90(%rsp), %rdi
movslq %r9d, %r14
leaq -0x1(%r13), %r15
leal (,%rdi,4), %eax
movl %eax, 0x18(%rsp)
leal 0x3(,%rdi,4), %eax
movl %eax, 0x1c(%rsp)
imulq $0x1c, %rdi, %rax
addq %r8, %rax
movq %rax, 0x50(%rsp)
imulq $0x1c, %r13, %rax
leaq (%r8,%rax), %rcx
movq %rcx, 0x48(%rsp)
leaq 0x1(%r13), %rbx
leaq (%r8,%rax), %rbp
addq $0x1c, %rbp
cmpq %r14, %rbx
jge 0x173c81
movq %r15, (%rdx,%rbx,8)
cmpq $0x0, (%r12,%rbx,8)
js 0x173c75
movl (%rsi,%rbx,4), %eax
movl %eax, %ecx
sarl $0x2, %ecx
movslq %ecx, %rcx
cmpq %rdi, %rcx
je 0x173bc5
movl 0x1c(%rsp), %eax
movl %eax, (%rsi,%rbx,4)
testb $0x40, 0x1b(%rbp)
je 0x173bc5
leaq 0x40(%rsp), %rax
movq %rax, (%rsp)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0x30(%rsp), %rcx
movsd 0x38(%rsp), %xmm0
movq 0x50(%rsp), %r8
movq %rbp, %r9
callq 0x173c90
testl %eax, %eax
je 0x173baa
movl 0x40(%rsp), %eax
addl 0x18(%rsp), %eax
movq 0x98(%rsp), %rsi
movl %eax, (%rsi,%rbx,4)
jmp 0x173bb5
movq 0x98(%rsp), %rsi
movl (%rsi,%rbx,4), %eax
movq 0xb8(%rsp), %rdx
movq 0x90(%rsp), %rdi
movl %eax, %ecx
notl %ecx
testb $0x3, %cl
je 0x173c75
sarl $0x2, %eax
cltq
cmpq %rdi, %rax
jne 0x173c75
movq (%r12,%rbx,8), %rax
cmpq %r13, %rax
jle 0x173bf5
cmpq %r13, (%rdx,%rax,8)
movq %r13, %rax
je 0x173bf5
movq %r15, %rax
cmpq %r13, %rax
jne 0x173c75
movq %r13, (%rdx,%rbx,8)
cmpq %r13, (%r12,%rbx,8)
je 0x173c4b
leaq 0x40(%rsp), %rax
movq %rax, (%rsp)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0x30(%rsp), %rcx
movsd 0x38(%rsp), %xmm0
movq %rbp, %r8
movq 0x48(%rsp), %r9
callq 0x173c90
movq 0x90(%rsp), %rdi
movq 0x98(%rsp), %rsi
movq 0xb8(%rsp), %rdx
testl %eax, %eax
je 0x173c75
movq 0xb0(%rsp), %rax
movslq (%rax,%rbx,4), %rax
incq %rax
movq 0xd0(%rsp), %rcx
cmpq %rax, (%rcx)
jg 0x173c75
movq %rax, (%rcx)
movq 0xc8(%rsp), %rax
movq %rbx, (%rax)
incq %rbx
addq $0x1c, %rbp
jmp 0x173b31
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq