// File: 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
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x18(%rbp)
jg 0x2a3c1b
movq $0x0, -0x8(%rbp)
jmp 0x2a3f61
leaq -0x3c(%rbp), %rdi
xorl %esi, %esi
movl $0x1c, %edx
callq 0x2100
movq $-0x1, -0x48(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0x2a3cf5
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
cmpq -0x48(%rbp), %rax
jle 0x2a3cce
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq %rax, -0x48(%rbp)
movq -0x50(%rbp), %rax
movl %eax, -0x3c(%rbp)
movq -0x58(%rbp), %rax
movl %eax, -0x2c(%rbp)
movq -0x58(%rbp), %rax
movq -0x10(%rbp), %rcx
movq -0x50(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
addq %rcx, %rax
movl %eax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movl -0x28(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x2a3c43
movq -0x20(%rbp), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %ecx
movq -0x20(%rbp), %rdx
movl -0x28(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
imulq $0x28, %rax, %rax
addq %rax, %rdx
xorl %eax, %eax
cmpl 0x14(%rdx), %ecx
movb %al, -0x79(%rbp)
jg 0x2a3d50
movq -0x20(%rbp), %rax
movl -0x28(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
movq -0x20(%rbp), %rcx
movl -0x2c(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x18(%rcx), %eax
setge %al
movb %al, -0x79(%rbp)
movb -0x79(%rbp), %al
testb $0x1, %al
jne 0x2a3d59
jmp 0x2a3d5b
jmp 0x2a3d7a
leaq 0xee094(%rip), %rdi     # 0x391df6
leaq 0xecac6(%rip), %rsi     # 0x39082f
movl $0x1609, %edx           # imm = 0x1609
leaq 0xee0b6(%rip), %rcx     # 0x391e2b
callq 0x2130
movq $0x0, -0x58(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0x2a3f45
movq -0x20(%rbp), %rax
imulq $0x28, -0x58(%rbp), %rcx
addq %rcx, %rax
movslq 0x14(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rax
movq -0x58(%rbp), %rcx
subq $0x1, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movslq 0x18(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x50(%rbp), %rax
movl -0x3c(%rbp), %ecx
cmpq %rcx, %rax
jne 0x2a3dee
jmp 0x2a3f34
movl -0x34(%rbp), %eax
cmpq -0x68(%rbp), %rax
ja 0x2a3e03
movl -0x34(%rbp), %eax
movq %rax, -0x88(%rbp)
jmp 0x2a3e0e
movq -0x68(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x90(%rbp)
movl -0x38(%rbp), %eax
cmpq -0x60(%rbp), %rax
jb 0x2a3e31
movl -0x38(%rbp), %eax
movq %rax, -0x98(%rbp)
jmp 0x2a3e3c
movq -0x60(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rax
movq -0x98(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x2a3eb7
movl -0x34(%rbp), %eax
cmpq -0x68(%rbp), %rax
ja 0x2a3e64
movl -0x34(%rbp), %eax
movq %rax, -0xa0(%rbp)
jmp 0x2a3e6f
movq -0x68(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0xa8(%rbp)
movl -0x38(%rbp), %eax
cmpq -0x60(%rbp), %rax
jb 0x2a3e92
movl -0x38(%rbp), %eax
movq %rax, -0xb0(%rbp)
jmp 0x2a3e9d
movq -0x60(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rax
movq -0xb0(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0xb8(%rbp)
jmp 0x2a3ec2
xorl %eax, %eax
movq %rax, -0xb8(%rbp)
jmp 0x2a3ec2
movq -0xb8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
movq -0x60(%rbp), %rcx
subq %rcx, %rax
movq -0x70(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x78(%rbp)
movaps 0xde126(%rip), %xmm1    # 0x382010
movq -0x78(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0xde125(%rip), %xmm1    # 0x382020
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movl -0x38(%rbp), %ecx
movl -0x34(%rbp), %eax
subl %ecx, %eax
cvtsi2sd %rax, %xmm1
movsd 0xec811(%rip), %xmm2    # 0x390730
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2a3f32
cmpq $0x8, -0x78(%rbp)
jbe 0x2a3f32
jmp 0x2a3f45
jmp 0x2a3f34
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x2a3d8a
movq -0x50(%rbp), %rax
cmpq -0x18(%rbp), %rax
jl 0x2a3f59
movq $0x1, -0x8(%rbp)
jmp 0x2a3f61
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nop