// File: chhylp123[P]hifiasm/hic.cpp
// Function: double_check_bub_branch(asg_arc_t*, ma_ug_t*, double*, unsigned int*, double, unsigned int)
int double_check_bub_branch(asg_arc_t *t, ma_ug_t *bs_ug, double *e_w, uint32_t *e_occ, double cutoff, uint32_t max_w_occ)
{
    uint32_t v = t->v^1, w = (t->ul>>32)^1, i, nv, rv, max_i, w_i, *a_occ = NULL;
    asg_arc_t *av = NULL;
    double *aw = NULL, max_w = cutoff - 1, w_w = 1;
    av = asg_arc_a(bs_ug->g, v);
    nv = asg_arc_n(bs_ug->g, v);
    aw = (&e_w[bs_ug->g->idx[v]>>32]);
    a_occ = (&e_occ[bs_ug->g->idx[v]>>32]);

    if(nv <= 1) return 1;

    for (i = rv = 0, max_i = w_i = (uint32_t)-1; i < nv; i++)
    {
        if(av[i].del) continue;
        rv++;
        if(av[i].v == w)
        {
            w_i = i;
            w_w = aw[i];
            continue;
        }
        if(max_i == (uint32_t)-1)
        {
            max_i = i;
            max_w = aw[i];
        }
        else if(max_w < aw[i])
        {
            max_i = i;
            max_w = aw[i];
        }
    }

    if(rv <= 1) return 1; ///must be here

    if(max_i == (uint32_t)-1 || w_i == (uint32_t)-1) return 0;
    ///if(max_w <= max_w_cutoff) return 0; //must be <=
    if(a_occ[max_i] <= max_w_occ) return 0; //must be <=
    
    if(w_w*cutoff < max_w) return 1;
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movsd %xmm0, -0x30(%rbp)
movl %r8d, -0x34(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movl %eax, -0x3c(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movsd -0x30(%rbp), %xmm0
movsd 0x19b3cf(%rip), %xmm1   # 0x382000
subsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movsd 0x19b3be(%rip), %xmm0   # 0x382000
movsd %xmm0, -0x78(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x28(%rcx), %rcx
movl -0x38(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rax
movl -0x38(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x44(%rbp)
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x28(%rcx), %rcx
movl -0x38(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x28(%rcx), %rcx
movl -0x38(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
cmpl $0x1, -0x44(%rbp)
ja 0x1e6ce9
movl $0x1, -0x4(%rbp)
jmp 0x1e6e27
movl $0x0, -0x48(%rbp)
movl $0x0, -0x40(%rbp)
movl $0xffffffff, -0x50(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x4c(%rbp) # imm = 0xFFFFFFFF
movl -0x40(%rbp), %eax
cmpl -0x44(%rbp), %eax
jae 0x1e6dc6
movq -0x60(%rbp), %rax
movl -0x40(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1e6d2f
jmp 0x1e6db8
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
movq -0x60(%rbp), %rax
movl -0x40(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x3c(%rbp), %eax
jne 0x1e6d67
movl -0x40(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x68(%rbp), %rax
movl -0x40(%rbp), %ecx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x78(%rbp)
jmp 0x1e6db8
cmpl $-0x1, -0x4c(%rbp)
jne 0x1e6d86
movl -0x40(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x68(%rbp), %rax
movl -0x40(%rbp), %ecx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x70(%rbp)
jmp 0x1e6db6
movsd -0x70(%rbp), %xmm1
movq -0x68(%rbp), %rax
movl -0x40(%rbp), %ecx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1e6db4
movl -0x40(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x68(%rbp), %rax
movl -0x40(%rbp), %ecx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x70(%rbp)
jmp 0x1e6db6
jmp 0x1e6db8
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x1e6d05
cmpl $0x1, -0x48(%rbp)
ja 0x1e6dd5
movl $0x1, -0x4(%rbp)
jmp 0x1e6e27
cmpl $-0x1, -0x4c(%rbp)
je 0x1e6de1
cmpl $-0x1, -0x50(%rbp)
jne 0x1e6dea
movl $0x0, -0x4(%rbp)
jmp 0x1e6e27
movq -0x58(%rbp), %rax
movl -0x4c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x34(%rbp), %eax
ja 0x1e6e02
movl $0x0, -0x4(%rbp)
jmp 0x1e6e27
movsd -0x78(%rbp), %xmm1
mulsd -0x30(%rbp), %xmm1
movsd -0x70(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1e6e20
movl $0x1, -0x4(%rbp)
jmp 0x1e6e27
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax)