// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: is_best_pair(ul_resolve_t*, usg_t*, unsigned long*, unsigned long*, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long*, unsigned long*, asg64_v*, asg64_v*, unsigned char*, double)
uint64_t is_best_pair(ul_resolve_t *uidx, usg_t *ng, uint64_t *int_idx, uint64_t *int_a, 
uint64_t s, uint64_t e, uint64_t it, uint64_t v, uint64_t *ridx_a, uint64_t *ridx, 
asg64_v *b0, asg64_v *b1, uint8_t *f, double cutoff)
{
    uint64_t *arc_a, arc_n, k, is, ie, w0 = 0, w1 = 0, sup_cut = 3; 
    if(!gen_sub_integer_path_ff(int_a, s, e, it, v, f, b0)) return 0;
    assert(b0->n >= 2); assert(f[b0->a[0]] && f[b0->a[b0->n-1]^1]);
    w0 = get_arc_support_chain(uidx, b0->a, b0->n, ng);
    if(w0 < sup_cut) return 0;

    arc_a = ridx_a + (ridx[v>>1]>>32); 
    arc_n = (uint32_t)ridx[v>>1];
    for (k = 0; k < arc_n; k++) {
        if(it == ((uint32_t)arc_a[k])) continue;
        is = int_idx[arc_a[k]>>32]>>32; 
        ie = is + ((uint32_t)(int_idx[arc_a[k]>>32])); 
        if(!gen_sub_integer_path_ff(int_a, is, ie, ((uint32_t)arc_a[k]), v, f, b1)) continue;
        assert(b1->n >= 2); assert(f[b1->a[0]] && f[b1->a[b1->n-1]^1]);
        if((b0->n == b1->n) && (memcmp(b0->a, b1->a, sizeof((*(b0->a)))*b0->n) == 0)) {
            if(it < ((uint32_t)arc_a[k])) continue;
            else return 0;///only keep 1 equal interval
        }
        w1 = get_arc_support_chain(uidx, b1->a, b1->n, ng);
        // fprintf(stderr, "[M::%s::] w0::%lu, w1::%lu\n", __func__, w0, w1);
        if((w0 <= w1) || (w1 > (w0*cutoff))) return 0;
    }
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movsd %xmm0, -0x40(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x3, -0x80(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq 0x10(%rbp), %rcx
movq 0x18(%rbp), %r8
movq 0x40(%rbp), %r9
movq 0x30(%rbp), %rax
movq %rax, (%rsp)
callq 0x362c30
cmpq $0x0, %rax
jne 0x363054
movq $0x0, -0x8(%rbp)
jmp 0x3633ae
movq 0x30(%rbp), %rax
cmpq $0x2, (%rax)
jb 0x363060
jmp 0x36307f
leaq 0x371e9(%rip), %rdi     # 0x39a250
leaq 0x3314b(%rip), %rsi     # 0x3961b9
movl $0x3776, %edx           # imm = 0x3776
leaq 0x371e1(%rip), %rcx     # 0x39a25b
callq 0x2130
movq 0x40(%rbp), %rcx
movq 0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rdx
xorl %eax, %eax
cmpb $0x0, (%rcx,%rdx)
movb %al, -0x81(%rbp)
je 0x3630c8
movq 0x40(%rbp), %rax
movq 0x30(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq 0x30(%rbp), %rdx
movq (%rdx), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
xorq $0x1, %rcx
cmpb $0x0, (%rax,%rcx)
setne %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %al
testb $0x1, %al
jne 0x3630d4
jmp 0x3630d6
jmp 0x3630f5
leaq 0x3722e(%rip), %rdi     # 0x39a30b
leaq 0x330d5(%rip), %rsi     # 0x3961b9
movl $0x3776, %edx           # imm = 0x3776
leaq 0x3716b(%rip), %rcx     # 0x39a25b
callq 0x2130
movq -0x10(%rbp), %rdi
movq 0x30(%rbp), %rax
movq 0x10(%rax), %rsi
movq 0x30(%rbp), %rax
movq (%rax), %rdx
movq -0x18(%rbp), %rcx
callq 0x35c120
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x80(%rbp), %rax
jae 0x36312c
movq $0x0, -0x8(%rbp)
jmp 0x3633ae
movq 0x20(%rbp), %rax
movq 0x28(%rbp), %rcx
movq 0x18(%rbp), %rdx
shrq %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq 0x28(%rbp), %rax
movq 0x18(%rbp), %rcx
shrq %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x3633a6
movq 0x10(%rbp), %rax
movq -0x48(%rbp), %rcx
movq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
cmpq %rcx, %rax
jne 0x363195
jmp 0x363395
movq -0x20(%rbp), %rax
movq -0x48(%rbp), %rcx
movq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x20(%rbp), %rcx
movq -0x48(%rbp), %rdx
movq -0x58(%rbp), %rsi
movq (%rdx,%rsi,8), %rdx
shrq $0x20, %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq -0x48(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movl %eax, %ecx
movq 0x18(%rbp), %r8
movq 0x40(%rbp), %r9
movq 0x38(%rbp), %rax
movq %rax, (%rsp)
callq 0x362c30
cmpq $0x0, %rax
jne 0x363216
jmp 0x363395
movq 0x38(%rbp), %rax
cmpq $0x2, (%rax)
jb 0x363222
jmp 0x363241
leaq 0x37105(%rip), %rdi     # 0x39a32e
leaq 0x32f89(%rip), %rsi     # 0x3961b9
movl $0x3781, %edx           # imm = 0x3781
leaq 0x3701f(%rip), %rcx     # 0x39a25b
callq 0x2130
movq 0x40(%rbp), %rcx
movq 0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rdx
xorl %eax, %eax
cmpb $0x0, (%rcx,%rdx)
movb %al, -0x82(%rbp)
je 0x36328a
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq 0x38(%rbp), %rdx
movq (%rdx), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
xorq $0x1, %rcx
cmpb $0x0, (%rax,%rcx)
setne %al
movb %al, -0x82(%rbp)
movb -0x82(%rbp), %al
testb $0x1, %al
jne 0x363296
jmp 0x363298
jmp 0x3632b7
leaq 0x3709a(%rip), %rdi     # 0x39a339
leaq 0x32f13(%rip), %rsi     # 0x3961b9
movl $0x3781, %edx           # imm = 0x3781
leaq 0x36fa9(%rip), %rcx     # 0x39a25b
callq 0x2130
movq 0x30(%rbp), %rax
movq (%rax), %rax
movq 0x38(%rbp), %rcx
cmpq (%rcx), %rax
jne 0x363315
movq 0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x38(%rbp), %rax
movq 0x10(%rax), %rsi
movq 0x30(%rbp), %rax
movq (%rax), %rdx
shlq $0x3, %rdx
callq 0x20b0
cmpl $0x0, %eax
jne 0x363315
movq 0x10(%rbp), %rax
movq -0x48(%rbp), %rcx
movq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x363308
jmp 0x363395
movq $0x0, -0x8(%rbp)
jmp 0x3633ae
movq -0x10(%rbp), %rdi
movq 0x38(%rbp), %rax
movq 0x10(%rax), %rsi
movq 0x38(%rbp), %rax
movq (%rax), %rdx
movq -0x18(%rbp), %rcx
callq 0x35c120
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x78(%rbp), %rax
jbe 0x363389
movq -0x78(%rbp), %xmm0
movaps 0x1ecc5(%rip), %xmm3    # 0x382010
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x1ecc9(%rip), %xmm2    # 0x382020
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x70(%rbp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
mulsd -0x40(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x363393
movq $0x0, -0x8(%rbp)
jmp 0x3633ae
jmp 0x363395
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x36316b
movq $0x1, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)