// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/hic.cpp
// Function: ma_2_bub_arc(bubble_type*, unsigned int, unsigned int*, unsigned int, unsigned int*, asg_arc_t*, unsigned int)
int ma_2_bub_arc(bubble_type* bub, uint32_t x_0, uint32_t* x_0_b_id, uint32_t x_1, uint32_t* x_1_b_id,
asg_arc_t *p, uint32_t check_het)
{
    uint64_t id0, ori_0, id1, ori_1, tmp_id;
    uint32_t beg, sink, n, *a, x;
    uint32_t beg_0, sink_0, beg_1, sink_1;
    if(x_0_b_id) id0 = (*x_0_b_id);
    if(x_1_b_id) id1 = (*x_1_b_id);
    if((x_0 != (uint32_t)-1) && (x_1 != (uint32_t)-1))
    {
        if(((x_0>>1) == (x_1>>1)))///if we would like to find a edge bridging two nearby bubbles
        {
            if(x_0_b_id == NULL && x_1_b_id == NULL)
            {
                get_bub_id(bub, x_0>>1, &id0, &id1, check_het);
            }
            
            get_bubbles(bub, id0, &beg_0, &sink_0, &a, &n, NULL);//first bubble
            get_bubbles(bub, id1, &beg_1, &sink_1, &a, &n, NULL);//second bubble


            ori_0 = (uint64_t)-1;
            if(x_0 == (beg_0^1))
            {
                ori_0 = 1;
            }
            else if(x_0 == (sink_0^1))
            {
                ori_0 = 0;
            }
            else if(x_0 == (beg_1^1))
            {
                ori_0 = 1+2;
            }
            else if(x_0 == (sink_1^1))
            {
                ori_0 = 0+2;
            }
            else
            {
                fprintf(stderr, "error 0\n");
                return 0;
            }


            ori_1 = (uint64_t)-1;
            if(x_1 == (beg_0^1))
            {
                ori_1 = 1;
            }
            else if(x_1 == (sink_0^1))
            {
                ori_1 = 0;
            }
            else if(x_1 == (beg_1^1))
            {
                ori_1 = 1 + 2;
            }
            else if(x_1 == (sink_1^1))
            {
                ori_1 = 0 + 2;
            }
            else
            {
                fprintf(stderr, "error 1\n");
                return 0;
            }

            

            if((((ori_0>>1)^(ori_1>>1))&1) != 1)
            {
                fprintf(stderr, "error 10\n");
                fprintf(stderr, "x_0: %u, id0: %lu, beg_0: %u, sink_0: %u, ori_0: %lu\n", 
                                                            x_0, id0, beg_0, sink_0, ori_0);
                fprintf(stderr, "x_1: %u, id1: %lu, beg_1: %u, sink_1: %u, ori_1: %lu\n", 
                                                            x_1, id1, beg_1, sink_1, ori_1);
                return 0;
            }
             
            if(ori_0 & 2)
            {
                tmp_id = id0; id0 = id1; id1 = tmp_id;
            }
            
            ori_0 &= 1; ori_1 &= 1; ori_1 ^= 1;


            
            p->ul = (id0<<1) | ori_0; p->ul <<= 32; p->ul += 0;
            p->v = (id1<<1) | ori_1; 
            p->ol = 0; p->del = 0; p->el = p->no_l_indel = p->strong = 1;
        }
        else
        {
            if(x_0_b_id == NULL) get_bub_id(bub, x_0>>1, &id0, NULL, check_het);
            if(x_1_b_id == NULL) get_bub_id(bub, x_1>>1, &id1, NULL, check_het);


            get_bubbles(bub, id0, &beg, &sink, &a, &n, NULL);
            ori_0 = (uint64_t)-1;
            if(x_0 == (beg^1))
            {
                ori_0 = 1;
            }
            else if(x_0 == (sink^1))
            {
                ori_0 = 0;
            }
            else
            {
                fprintf(stderr, "error 0\n");
                return 0;
            }
            
            

            get_bubbles(bub, id1, &beg, &sink, &a, &n, NULL);
            ori_1 = (uint64_t)-1;
            if(x_1 == (beg^1))
            {
                ori_1 = 1;
            }
            else if(x_1 == (sink^1))
            {
                ori_1 = 0;
            }
            else
            {
                fprintf(stderr, "error 1\n");
                return 0;
            }
            ori_0 &= 1; ori_1 &= 1; ori_1 ^= 1;

            p->ul = (id0<<1) | ori_0; p->ul <<= 32; p->ul += 0;
            p->v = (id1<<1) | ori_1; 
            p->ol = 0; p->del = 0; p->el = p->no_l_indel = p->strong = 1;
        }
    }
    else
    {
        x = (uint32_t)-1;
        if(x_0 != (uint32_t)-1) x = x_0;
        if(x_1 != (uint32_t)-1) x = x_1;
        if(x == (uint32_t)-1) return 0;
        if(x_0_b_id == NULL && x_1_b_id == NULL)
        {
            get_bub_id(bub, x>>1, &id0, &id1, check_het);
        }
        
        if(id0 != (uint64_t)-1)
        {
            get_bubbles(bub, id0, &beg, &sink, &a, &n, NULL);
            if(x == (beg^1))
            {
                return 1;
            }
            else if(x == (sink^1))
            {
                return 1;
            }

            return 0;
        }
        
        if(id1 != (uint64_t)-1)
        {
            get_bubbles(bub, id1, &beg, &sink, &a, &n, NULL);
            if(x == (beg^1))
            {
                return 1;
            }
            else if(x == (sink^1))
            {
                return 1;
            }

            return 0;
        }
    }
    
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r14
movq %r8, %r13
movl %ecx, %r12d
movl %esi, %ebx
movq %rdi, %r15
testq %rdx, %rdx
je 0x14479c
movl (%rdx), %eax
movq %rax, 0x18(%rsp)
testq %r13, %r13
je 0x1447aa
movl (%r13), %eax
movq %rax, 0x10(%rsp)
movl 0x60(%rsp), %r8d
cmpl $-0x1, %ebx
sete %al
cmpl $-0x1, %r12d
sete %cl
orb %al, %cl
jne 0x144833
movl %ebx, %esi
shrl %esi
movl %r12d, %ebp
shrl %ebp
cmpl %ebp, %esi
jne 0x144886
orq %r13, %rdx
jne 0x1447e8
leaq 0x18(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %r15, %rdi
callq 0x1445e7
movq 0x18(%rsp), %rax
movq 0x28(%r15), %rdx
movq 0x40(%r15), %rsi
movl (%rsi,%rax,4), %ecx
movl (%rdx,%rcx,4), %r13d
incl %ecx
movl (%rdx,%rcx,4), %edi
movq 0x10(%rsp), %rcx
movl (%rsi,%rcx,4), %esi
movl (%rdx,%rsi,4), %r8d
incl %esi
movl (%rdx,%rsi,4), %r9d
movl %r13d, %esi
xorl %ebx, %esi
movl $0x1, %r15d
movb $0x1, %dl
cmpl $0x1, %esi
jne 0x1448db
movl $0x1, %ebp
jmp 0x1449a1
cmpl $-0x1, %r12d
cmovnel %r12d, %ebx
cmpl $-0x1, %ebx
je 0x144ade
orq %r13, %rdx
jne 0x14485f
movl %ebx, %esi
shrl %esi
leaq 0x18(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %r15, %rdi
callq 0x1445e7
movq 0x18(%rsp), %rcx
cmpq $-0x1, %rcx
je 0x14493f
movq 0x28(%r15), %rax
movq 0x40(%r15), %rdx
movl (%rdx,%rcx,4), %ecx
movl (%rax,%rcx,4), %edx
xorl %ebx, %edx
movb $0x1, %bpl
jmp 0x144961
testq %rdx, %rdx
jne 0x14489f
leaq 0x18(%rsp), %rdx
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x1445e7
movl 0x60(%rsp), %r8d
testq %r13, %r13
jne 0x1448b5
leaq 0x10(%rsp), %rdx
movq %r15, %rdi
movl %ebp, %esi
xorl %ecx, %ecx
callq 0x1445e7
movq 0x18(%rsp), %rax
movq 0x28(%r15), %rcx
movq 0x40(%r15), %rdi
movl (%rdi,%rax,4), %edx
movl (%rcx,%rdx,4), %esi
xorl %ebx, %esi
cmpl $0x1, %esi
jne 0x1448ef
movabsq $0x100000000, %rdx      # imm = 0x100000000
jmp 0x1448ff
movl %edi, %esi
xorl %ebx, %esi
cmpl $0x1, %esi
jne 0x14497b
xorl %ebp, %ebp
jmp 0x1449a1
incl %edx
xorl (%rcx,%rdx,4), %ebx
cmpl $0x1, %ebx
jne 0x144ac4
xorl %edx, %edx
movq 0x10(%rsp), %rsi
movl (%rdi,%rsi,4), %edi
movl (%rcx,%rdi,4), %r8d
xorl %r12d, %r8d
cmpl $0x1, %r8d
jne 0x144918
xorl %ecx, %ecx
jmp 0x14492d
incl %edi
xorl (%rcx,%rdi,4), %r12d
movl $0x1, %ecx
cmpl $0x1, %r12d
jne 0x144acb
shlq $0x21, %rax
orq %rax, %rdx
movq %rdx, (%r14)
leal (%rcx,%rsi,2), %eax
jmp 0x144a1e
movq 0x10(%rsp), %rcx
movb $0x1, %bpl
cmpq $-0x1, %rcx
je 0x144ae0
movq 0x28(%r15), %rax
movq 0x40(%r15), %rdx
movl (%rdx,%rcx,4), %ecx
movl (%rax,%rcx,4), %edx
xorl %ebx, %edx
cmpl $0x1, %edx
je 0x144ae0
incl %ecx
xorl (%rax,%rcx,4), %ebx
cmpl $0x1, %ebx
sete %bpl
jmp 0x144ae0
movl %r8d, %edx
xorl %ebx, %edx
cmpl $0x1, %edx
jne 0x14498c
movl $0x3, %ebp
jmp 0x14499f
movl %r9d, %edx
xorl %ebx, %edx
cmpl $0x1, %edx
jne 0x144ad2
movl $0x2, %ebp
xorl %edx, %edx
movl %r13d, %esi
xorl %r12d, %esi
cmpl $0x1, %esi
je 0x1449e1
movl %edi, %esi
xorl %r12d, %esi
cmpl $0x1, %esi
jne 0x1449bb
xorl %r15d, %r15d
jmp 0x1449e1
movl %r8d, %esi
xorl %r12d, %esi
movl $0x3, %r15d
cmpl $0x1, %esi
je 0x1449e1
movl %r9d, %esi
xorl %r12d, %esi
movl $0x2, %r15d
cmpl $0x1, %esi
jne 0x144ad9
movl %r15d, %esi
xorl %ebp, %esi
cmpl $0x1, %esi
jbe 0x144a3c
testb %dl, %dl
jne 0x1449f9
movq %rcx, 0x18(%rsp)
movq %rax, 0x10(%rsp)
andl $0x1, %r15d
movq 0x18(%rsp), %rax
shlq $0x21, %rax
andl $0x1, %ebp
shlq $0x20, %rbp
orq %rax, %rbp
movq %rbp, (%r14)
movl 0x10(%rsp), %eax
leal (%r15,%rax,2), %eax
xorl $0x1, %eax
movl %eax, 0x8(%r14)
movl $0x0, 0xc(%r14)
orb $-0x40, 0x11(%r14)
movb $0x1, 0x12(%r14)
movb $0x1, %bpl
jmp 0x144ae0
movq 0x14559d(%rip), %rax    # 0x289fe0
movq (%rax), %rcx
movl %edi, %r14d
leaq 0xeaf7a(%rip), %rdi     # 0x22f9ca
movl $0x9, %esi
movl $0x1, %edx
movl %r8d, 0x20(%rsp)
movl %r9d, 0x24(%rsp)
callq 0x2410
movq 0x145570(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
movq 0x18(%rsp), %rcx
movq %rbp, (%rsp)
leaq 0xeaf51(%rip), %rsi     # 0x22f9d4
xorl %ebp, %ebp
movl %ebx, %edx
movl %r13d, %r8d
movl %r14d, %r9d
xorl %eax, %eax
callq 0x22b0
movq 0x145545(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
movq 0x10(%rsp), %rcx
movq %r15, (%rsp)
leaq 0xeaf5c(%rip), %rsi     # 0x22fa0a
movl %r12d, %edx
movl 0x20(%rsp), %r8d
movl 0x24(%rsp), %r9d
xorl %eax, %eax
callq 0x22b0
jmp 0x144ae0
callq 0x1d0b3
jmp 0x144ade
callq 0x1d0d5
jmp 0x144ade
callq 0x1d0f7
jmp 0x144ade
callq 0x1d119
xorl %ebp, %ebp
movzbl %bpl, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq