// File: /workspace/github_cpp_makefile_star2_O3/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 0x14adde
movl (%rdx), %eax
movq %rax, 0x18(%rsp)
jmp 0x14adde
testq %r13, %r13
je 0x14adee
movl (%r13), %ecx
movq %rcx, 0x10(%rsp)
jmp 0x14adee
movl 0x60(%rsp), %r8d
cmpl $-0x1, %ebx
sete %sil
cmpl $-0x1, %r12d
sete %dil
orb %sil, %dil
jne 0x14ae7e
movl %ebx, %esi
shrl %esi
movl %r12d, %ebp
shrl %ebp
cmpl %ebp, %esi
jne 0x14aee7
orq %r13, %rdx
jne 0x14ae3d
leaq 0x18(%rsp), %r13
leaq 0x10(%rsp), %rbp
movq %r15, %rdi
movq %r13, %rdx
movq %rbp, %rcx
callq 0x14ac07
movq (%r13), %rax
movq (%rbp), %rcx
movq 0x28(%r15), %rdx
movq 0x40(%r15), %rsi
movl (%rsi,%rax,4), %edi
movl (%rdx,%rdi,4), %r13d
incl %edi
movl (%rdx,%rdi,4), %edi
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 0x14af3c
movl $0x1, %ebp
jmp 0x14aff7
cmpl $-0x1, %r12d
cmovnel %r12d, %ebx
cmpl $-0x1, %ebx
je 0x14b129
orq %r13, %rdx
jne 0x14aeba
movl %ebx, %esi
shrl %esi
leaq 0x18(%rsp), %r14
leaq 0x10(%rsp), %rcx
movq %r15, %rdi
movq %r14, %rdx
callq 0x14ac07
movq (%r14), %rax
cmpq $-0x1, %rax
je 0x14afad
movq 0x28(%r15), %rcx
movq 0x40(%r15), %rdx
movl (%rdx,%rax,4), %eax
movl (%rcx,%rax,4), %edx
xorl %ebx, %edx
movb $0x1, %bpl
cmpl $0x1, %edx
je 0x14b12b
incl %eax
xorl (%rcx,%rax,4), %ebx
cmpl $0x1, %ebx
sete %bpl
jmp 0x14b12b
testq %rdx, %rdx
jne 0x14af00
leaq 0x18(%rsp), %rdx
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x14ac07
movl 0x60(%rsp), %r8d
testq %r13, %r13
jne 0x14af16
leaq 0x10(%rsp), %rdx
movq %r15, %rdi
movl %ebp, %esi
xorl %ecx, %ecx
callq 0x14ac07
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 0x14af4c
movabsq $0x100000000, %rdx      # imm = 0x100000000
jmp 0x14af5c
movl %edi, %esi
xorl %ebx, %esi
cmpl $0x1, %esi
jne 0x14af9c
xorl %ebp, %ebp
jmp 0x14aff7
incl %edx
xorl (%rcx,%rdx,4), %ebx
cmpl $0x1, %ebx
jne 0x14b10f
xorl %edx, %edx
movq 0x10(%rsp), %rsi
movl (%rdi,%rsi,4), %edi
movl (%rcx,%rdi,4), %r8d
xorl %r12d, %r8d
cmpl $0x1, %r8d
jne 0x14af75
xorl %ecx, %ecx
jmp 0x14af8a
incl %edi
xorl (%rcx,%rdi,4), %r12d
movl $0x1, %ecx
cmpl $0x1, %r12d
jne 0x14b116
shlq $0x21, %rax
orq %rax, %rdx
movq %rdx, (%r14)
leal (%rcx,%rsi,2), %eax
jmp 0x14b069
movl %r8d, %edx
xorl %ebx, %edx
cmpl $0x1, %edx
jne 0x14afe2
movl $0x3, %ebp
jmp 0x14aff5
movq 0x10(%rsp), %rcx
movb $0x1, %bpl
cmpq $-0x1, %rcx
je 0x14b12b
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 0x14b12b
incl %ecx
xorl (%rax,%rcx,4), %ebx
jmp 0x14aedb
movl %r9d, %edx
xorl %ebx, %edx
cmpl $0x1, %edx
jne 0x14b11d
movl $0x2, %ebp
xorl %edx, %edx
movl %r13d, %esi
xorl %r12d, %esi
cmpl $0x1, %esi
je 0x14b037
movl %edi, %esi
xorl %r12d, %esi
cmpl $0x1, %esi
jne 0x14b011
xorl %r15d, %r15d
jmp 0x14b037
movl %r8d, %esi
xorl %r12d, %esi
movl $0x3, %r15d
cmpl $0x1, %esi
je 0x14b037
movl %r9d, %esi
xorl %r12d, %esi
movl $0x2, %r15d
cmpl $0x1, %esi
jne 0x14b124
movl %r15d, %esi
xorl %ebp, %esi
cmpl $0x1, %esi
jbe 0x14b087
andl $0x1, %r15d
testb %dl, %dl
movq %rcx, %rdx
cmovneq %rax, %rdx
cmovnel %ecx, %eax
shlq $0x21, %rdx
andl $0x1, %ebp
shlq $0x20, %rbp
orq %rdx, %rbp
movq %rbp, (%r14)
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 0x14b12b
movq 0x149f52(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl %edi, %r14d
leaq 0xf0b7f(%rip), %rdi     # 0x23bc1a
movl $0x9, %esi
movl $0x1, %edx
movl %r8d, 0x20(%rsp)
movl %r9d, 0x24(%rsp)
callq 0x2410
movq 0x149f25(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
movq 0x18(%rsp), %rcx
movq %rbp, (%rsp)
leaq 0xf0b56(%rip), %rsi     # 0x23bc24
xorl %ebp, %ebp
movl %ebx, %edx
movl %r13d, %r8d
movl %r14d, %r9d
xorl %eax, %eax
callq 0x22b0
movq 0x149efa(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
movq 0x10(%rsp), %rcx
movq %r15, (%rsp)
leaq 0xf0b61(%rip), %rsi     # 0x23bc5a
movl %r12d, %edx
movl 0x20(%rsp), %r8d
movl 0x24(%rsp), %r9d
xorl %eax, %eax
callq 0x22b0
jmp 0x14b12b
callq 0x1c79a
jmp 0x14b129
callq 0x1c7bc
jmp 0x14b129
callq 0x1c7de
jmp 0x14b129
callq 0x1c800
xorl %ebp, %ebp
movzbl %bpl, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq