// File: chhylp123[P]hifiasm/inter.cpp
// Function: quick_primary_assgin(ul_idx_t const*, ug_opt_t const*, long, double, ul_ov_t*, long)
uint32_t quick_primary_assgin(const ul_idx_t *uref, const ug_opt_t *uopt, int64_t bw, double diff_ec_ul, ul_ov_t *a, int64_t a_n)
{
	int64_t k, qo, share, f = 1; ul_ov_t *li, *lk; uint32_t li_v, lk_v;
	for (k = a_n - 1, li = NULL; k >= 0; k--) {
		lk = &(a[k]); lk_v = (lk->tn<<1)|lk->rev; lk->sec = SEC_MODE; 
		if(!(lk->tn&((uint32_t)(0x80000000)))) continue;
		if(li && lk->qe > li->qs) { ///lk is overlapped with li
			li->tn <<= 1; li->tn >>= 1; lk->tn <<= 1; lk->tn >>= 1;
			qo = infer_rovlp(li, lk, NULL, NULL, NULL, NULL);
			li->tn |= ((uint32_t)(0x80000000)); lk->tn |= ((uint32_t)(0x80000000));
			if(qo && li_v != lk_v && get_ecov_adv(uref, uopt, li_v^1, lk_v^1, bw, diff_ec_ul, qo, 1, &share)) {
				li->sec = k; f++; ///the end of a chain is a cis overlap
			} else {
				f = 0;
				break;
			}
		}
		li = lk; li_v = lk_v; 
	}
	return f;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq $0x1, -0x50(%rbp)
movq -0x30(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x58(%rbp)
cmpq $0x0, -0x38(%rbp)
jl 0x2964b0
movq -0x28(%rbp), %rax
imulq $0x1c, -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movl 0xc(%rax), %eax
shll %eax
movq -0x60(%rbp), %rcx
movl 0x18(%rcx), %ecx
shrl $0x1f, %ecx
orl %ecx, %eax
movl %eax, -0x68(%rbp)
movq -0x60(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movl %ecx, 0x18(%rax)
movq -0x60(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
jne 0x29637f
jmp 0x29649f
cmpq $0x0, -0x58(%rbp)
je 0x296491
movq -0x60(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x58(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0x296491
movq -0x58(%rbp), %rax
movl 0xc(%rax), %ecx
shll %ecx
movl %ecx, 0xc(%rax)
movq -0x58(%rbp), %rax
movl 0xc(%rax), %ecx
shrl %ecx
movl %ecx, 0xc(%rax)
movq -0x60(%rbp), %rax
movl 0xc(%rax), %ecx
shll %ecx
movl %ecx, 0xc(%rax)
movq -0x60(%rbp), %rax
movl 0xc(%rax), %ecx
shrl %ecx
movl %ecx, 0xc(%rax)
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rsi
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %rdx
movq %r9, %rcx
movq %r9, %r8
callq 0x71a90
movq %rax, -0x40(%rbp)
movq -0x58(%rbp), %rax
movl 0xc(%rax), %ecx
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0xc(%rax)
movq -0x60(%rbp), %rax
movl 0xc(%rax), %ecx
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0xc(%rax)
cmpq $0x0, -0x40(%rbp)
je 0x296485
movl -0x64(%rbp), %eax
cmpl -0x68(%rbp), %eax
je 0x296485
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x64(%rbp), %edx
xorl $0x1, %edx
movl -0x68(%rbp), %ecx
xorl $0x1, %ecx
movq -0x18(%rbp), %r8
movsd -0x20(%rbp), %xmm0
movq -0x40(%rbp), %r9
leaq -0x48(%rbp), %rax
movq $0x1, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x292000
cmpq $0x0, %rax
je 0x296485
movq -0x38(%rbp), %rax
movl %eax, %edx
movq -0x58(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl %edx, %ecx
movl %ecx, 0x18(%rax)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x29648f
movq $0x0, -0x50(%rbp)
jmp 0x2964b0
jmp 0x296491
movq -0x60(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x68(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x296320
movq -0x50(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)