// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: detect_simple_bubble(asg_t*, unsigned int, unsigned int*, long long*, buf_t*)
int detect_simple_bubble(asg_t *g, uint32_t begNode, uint32_t* endNode, long long* minLen, buf_t* b)
{
    uint32_t e1, e2;
    long long l1, l2;

    if(asg_arc_n(g, begNode) != 2)
    {
        return 0;
    }

    if(asg_is_single_edge(g, asg_arc_a(g, begNode)[0].v, begNode>>1)!=1
      || 
       asg_is_single_edge(g, asg_arc_a(g, begNode)[1].v, begNode>>1)!=1)
    {
        return 0;
    }

    if(b) kv_push(uint32_t, b->b, begNode>>1);

    


    if(detect_single_path(g, asg_arc_a(g, begNode)[0].v, &e1, &l1, b) == TWO_INPUT 
       && 
       detect_single_path(g, asg_arc_a(g, begNode)[1].v, &e2, &l2, b) == TWO_INPUT)
    {
        if(e1 == e2)
        {
            (*endNode) = e1;
            (*minLen) = (l1 <= l2)? l1: l2;
            (*minLen)++;
            return 1;
        }
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %r15
movq %rdx, %r8
movq 0x28(%rdi), %rax
movl %esi, %ebx
movq (%rax,%rbx,8), %rdx
cmpl $0x2, %edx
jne 0xa4af6
movq %rcx, %r13
movl %esi, %ebp
movq %rdi, %r12
movq 0x8(%rdi), %rcx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
movl 0x8(%rcx,%rdx,8), %edx
shrl %ebp
xorq $0x1, %rdx
movq (%rax,%rdx,8), %r14
testl %r14d, %r14d
jle 0xa4bb6
movq %r14, %rdx
shrq $0x20, %rdx
movl %r14d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rdx
addq $0x8, %rdx
xorl %ecx, %ecx
movl $0x1, %esi
movl (%rdx), %edi
shrl %edi
cmpl %ebp, %edi
cmovel %esi, %ecx
addq $0x18, %rdx
decq %rax
jne 0xa4a21
testl %ecx, %ecx
je 0xa4bb9
cmpl $0x1, %r14d
jne 0xa4af6
movq 0x8(%r12), %rcx
movq 0x28(%r12), %rax
movl 0x4(%rax,%rbx,8), %edx
leaq (%rdx,%rdx,2), %rdx
movl 0x20(%rcx,%rdx,8), %edx
xorq $0x1, %rdx
movq (%rax,%rdx,8), %r14
testl %r14d, %r14d
movq %r13, 0x10(%rsp)
jle 0xa4be8
movq %r14, %rdx
shrq $0x20, %rdx
movl %r14d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rdx
addq $0x8, %rdx
xorl %ecx, %ecx
movl $0x1, %esi
movl (%rdx), %edi
shrl %edi
cmpl %ebp, %edi
cmovel %esi, %ecx
addq $0x18, %rdx
decq %rax
jne 0xa4a93
testl %ecx, %ecx
je 0xa4beb
xorl %r13d, %r13d
cmpl $0x1, %r14d
jne 0xa4af9
testq %r15, %r15
je 0xa4b1a
movq 0x38(%r15), %rcx
cmpq 0x40(%r15), %rcx
jne 0xa4b0b
leaq (%rcx,%rcx), %rax
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rax, %rsi
movq %rsi, 0x40(%r15)
movq 0x48(%r15), %rdi
shlq $0x2, %rsi
movq %r8, %r14
callq 0x2370
movq %r14, %r8
movq %rax, 0x48(%r15)
movq 0x38(%r15), %rcx
jmp 0xa4b0f
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x48(%r15), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, 0x38(%r15)
movl %ebp, (%rax,%rcx,4)
movq %r8, %r14
movq 0x8(%r12), %rax
movq 0x28(%r12), %rcx
movl 0x4(%rcx,%rbx,8), %ecx
leaq (%rcx,%rcx,2), %rcx
movl 0x8(%rax,%rcx,8), %esi
leaq 0x4(%rsp), %rdx
leaq 0x20(%rsp), %rcx
movq %r12, %rdi
movq %r15, %r8
callq 0xa4708
cmpl $0x1, %eax
jne 0xa4af9
movq 0x8(%r12), %rax
movq 0x28(%r12), %rcx
movl 0x4(%rcx,%rbx,8), %ecx
leaq (%rcx,%rcx,2), %rcx
movl 0x20(%rax,%rcx,8), %esi
movq %rsp, %rdx
leaq 0x18(%rsp), %rcx
movq %r12, %rdi
movq %r15, %r8
callq 0xa4708
cmpl $0x1, %eax
jne 0xa4af9
movl 0x4(%rsp), %eax
cmpl (%rsp), %eax
jne 0xa4af9
movl %eax, (%r14)
movq 0x20(%rsp), %rax
movq 0x18(%rsp), %rcx
cmpq %rcx, %rax
cmovlq %rax, %rcx
incq %rcx
movq 0x10(%rsp), %rax
movq %rcx, (%rax)
movl $0x1, %r13d
jmp 0xa4af9
xorl %r14d, %r14d
movq 0x1f0420(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x194550(%rip), %rdi    # 0x23911a
movl $0xa, %esi
movl $0x1, %edx
movq %r8, 0x8(%rsp)
callq 0x2410
movq 0x8(%rsp), %r8
jmp 0xa4a3b
xorl %r14d, %r14d
movq 0x1f03ee(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x19451e(%rip), %rdi    # 0x23911a
movl $0xa, %esi
movl $0x1, %edx
movq %r8, %r13
callq 0x2410
movq %r13, %r8
jmp 0xa4aad