// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: cal_exact_ug_o(dedup_idx_t*, ma_utg_t*, unsigned long)
int64_t cal_exact_ug_o(dedup_idx_t *idx, ma_utg_t *u, uint64_t f)
{
    if(u->n <= 0) return INT32_MIN;
    uint64_t sv, *sa, sn, ev, *ea, en, si, ei, zn, *za, rev, k, nf = (uint64_t)-1, m, fn, nfn; ma_utg_t *z;
    if(f == FATHER) nf = MOTHER; if(f == MOTHER) nf = FATHER;
    sv = u->a[0]>>32; sa = idx->ra + idx->ridx[sv>>1]; sn = idx->ridx[(sv>>1)+1]-idx->ridx[sv>>1];
    ev = u->a[u->n-1]>>32; ea = idx->ra + idx->ridx[ev>>1]; en = idx->ridx[(ev>>1)+1] - idx->ridx[ev>>1];
    for (si = 0; si < sn; si++) {
        z = &(idx->ug->u.a[sa[si]>>32]);
        if((z->n == 0) || (z->m == 0) || (idx->ug->g->seq[sa[si]>>32].del)) continue;
        assert(((z->a[(uint32_t)sa[si]]>>32)>>1) == (sv>>1));
        if((z->a[(uint32_t)sa[si]]>>32) == sv) rev = 0;
        else rev = 1;
        for (ei = 0; ei < en; ei++) {
            if((idx->ug->u.a[ea[ei]>>32].n == 0) || (idx->ug->u.a[ea[ei]>>32].m == 0) || (idx->ug->g->seq[ea[ei]>>32].del)) continue;
            assert(((idx->ug->u.a[ea[ei]>>32].a[(uint32_t)ea[ei]]>>32)>>1) == (ev>>1));
            if((sa[si]>>32) != (ea[ei]>>32)) continue;///not the same uid            
            if(((uint32_t)sa[si]) >= ((uint32_t)ea[ei])) {
                zn = ((uint32_t)sa[si]) - ((uint32_t)ea[ei]) + 1; za = z->a + ((uint32_t)ea[ei]);
            } else {
                zn = ((uint32_t)ea[ei]) - ((uint32_t)sa[si]) + 1; za = z->a + ((uint32_t)sa[si]);
            }
            if(u->n != zn) continue;
            if(!rev) {
                for (k = 0; (k < zn) && ((u->a[k]>>32) == ((za[k]>>32))); k++);
                if(k < zn) continue;
            } else {
                for (k = 0; (k < zn) && ((u->a[k]>>32) == (((uint64_t)(za[zn-k-1]>>32))^1)); k++);
                if(k < zn) continue;
            }
            
            assert(u->n <= z->n);
            if(u->n < z->n) {
                return -1;///delete u
            } else if(u->n == z->n) {
                for (m = fn = nfn = 0; m < u->n; m++) {
                    if(R_INF.trio_flag[u->a[m]>>33] == f) fn++;
                    if(R_INF.trio_flag[u->a[m]>>33] == nf) nfn++;
                }
                if(fn < nfn) return -1;///delete u
                else return sa[si]>>32;///delete z
            }
        }
    }
    return INT32_MIN;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl 0x10(%rsi), %ecx
movq $-0x80000000, %rax      # imm = 0x80000000
testq %rcx, %rcx
je 0x9d1bd
xorl %eax, %eax
cmpq $0x1, %rdx
sete %al
leaq (%rax,%rax,2), %rax
decq %rax
movq %rdx, 0x10(%rsp)
cmpq $0x2, %rdx
pushq $0x1
popq %rdx
cmovneq %rax, %rdx
movq %rdx, 0x8(%rsp)
movq 0x18(%rsi), %rbx
movq (%rbx), %rsi
movq 0x10(%rdi), %rax
movq 0x18(%rdi), %rdx
movq %rsi, 0x18(%rsp)
movq %rsi, %r8
shrq $0x21, %r8
movl (%rax,%r8,4), %esi
movq %r8, 0x20(%rsp)
movl 0x4(%rax,%r8,4), %r8d
leaq (%rdx,%rsi,8), %r9
movq %r9, 0x48(%rsp)
subl %esi, %r8d
movq %r8, 0x50(%rsp)
movq %rcx, (%rsp)
leal -0x1(%rcx), %esi
movq (%rbx,%rsi,8), %rcx
shrq $0x21, %rcx
movl (%rax,%rcx,4), %esi
movq %rcx, 0x40(%rsp)
movl 0x4(%rax,%rcx,4), %r12d
leaq (%rdx,%rsi,8), %r13
subl %esi, %r12d
xorl %ebp, %ebp
movq %rdi, 0x38(%rsp)
cmpq 0x50(%rsp), %rbp
je 0x9d1b6
movq (%rdi), %rsi
movq 0x10(%rsi), %rax
movq 0x48(%rsp), %rcx
movq (%rcx,%rbp,8), %r11
movq %r11, %r9
shrq $0x20, %r9
imulq $0x28, %r9, %rdx
movl 0x10(%rax,%rdx), %r10d
testl %r10d, %r10d
je 0x9d139
addq %rax, %rdx
cmpl $0x0, 0xc(%rdx)
je 0x9d139
movq 0x18(%rsi), %rsi
movq 0x20(%rsi), %r14
cmpl $0x0, (%r14,%r9,8)
js 0x9d139
movq 0x18(%rdx), %rcx
movl %r11d, %edx
movq (%rcx,%rdx,8), %rdi
movq %rdi, %rsi
shrq $0x21, %rsi
cmpl 0x20(%rsp), %esi
jne 0x9d1eb
movq %rcx, 0x30(%rsp)
leaq (%rcx,%rdx,8), %rcx
movq %rcx, 0x28(%rsp)
xorq 0x18(%rsp), %rdi
shrq $0x20, %rdi
xorl %r15d, %r15d
cmpq %r12, %r15
je 0x9d139
movq (%r13,%r15,8), %rdx
movq %rdx, %r8
shrq $0x20, %r8
imulq $0x28, %r8, %rsi
cmpl $0x0, 0x10(%rax,%rsi)
je 0x9d131
addq %rax, %rsi
cmpl $0x0, 0xc(%rsi)
je 0x9d131
cmpl $0x0, (%r14,%r8,8)
js 0x9d131
movq 0x18(%rsi), %rcx
movl %edx, %esi
movq (%rcx,%rsi,8), %rcx
shrq $0x21, %rcx
cmpl 0x40(%rsp), %ecx
jne 0x9d1cc
cmpl %r8d, %r9d
jne 0x9d131
movq %r11, %rcx
subq %rdx, %rcx
movq %rdx, %r8
subq %r11, %r8
cmpl %edx, %r11d
movq 0x30(%rsp), %rdx
leaq (%rdx,%rsi,8), %rdx
cmovaeq %rcx, %r8
cmovbq 0x28(%rsp), %rdx
incq %r8
cmpl %r8d, (%rsp)
jne 0x9d131
movl %r8d, %r8d
testq %rdi, %rdi
jne 0x9d114
xorl %esi, %esi
cmpq %rsi, %r8
je 0x9d146
movq (%rdx,%rsi,8), %rcx
xorq (%rbx,%rsi,8), %rcx
shrq $0x20, %rcx
incq %rsi
testq %rcx, %rcx
je 0x9d0f9
jmp 0x9d131
movq %rbx, %rsi
subq $0x1, %r8
jb 0x9d146
movq (%rdx,%r8,8), %rcx
xorq (%rsi), %rcx
shrq $0x20, %rcx
addq $0x8, %rsi
cmpl $0x1, %ecx
je 0x9d117
incq %r15
jmp 0x9d06b
incq %rbp
movq 0x38(%rsp), %rdi
jmp 0x9cfe1
movq (%rsp), %r11
cmpl %r10d, %r11d
ja 0x9d20a
cmpl %r10d, %r11d
movq 0x10(%rsp), %r10
movq 0x8(%rsp), %r14
jae 0x9d167
pushq $-0x1
popq %rax
jmp 0x9d1bd
leaq 0x1b70c2(%rip), %rax    # 0x254230
movq 0x28(%rax), %rax
xorl %edx, %edx
xorl %edi, %edi
xorl %r8d, %r8d
cmpq %rdx, %r11
je 0x9d1a7
movq (%rbx,%rdx,8), %rcx
shrq $0x21, %rcx
movzbl (%rax,%rcx), %ecx
xorl %esi, %esi
cmpq %r10, %rcx
sete %sil
addq %rsi, %rdi
xorl %esi, %esi
cmpq %rcx, %r14
sete %sil
addq %rsi, %r8
incq %rdx
jmp 0x9d179
cmpq %r8, %rdi
pushq $-0x1
popq %rax
cmovbq %rax, %r9
movq %r9, %rax
jmp 0x9d1bd
movq $-0x80000000, %rax      # imm = 0x80000000
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x14c539(%rip), %rdi    # 0x1e970c
leaq 0x14abb7(%rip), %rsi    # 0x1e7d91
leaq 0x14c4ef(%rip), %rcx    # 0x1e96d0
movl $0x53bb, %edx           # imm = 0x53BB
callq 0x2110
leaq 0x14c4b1(%rip), %rdi    # 0x1e96a3
leaq 0x14ab98(%rip), %rsi    # 0x1e7d91
leaq 0x14c4d0(%rip), %rcx    # 0x1e96d0
movl $0x53b6, %edx           # imm = 0x53B6
callq 0x2110
leaq 0x14c53e(%rip), %rdi    # 0x1e974f
leaq 0x14ab79(%rip), %rsi    # 0x1e7d91
leaq 0x14c4b1(%rip), %rcx    # 0x1e96d0
movl $0x53cb, %edx           # imm = 0x53CB
callq 0x2110