// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: rd_hm_drop(asg_t*, asg_t*, unsigned int, unsigned int, double, unsigned int, buf_t*)
uint64_t rd_hm_drop(asg_t *g, asg_t *ref, uint32_t v0, uint32_t v1, double cutoff, uint32_t drop_inexact, buf_t *b)
{
    uint32_t i1, ncut = 0;
    uint32_t v, w, nv1, i; asg_arc_t *av1; 
    if (g->seq[v0>>1].del) return 0; // already deleted    
    ///b->S is the nodes with all incoming edges visited
    b->S.n = 0;
    kv_push(uint32_t, b->S, v0);    
    while(b->S.n) {
        v = kv_pop(b->S); 
        if(b->a[v].s) continue;
        b->a[v].s = 1; 
        kv_push(uint32_t, b->b, v); // save it for revert
        nv1 = asg_arc_n(ref, v); av1 = asg_arc_a(ref, v);
        for (i1 = 0; i1 < nv1; ++i1) { // loop through v's neighbors
            if (av1[i1].del) continue;
            w = av1[i1].v;
            if(b->a[w].s || w == v1) continue;
            kv_push(uint32_t, b->S, w);
        }
    }
    for (i = 0; i < b->b.n; ++i) { // clear the states of visited vertices
        v = b->b.a[i]; b->a[b->b.a[i]].s = 0;
        if(v == v0 || v == v1) continue;
        ncut += rd_hm_drop0(g, ref, v, cutoff, drop_inexact);
        ncut += rd_hm_drop0(g, ref, v^1, cutoff, drop_inexact);
    }
    ncut += rd_hm_drop0(g, ref, v0, cutoff, drop_inexact);
    ncut += rd_hm_drop0(g, ref, v1^1, cutoff, drop_inexact);
    return ncut;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movsd %xmm0, 0x10(%rsp)
movl %ecx, 0xc(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, 0x20(%rsp)
movq 0x20(%rdi), %rax
movl %edx, 0x8(%rsp)
movl %edx, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xe3dd4
movq %r9, %r13
movl %r8d, 0x4(%rsp)
movq $0x0, 0x8(%r9)
cmpq $0x0, 0x10(%r9)
jne 0xe3bdd
movq $0x2, 0x10(%r13)
movq 0x18(%r13), %rdi
movl $0x8, %esi
callq 0x2370
movq %rax, 0x18(%r13)
movq 0x8(%r13), %rcx
movq 0x18(%r13), %rdx
movq %rcx, %rax
incq %rax
movq %rax, 0x8(%r13)
movl 0x8(%rsp), %esi
movl %esi, (%rdx,%rcx,4)
je 0xe3d37
movq (%r13), %rcx
movq 0x18(%r13), %rdx
leaq -0x1(%rax), %rsi
movq %rsi, 0x8(%r13)
movl -0x4(%rdx,%rax,4), %ebx
leaq (%rbx,%rbx,8), %rax
leaq (%rax,%rax,2), %rax
addq %rbx, %rax
movl 0x18(%rcx,%rax), %edx
testl %edx, %edx
js 0xe3d2a
addq %rcx, %rax
addq $0x18, %rax
orl $0x80000000, %edx       # imm = 0x80000000
movl %edx, (%rax)
movq 0x40(%r13), %rax
cmpq %rax, 0x38(%r13)
jne 0xe3c65
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x40(%r13)
movq 0x48(%r13), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %rax, 0x48(%r13)
movq 0x38(%r13), %rax
movq 0x48(%r13), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x38(%r13)
movl %ebx, (%rcx,%rax,4)
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rax
movq (%rax,%rbx,8), %rax
testl %eax, %eax
je 0xe3d2a
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %r15
addq $0xc, %r15
shlq $0x3, %rax
leaq (%rax,%rax,2), %r12
xorl %ebx, %ebx
cmpl $0x0, (%r15,%rbx)
js 0xe3d21
movl -0x4(%r15,%rbx), %r14d
cmpl 0xc(%rsp), %r14d
je 0xe3d21
movq (%r13), %rax
leaq (%r14,%r14,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r14, %rcx
cmpl $0x0, 0x18(%rax,%rcx)
js 0xe3d21
movq 0x10(%r13), %rax
cmpq %rax, 0x8(%r13)
jne 0xe3d0d
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x10(%r13)
movq 0x18(%r13), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %rax, 0x18(%r13)
movq 0x8(%r13), %rax
movq 0x18(%r13), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x8(%r13)
movl %r14d, (%rcx,%rax,4)
addq $0x18, %rbx
cmpq %rbx, %r12
jne 0xe3cb5
movq 0x8(%r13), %rax
testq %rax, %rax
jne 0xe3bfc
cmpq $0x0, 0x38(%r13)
je 0xe3dd8
xorl %eax, %eax
movl $0x1, %r12d
movl $0x0, (%rsp)
movq 0x20(%rsp), %r15
movq 0x18(%rsp), %r14
movq (%r13), %rcx
movq 0x48(%r13), %rdx
movl (%rdx,%rax,4), %ebx
leaq (%rbx,%rbx,8), %rax
leaq (%rax,%rax,2), %rax
addq %rbx, %rax
andl $0x7fffffff, 0x18(%rcx,%rax) # imm = 0x7FFFFFFF
cmpl 0x8(%rsp), %ebx
sete %al
cmpl 0xc(%rsp), %ebx
sete %cl
orb %al, %cl
jne 0xe3dc6
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
movsd 0x10(%rsp), %xmm0
movl 0x4(%rsp), %ecx
callq 0xe38aa
movl (%rsp), %ebp
addl %eax, %ebp
xorl $0x1, %ebx
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
movsd 0x10(%rsp), %xmm0
movl 0x4(%rsp), %ecx
callq 0xe38aa
addl %ebp, %eax
movl %eax, (%rsp)
movl %r12d, %eax
incl %r12d
cmpq %rax, 0x38(%r13)
ja 0xe3d5b
jmp 0xe3ddf
xorl %eax, %eax
jmp 0xe3e2b
movl $0x0, (%rsp)
movq 0x20(%rsp), %r15
movq %r15, %rdi
movq 0x18(%rsp), %r14
movq %r14, %rsi
movl 0x8(%rsp), %edx
movsd 0x10(%rsp), %xmm0
movl 0xc(%rsp), %r12d
movl 0x4(%rsp), %ebp
movl %ebp, %ecx
callq 0xe38aa
movq %rax, %rbx
addl (%rsp), %ebx
xorl $0x1, %r12d
movq %r15, %rdi
movq %r14, %rsi
movl %r12d, %edx
movsd 0x10(%rsp), %xmm0
movl %ebp, %ecx
callq 0xe38aa
addl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq