// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movsd %xmm0, 0x20(%rsp)
movl %ecx, %ebp
movq %rsi, 0x10(%rsp)
movq %rdi, 0x30(%rsp)
movq 0x20(%rdi), %rax
movl %edx, 0xc(%rsp)
movl %edx, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xe5321
movq %r9, %r13
movl %r8d, 0x1c(%rsp)
movq $0x0, 0x8(%r9)
cmpq $0x0, 0x10(%r9)
je 0xe5328
movq 0x18(%r13), %rax
movl 0xc(%rsp), %ecx
movl %ecx, (%rax)
movl $0x1, %ecx
jmp 0xe535d
xorl %eax, %eax
jmp 0xe5594
movq $0x2, 0x10(%r13)
movq 0x18(%r13), %rdi
movl $0x8, %esi
callq 0x2370
movq %rax, 0x18(%r13)
movq 0x8(%r13), %rdx
movq %rdx, %rcx
incq %rcx
movq %rcx, 0x8(%r13)
movl 0xc(%rsp), %esi
movl %esi, (%rax,%rdx,4)
je 0xe5495
movq (%r13), %rax
movq 0x18(%r13), %rdx
leaq -0x1(%rcx), %rsi
movq %rsi, 0x8(%r13)
movl -0x4(%rdx,%rcx,4), %r14d
leaq (%r14,%r14,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r14, %rcx
movl 0x18(%rax,%rcx), %edx
testl %edx, %edx
js 0xe5488
addq %rcx, %rax
addq $0x18, %rax
orl $0x80000000, %edx       # imm = 0x80000000
movl %edx, (%rax)
movq 0x38(%r13), %rcx
movq 0x48(%r13), %rax
cmpq 0x40(%r13), %rcx
jne 0xe53ce
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x40(%r13)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x48(%r13)
movq 0x38(%r13), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x38(%r13)
movl %r14d, (%rax,%rcx,4)
movq 0x10(%rsp), %rax
movq 0x28(%rax), %rax
movq (%rax,%r14,8), %rax
testl %eax, %eax
je 0xe5488
movq 0x10(%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 %r14d, %r14d
cmpl $0x0, (%r15,%r14)
js 0xe547f
movl -0x4(%r15,%r14), %ebx
cmpl %ebp, %ebx
je 0xe547f
movq (%r13), %rax
leaq (%rbx,%rbx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rbx, %rcx
cmpl $0x0, 0x18(%rax,%rcx)
js 0xe547f
movq 0x8(%r13), %rcx
movq 0x18(%r13), %rax
cmpq 0x10(%r13), %rcx
jne 0xe5474
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r13)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x18(%r13)
movq 0x8(%r13), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r13)
movl %ebx, (%rax,%rcx,4)
addq $0x18, %r14
cmpq %r14, %r12
jne 0xe5418
movq 0x8(%r13), %rcx
testq %rcx, %rcx
jne 0xe535d
cmpq $0x0, 0x38(%r13)
je 0xe5541
xorl %eax, %eax
movl $0x1, %r12d
movl $0x0, 0x8(%rsp)
movl %ebp, 0x2c(%rsp)
movq 0x30(%rsp), %r15
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 0xc(%rsp), %ebx
sete %al
cmpl %ebp, %ebx
sete %cl
orb %al, %cl
jne 0xe552f
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movl %ebx, %edx
movsd 0x20(%rsp), %xmm0
movl 0x1c(%rsp), %ebp
movl %ebp, %ecx
callq 0xe4ffd
movl 0x8(%rsp), %r14d
addl %eax, %r14d
xorl $0x1, %ebx
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movl %ebx, %edx
movsd 0x20(%rsp), %xmm0
movl %ebp, %ecx
movl 0x2c(%rsp), %ebp
callq 0xe4ffd
addl %r14d, %eax
movl %eax, 0x8(%rsp)
movl %r12d, %eax
incl %r12d
cmpq %rax, 0x38(%r13)
ja 0xe54b9
jmp 0xe5549
movl $0x0, 0x8(%rsp)
movq 0x30(%rsp), %r15
movq %r15, %rdi
movq 0x10(%rsp), %r14
movq %r14, %rsi
movl 0xc(%rsp), %edx
movsd 0x20(%rsp), %xmm0
movl %ebp, %r12d
movl 0x1c(%rsp), %ebp
movl %ebp, %ecx
callq 0xe4ffd
movq %rax, %rbx
addl 0x8(%rsp), %ebx
xorl $0x1, %r12d
movq %r15, %rdi
movq %r14, %rsi
movl %r12d, %edx
movsd 0x20(%rsp), %xmm0
movl %ebp, %ecx
callq 0xe4ffd
addl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq