// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: primary_chain_check(unsigned long*, long, mg_lchain_t*)
uint64_t primary_chain_check(uint64_t *idx, int64_t idx_n, mg_lchain_t *a)
{
	if(idx_n <= 0) return 0;
	ul_ov_t m; memset(&m, 0, sizeof(m)); int64_t m_sc = -1, i, a_n; uint64_t s_idx, e_idx, ovlp, novlp;
	for (i = a_n = 0; i < idx_n; ++i) {
        if(((int64_t)(idx[i]>>32)) > m_sc) {
            m_sc = ((int64_t)(idx[i]>>32)); m.qn = i;
            m.ts = a_n; m.te = a_n + ((uint32_t)idx[i]);
            m.qs = a[m.ts].qs; m.qe = a[m.te-1].qe;
        }
        a_n += ((uint32_t)idx[i]);
    }
	assert(a[m.ts].qs<=a[m.te-1].qs && a[m.te-1].qe>=a[m.ts].qe);

	for (i = a_n = 0; i < idx_n; ++i) {
		s_idx = a[a_n].qs; a_n += ((uint32_t)idx[i]); e_idx = a[a_n-1].qe;
		if(i == m.qn) continue;
		ovlp = ((MIN(m.qe, e_idx) > MAX(m.qs, s_idx))? (MIN(m.qe, e_idx) - MAX(m.qs, s_idx)):0);
		novlp = (e_idx - s_idx) - ovlp;
		if(novlp > ((m.qe-m.qs)*GC_OFFSET_RATE) && novlp > GC_OFFSET_POS) break;
	}
	if(i >= idx_n) return 1;
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
xorl %eax, %eax
testq %rsi, %rsi
jle 0x1ac651
movq $-0x1, %rbx
xorl %r10d, %r10d
xorl %r11d, %r11d
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %ebp, %ebp
xorl %r9d, %r9d
movq (%rdi,%r8,8), %r14
movq %r14, %r15
shrq $0x20, %r15
cmpq %rbx, %r15
jle 0x1ac544
movl %ecx, %eax
leaq (%rax,%rax,4), %rax
movl 0x14(%rdx,%rax,8), %r10d
leal (%r14,%rcx), %r9d
leal (%r14,%rcx), %eax
decl %eax
leaq (%rax,%rax,4), %rax
movl 0x18(%rdx,%rax,8), %r11d
movl %ecx, %ebp
movq %r15, %rbx
movl %r8d, %eax
addq %r14, %rcx
incq %r8
cmpq %r8, %rsi
jne 0x1ac50e
movl %ebp, %ecx
leaq (%rcx,%rcx,4), %rcx
movl 0x14(%rdx,%rcx,8), %ebx
decl %r9d
leaq (%r9,%r9,4), %r8
cmpl 0x14(%rdx,%r8,8), %ebx
jg 0x1ac660
leaq (%rdx,%rcx,8), %rcx
leaq (%rdx,%r8,8), %r8
movl 0x18(%r8), %r8d
cmpl 0x18(%rcx), %r8d
jl 0x1ac660
leaq -0x10(%rdx), %rcx
movl %eax, %eax
movl %r11d, %r8d
movl %r10d, %r9d
subl %r10d, %r11d
cvtsi2sd %r11, %xmm0
mulsd 0x872eb(%rip), %xmm0    # 0x233888
movq %rsi, %r10
negq %r10
negq %rax
movl $0x1, %r11d
xorl %ebx, %ebx
movq 0x78c8a(%rip), %xmm1    # 0x225240
movapd 0x78c92(%rip), %xmm2    # 0x225250
xorl %r14d, %r14d
movq %r14, %r13
leaq (%rax,%r11), %r15
movl -0x8(%rdi,%r11,8), %r14d
addq %r13, %r14
cmpq $0x1, %r15
je 0x1ac631
leaq (%r14,%r14,4), %r15
movslq (%rcx,%r15,8), %r15
movq %r8, %r12
cmpq %r15, %r8
jb 0x1ac5e9
movq %r15, %r12
leaq (%r13,%r13,4), %r13
movslq 0x14(%rdx,%r13,8), %r13
movq %r9, %rbp
cmpq %r13, %r9
ja 0x1ac5fe
movq %r13, %rbp
subq %rbp, %r12
jae 0x1ac606
xorl %r12d, %r12d
addq %r13, %r12
subq %r12, %r15
movq %r15, %xmm3
punpckldq %xmm1, %xmm3    # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1]
subpd %xmm2, %xmm3
cmpq $0x9, %r15
jb 0x1ac631
movapd %xmm3, %xmm4
unpckhpd %xmm3, %xmm4            # xmm4 = xmm4[1],xmm3[1]
addsd %xmm3, %xmm4
ucomisd %xmm0, %xmm4
ja 0x1ac64b
cmpq %rsi, %r11
setge %bl
leaq (%r10,%r11), %r15
incq %r15
incq %r11
cmpq $0x1, %r15
jne 0x1ac5c1
movzbl %bl, %eax
andl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x888eb(%rip), %rdi     # 0x234f52
leaq 0x8731d(%rip), %rsi     # 0x23398b
leaq 0x88912(%rip), %rcx     # 0x234f87
movl $0x1609, %edx           # imm = 0x1609
callq 0x2110