// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/inter.cpp
// Function: renew_consensus_chain(kv_ul_ov_t*, unsigned int, unsigned int, kv_ul_ov_t*, asg64_v*, R_to_U*, ug_opt_t const*, asg_t const*, long, double, unsigned int, Chain_Data*, unsigned long, unsigned int)
void renew_consensus_chain(kv_ul_ov_t *in, uint32_t in_s, uint32_t in_e, kv_ul_ov_t *idx, asg64_v *ou, R_to_U *ri,
const ug_opt_t *uopt, const asg_t *rg, int64_t bw, double diff_ec_ul, uint32_t arc_id, Chain_Data* dp, uint64_t rlen, uint32_t ulid)
{	
	if(in_e <= in_s) return;
	uint64_t mqs, mqe, k, l, ou_n = ou->n, stn, etn;
	collect_pp_ovlps(in->a + in_s, in_e - in_s, idx, uopt, rg, rlen, ulid, &mqs, &mqe);
	// if(ulid == 7723 && in_e-in_s == 2 && in->a[in_s].tn == (7723>>1) && in->a[in_e-1].tn == (7829>>1)) {
	// 	fprintf(stderr, "-0-[M::%s] ulid::%u, idx->n::%u\n", __func__, ulid, (uint32_t)idx->n);
	// }
	if(!idx->n) return;///it is possible
	kv_resize(uint64_t, *ou, (ou_n+(in_e-in_s)));
	for (k = in_s; k < in_e; k++) {
		if(in->a[k].el) continue;
		ou->a[ou_n++] = in->a[k].tn;
	}
	assert(ou_n <= ou->m);
	radix_sort_gfa64(ou->a+ou->n, ou->a+ou_n);
	gen_linear_rchains_dedup(idx, in, rg, uopt, bw, diff_ec_ul, rlen, dp, ulid, ou->a+ou->n, ou_n-ou->n);
	// if(ulid == 7723 && in_e-in_s == 2 && in->a[in_s].tn == (7723>>1) && in->a[in_e-1].tn == (7829>>1)) {
	// 	fprintf(stderr, "-1-[M::%s] ulid::%u, idx->n::%u\n", __func__, ulid, (uint32_t)idx->n);
	// }
	if(!idx->n) return;///it is possible
	stn = etn = (uint64_t)-1;
	if(in_e > in_s && in->a[in_s].el) stn = in->a[in_s].tn;
	if(in_e-in_s>1 && in->a[in_e-1].el) etn = in->a[in_e-1].tn;
	idx->n = gen_cns_chain_linear_hard(idx->a, idx->n, rg, rlen, bw, diff_ec_ul, dp, UG_SKIP_N, UG_ITER_N, UG_DIS_N, mqs, mqe, ulid, stn, etn);
	// if(ulid == 7723 && in_e-in_s == 2 && in->a[in_s].tn == (7723>>1) && in->a[in_e-1].tn == (7829>>1)) {
	// 	fprintf(stderr, "-2-[M::%s] ulid::%u, idx->n::%u\n", __func__, ulid, (uint32_t)idx->n);
	// }
	if(!idx->n) return;
	assert((stn==((uint64_t)-1))||((idx->a[0].tn == stn) && (idx->a[0].el)));
	assert((etn==((uint64_t)-1))||((idx->a[idx->n-1].tn == etn) && (idx->a[idx->n-1].el)));
	if((stn != ((uint64_t)-1)) && (etn != ((uint64_t)-1)) && idx->n < 2) return;///could happen for circle
	if(((stn != ((uint64_t)-1)) || (etn != ((uint64_t)-1))) && idx->n < 1) return;///not sure if it will happen
	ou_n = ou->n;
	for (k = in_s; k < in_e; k++) {
		if(in->a[k].el) continue;
		kv_push(uint64_t, *ou, in->a[k].tn);
	}
	for (k = 0; k < idx->n; k++) {
		if(idx->a[k].el) continue;
		kv_push(uint64_t, *ou, idx->a[k].tn);
	}
	if(ou->n == ou_n) return;
	radix_sort_gfa64(ou->a+ou_n, ou->a+ou->n);
	for (k = ou_n+1, l = ou_n; k <= ou->n; k++) {
		if(k == ou->n || ou->a[l] != ou->a[k]) {
			if(k-l > 1) break;
			l = k;
		}
	}
	assert(k > ou->n);
	ou->n = ou_n;
	l = arc_id; 
	if(arc_id == (uint32_t)-1) {///this is an isloated node
		l = idx->a[0].tn; l |= ((uint64_t)0x80000000);
	}
	l <<= 32; l |= ((uint64_t)((uint32_t)-1));
	kv_push(uint64_t, *ou, l);
	for (k = 0; k < idx->n; k++) {
		l = ((uint64_t)(idx->a[k].tn<<1))|((uint64_t)idx->a[k].rev);
		if(idx->a[k].el) l += ((uint64_t)0x100000000);
		kv_push(uint64_t, *ou, l);
	}
	kv_push(uint64_t, *ou, ((uint64_t)-1));
	for (k = in_s; k < in_e; k++) {
		l = ((uint64_t)(in->a[k].tn<<1))|((uint64_t)in->a[k].rev);
		if(in->a[k].el) l += ((uint64_t)0x100000000);
		kv_push(uint64_t, *ou, l);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %edx, %ebp
subl %esi, %ebp
jbe 0x1debfa
movq %r8, %rbx
movq %rcx, %r10
movl %edx, %r12d
movsd %xmm0, 0x58(%rsp)
movq 0xd8(%rsp), %r9
movq 0xb8(%rsp), %r8
movq 0xb0(%rsp), %rcx
movq (%rbx), %r15
movl %esi, %edx
leaq (%rdx,%rdx,8), %rax
leaq (%rax,%rax,2), %rsi
movq %rdx, 0x50(%rsp)
movq %rsi, 0x60(%rsp)
leaq (%rsi,%rdx), %r14
movq %rdi, 0x48(%rsp)
movq (%rdi), %rdi
addq %r14, %rdi
leaq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x70(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rbp, %rsi
movq %r10, %rdx
movq %r10, 0x40(%rsp)
callq 0x1dd862
movq 0x40(%rsp), %rax
cmpq $0x0, 0x8(%rax)
je 0x1debfa
leaq (%r15,%rbp), %rax
cmpq %rax, 0x8(%rbx)
jae 0x1de72f
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%rbx)
movq 0x10(%rbx), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
movl %r12d, %r13d
movq 0x48(%rsp), %rax
movq (%rax), %rcx
movq %r13, %rax
subq 0x50(%rsp), %rax
addq %r14, %rcx
addq $0x18, %rcx
testb $0x40, 0x3(%rcx)
jne 0x1de75d
movl -0xc(%rcx), %edx
movq 0x10(%rbx), %rsi
movq %rdx, (%rsi,%r15,8)
incq %r15
addq $0x1c, %rcx
decq %rax
jne 0x1de749
cmpq 0x8(%rbx), %r15
ja 0x1dec28
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq (%rcx,%rax,8), %rdi
leaq (%rcx,%r15,8), %rsi
callq 0x19dd99
movq (%rbx), %rax
leaq (,%rax,8), %rcx
addq 0x10(%rbx), %rcx
subq %rax, %r15
movq %r15, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, (%rsp)
movq 0x40(%rsp), %r15
movq %r15, %rdi
movq 0x48(%rsp), %rsi
movq 0xb8(%rsp), %rdx
movq 0xc0(%rsp), %r8
movsd 0x58(%rsp), %xmm0
callq 0x1de3b6
movq 0x8(%r15), %rsi
testq %rsi, %rsi
je 0x1debfa
movq %r15, %rdx
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq $-0x1, %r9
testb $0x40, 0x1b(%rax,%r14)
movq $-0x1, %r15
je 0x1de80a
leaq (%rax,%r14), %rcx
movl 0xc(%rcx), %r15d
cmpl $0x2, %ebp
movsd 0x58(%rsp), %xmm0
jb 0x1de831
decl %r12d
leaq (%r12,%r12,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r12, %rcx
testb $0x40, 0x1b(%rax,%rcx)
je 0x1de831
addq %rcx, %rax
movl 0xc(%rax), %r9d
movq (%rdx), %rdi
movq 0x70(%rsp), %rax
movq 0x68(%rsp), %rcx
movq %r9, 0x38(%rsp)
movq %r15, 0x30(%rsp)
movq %rcx, 0x20(%rsp)
movq %rax, 0x18(%rsp)
movq $0xc350, 0x10(%rsp)     # imm = 0xC350
movq $0x1388, 0x8(%rsp)      # imm = 0x1388
movq $0x64, (%rsp)
movq 0xb8(%rsp), %rdx
movq 0xd8(%rsp), %rcx
movq 0xc0(%rsp), %r8
movq %r9, %r12
movq 0xd0(%rsp), %r9
callq 0x1ddca7
movq 0x40(%rsp), %r8
movq %rax, 0x8(%r8)
testq %rax, %rax
je 0x1debfa
movq %r12, %rdi
cmpq $-0x1, %r15
je 0x1de8c8
movq (%r8), %rcx
movl 0xc(%rcx), %edx
cmpq %rdx, %r15
jne 0x1dec47
testb $0x40, 0x1b(%rcx)
je 0x1dec47
cmpq $-0x1, %rdi
je 0x1de906
movq (%r8), %rcx
leaq (%rax,%rax,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rax, %rdx
movl -0x10(%rcx,%rdx), %esi
cmpq %rsi, %rdi
jne 0x1dec66
addq %rdx, %rcx
testb $0x40, -0x1(%rcx)
je 0x1dec66
cmpq $-0x1, %r15
je 0x1de906
cmpq $0x1, %rax
je 0x1debfa
movq (%rbx), %r12
movq 0x48(%rsp), %rax
movq (%rax), %rcx
movq %r13, %r15
subq 0x50(%rsp), %r15
movl $0x2, %ebp
testb $0x40, 0x1b(%rcx,%r14)
jne 0x1de972
movq (%rbx), %rdx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rdx
jne 0x1de962
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
cmoveq %rbp, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x40(%rsp), %r8
movq %rax, 0x10(%rbx)
movq 0x48(%rsp), %rcx
movq (%rcx), %rcx
movq (%rbx), %rdx
movl 0xc(%rcx,%r14), %esi
leaq 0x1(%rdx), %rdi
movq %rdi, (%rbx)
movq %rsi, (%rax,%rdx,8)
addq $0x1c, %r14
decq %r15
jne 0x1de91e
movq 0x8(%r8), %rax
testq %rax, %rax
je 0x1de9f1
movq (%r8), %rcx
xorl %r14d, %r14d
movl $0x2, %r15d
xorl %ebp, %ebp
testb $0x40, 0x1b(%rcx,%r14)
jne 0x1de9e5
movq (%rbx), %rdx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rdx
jne 0x1de9d1
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
cmoveq %r15, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x40(%rsp), %r8
movq %rax, 0x10(%rbx)
movq (%r8), %rcx
movq (%rbx), %rdx
movl 0xc(%rcx,%r14), %esi
leaq 0x1(%rdx), %rdi
movq %rdi, (%rbx)
movq %rsi, (%rax,%rdx,8)
movq 0x8(%r8), %rax
incq %rbp
addq $0x1c, %r14
cmpq %rax, %rbp
jb 0x1de992
movq (%rbx), %rax
cmpq %r12, %rax
je 0x1debfa
movq 0x10(%rbx), %rcx
leaq (%rcx,%r12,8), %rdi
leaq (%rcx,%rax,8), %rsi
callq 0x19dd99
movq (%rbx), %rax
leaq 0x1(%r12), %rcx
cmpq %rax, %rcx
movl 0xc8(%rsp), %r9d
ja 0x1dea57
movq %rcx, %rdx
movq %r12, %rsi
cmpq %rdx, %rax
je 0x1dea3c
movq 0x10(%rbx), %rdi
movq (%rdi,%rsi,8), %r8
cmpq (%rdi,%rdx,8), %r8
je 0x1dea4f
movq %rdx, %rdi
subq %rsi, %rdi
movq %rdx, %rsi
cmpq $0x1, %rdi
ja 0x1dec09
incq %rdx
cmpq %rax, %rdx
jbe 0x1dea29
movq %r12, (%rbx)
cmpl $-0x1, %r9d
movq 0x40(%rsp), %rdi
jne 0x1dea72
movq (%rdi), %rax
movl $0x80000000, %r9d       # imm = 0x80000000
orl 0xc(%rax), %r9d
shlq $0x20, %r9
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
orq %r9, %r14
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %r12
jne 0x1deaba
leaq (%r12,%r12), %rcx
testq %r12, %r12
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x40(%rsp), %rdi
movq %rax, 0x10(%rbx)
movq (%rbx), %r12
leaq 0x1(%r12), %rcx
movq %rcx, (%rbx)
movq %r14, (%rax,%r12,8)
cmpq $0x0, 0x8(%rdi)
je 0x1deb41
movl $0x18, %r14d
xorl %r15d, %r15d
movq (%rdi), %rcx
movl -0xc(%rcx,%r14), %ebp
movl (%rcx,%r14), %r12d
movq (%rbx), %rcx
cmpq 0x8(%rbx), %rcx
jne 0x1deb12
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x40(%rsp), %rdi
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
shldl $0x1, %r12d, %ebp
andl $0x40000000, %r12d      # imm = 0x40000000
leaq (,%r12,4), %rdx
addq %rbp, %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbx)
movq %rdx, (%rax,%rcx,8)
incq %r15
addq $0x1c, %r14
cmpq 0x8(%rdi), %r15
jb 0x1dead1
movq (%rbx), %rcx
cmpq 0x8(%rbx), %rcx
jne 0x1deb71
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rdx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
movq $-0x1, (%rax,%rcx,8)
movq 0x50(%rsp), %rcx
subq %rcx, %r13
movq 0x60(%rsp), %rdx
leaq (%rcx,%rdx), %r14
addq $0x18, %r14
movl $0x2, %r15d
movq 0x48(%rsp), %rcx
movq (%rcx), %rcx
movl -0xc(%rcx,%r14), %r12d
movl (%rcx,%r14), %ebp
movq (%rbx), %rcx
cmpq 0x8(%rbx), %rcx
jne 0x1debd7
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %r15, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
shldl $0x1, %ebp, %r12d
andl $0x40000000, %ebp       # imm = 0x40000000
leaq (%r12,%rbp,4), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbx)
movq %rdx, (%rax,%rcx,8)
addq $0x1c, %r14
decq %r13
jne 0x1deb9b
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x64f27(%rip), %rdi     # 0x243b37
leaq 0x61044(%rip), %rsi     # 0x23fc5b
leaq 0x64dcb(%rip), %rcx     # 0x2439e9
movl $0x4969, %edx           # imm = 0x4969
callq 0x2110
leaq 0x64dac(%rip), %rdi     # 0x2439db
leaq 0x61025(%rip), %rsi     # 0x23fc5b
leaq 0x64dac(%rip), %rcx     # 0x2439e9
movl $0x4945, %edx           # imm = 0x4945
callq 0x2110
leaq 0x64e59(%rip), %rdi     # 0x243aa7
leaq 0x61006(%rip), %rsi     # 0x23fc5b
leaq 0x64d8d(%rip), %rcx     # 0x2439e9
movl $0x4954, %edx           # imm = 0x4954
callq 0x2110
leaq 0x64e7b(%rip), %rdi     # 0x243ae8
leaq 0x60fe7(%rip), %rsi     # 0x23fc5b
leaq 0x64d6e(%rip), %rcx     # 0x2439e9
movl $0x4955, %edx           # imm = 0x4955
callq 0x2110