// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movq %r8, %r14
movl %ecx, %r13d
movl %esi, %ebx
movq %rdi, %r12
testq %rdx, %rdx
je 0x102f37
movl (%rdx), %r15d
movq %r15, 0x38(%rsp)
jmp 0x102f37
testq %r14, %r14
je 0x102f46
movl (%r14), %edi
movq %rdi, 0x28(%rsp)
jmp 0x102f46
movl 0x80(%rsp), %r8d
cmpl $-0x1, %ebx
sete %al
cmpl $-0x1, %r13d
sete %cl
orb %al, %cl
jne 0x103012
movq %r9, 0x40(%rsp)
movl %ebx, %esi
shrl %esi
movl %r13d, %ebp
shrl %ebp
cmpl %ebp, %esi
jne 0x103096
orq %r14, %rdx
jne 0x102f9d
leaq 0x38(%rsp), %r14
leaq 0x28(%rsp), %rbp
movq %r12, %rdi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x102d73
movq (%r14), %r15
movq (%rbp), %rdi
andq $0x0, (%rsp)
leaq 0x18(%rsp), %rdx
leaq 0x14(%rsp), %rcx
leaq 0x30(%rsp), %r8
leaq 0x1c(%rsp), %r9
movq %rdi, %r14
movq %r12, %rdi
movq %r15, %rsi
callq 0xf6ab5
andq $0x0, (%rsp)
leaq 0x24(%rsp), %rdx
leaq 0x20(%rsp), %rcx
movq %r12, %rdi
movq %r14, %rbp
movq %r14, %rsi
leaq 0x30(%rsp), %r8
leaq 0x1c(%rsp), %r9
callq 0xf6ab5
leaq 0x18(%rsp), %rax
movl (%rax), %ecx
movl %ecx, %edx
xorl %ebx, %edx
pushq $0x1
popq %r14
movb $0x1, %al
cmpl $0x1, %edx
jne 0x103108
movq %r14, %r12
movq 0x40(%rsp), %rdx
jmp 0x10320a
cmpl $-0x1, %r13d
cmovnel %r13d, %ebx
cmpl $-0x1, %ebx
je 0x10332f
orq %r14, %rdx
jne 0x10304e
movl %ebx, %esi
shrl %esi
leaq 0x38(%rsp), %r14
leaq 0x28(%rsp), %rcx
movq %r12, %rdi
movq %r14, %rdx
callq 0x102d73
movq (%r14), %r15
cmpq $-0x1, %r15
je 0x1031b5
andq $0x0, (%rsp)
leaq 0x18(%rsp), %r14
leaq 0x14(%rsp), %rcx
leaq 0x30(%rsp), %r8
leaq 0x1c(%rsp), %r9
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0xf6ab5
movl (%r14), %eax
xorl %ebx, %eax
movb $0x1, %bpl
cmpl $0x1, %eax
je 0x103331
xorl 0x14(%rsp), %ebx
cmpl $0x1, %ebx
sete %bpl
jmp 0x103331
testq %rdx, %rdx
jne 0x1030b0
leaq 0x38(%rsp), %rdx
movq %r12, %rdi
xorl %ecx, %ecx
movl %r8d, %r15d
callq 0x102d73
movl %r15d, %r8d
testq %r14, %r14
jne 0x1030c6
leaq 0x28(%rsp), %rdx
movq %r12, %rdi
movl %ebp, %esi
xorl %ecx, %ecx
callq 0x102d73
movq 0x38(%rsp), %r15
andq $0x0, (%rsp)
leaq 0x18(%rsp), %r14
leaq 0x14(%rsp), %rcx
leaq 0x30(%rsp), %r8
leaq 0x1c(%rsp), %r9
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0xf6ab5
movl (%r14), %eax
xorl %ebx, %eax
cmpl $0x1, %eax
jne 0x103124
movabsq $0x100000000, %rbp      # imm = 0x100000000
jmp 0x103133
movl 0x14(%rsp), %edx
xorl %ebx, %edx
cmpl $0x1, %edx
movq 0x40(%rsp), %rdx
jne 0x1031a6
xorl %r12d, %r12d
jmp 0x10320a
xorl 0x14(%rsp), %ebx
cmpl $0x1, %ebx
jne 0x103300
xorl %ebp, %ebp
movq 0x28(%rsp), %rbx
andq $0x0, (%rsp)
leaq 0x18(%rsp), %r14
leaq 0x14(%rsp), %rcx
leaq 0x30(%rsp), %r8
leaq 0x1c(%rsp), %r9
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xf6ab5
movl (%r14), %eax
xorl %r13d, %eax
cmpl $0x1, %eax
jne 0x10316e
xorl %eax, %eax
jmp 0x103180
xorl 0x14(%rsp), %r13d
cmpl $0x1, %r13d
jne 0x103313
pushq $0x1
popq %rax
shlq $0x21, %r15
orq %r15, %rbp
movq 0x40(%rsp), %rcx
movq %rbp, (%rcx)
leal (%rax,%rbx,2), %eax
movl %eax, 0x8(%rcx)
andl $0x0, 0xc(%rcx)
orb $-0x40, 0x11(%rcx)
movb $0x1, 0x12(%rcx)
jmp 0x10328b
movl 0x24(%rsp), %eax
xorl %ebx, %eax
cmpl $0x1, %eax
jne 0x1031f5
pushq $0x3
jmp 0x103206
movq 0x28(%rsp), %rsi
movb $0x1, %bpl
cmpq $-0x1, %rsi
je 0x103331
andq $0x0, (%rsp)
leaq 0x18(%rsp), %r14
leaq 0x14(%rsp), %rcx
leaq 0x30(%rsp), %r8
leaq 0x1c(%rsp), %r9
movq %r12, %rdi
movq %r14, %rdx
callq 0xf6ab5
movl (%r14), %eax
xorl %ebx, %eax
jmp 0x10307d
movl 0x20(%rsp), %eax
xorl %ebx, %eax
cmpl $0x1, %eax
jne 0x103300
pushq $0x2
popq %r12
xorl %eax, %eax
xorl %r13d, %ecx
cmpl $0x1, %ecx
je 0x103247
movl 0x14(%rsp), %ecx
xorl %r13d, %ecx
cmpl $0x1, %ecx
jne 0x103223
xorl %r14d, %r14d
jmp 0x103247
movl 0x24(%rsp), %ecx
xorl %r13d, %ecx
cmpl $0x1, %ecx
jne 0x103233
pushq $0x3
jmp 0x103245
movl 0x20(%rsp), %ecx
xorl %r13d, %ecx
cmpl $0x1, %ecx
jne 0x103313
pushq $0x2
popq %r14
movl %r14d, %ecx
xorl %r12d, %ecx
cmpl $0x1, %ecx
jbe 0x103293
andl $0x1, %r14d
testb %al, %al
movq %rbp, %rax
cmovneq %r15, %rax
cmovnel %ebp, %r15d
shlq $0x21, %rax
andl $0x1, %r12d
shlq $0x20, %r12
orq %rax, %r12
movq %r12, (%rdx)
leal (%r14,%r15,2), %eax
xorl $0x1, %eax
movl %eax, 0x8(%rdx)
andl $0x0, 0xc(%rdx)
orb $-0x40, 0x11(%rdx)
movb $0x1, 0x12(%rdx)
movb $0x1, %bpl
jmp 0x103331
movq 0x14fd46(%rip), %r15    # 0x252fe0
movq (%r15), %rcx
leaq 0xea866(%rip), %rdi     # 0x1edb0a
pushq $0x9
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq (%r15), %rdi
movq 0x38(%rsp), %rcx
movl 0x18(%rsp), %r8d
movl 0x14(%rsp), %r9d
movq %r12, (%rsp)
leaq 0xea848(%rip), %rsi     # 0x1edb14
xorl %ebp, %ebp
movl %ebx, %edx
xorl %eax, %eax
callq 0x22b0
movq (%r15), %rdi
movq 0x28(%rsp), %rcx
movl 0x24(%rsp), %r8d
movl 0x20(%rsp), %r9d
movq %r14, (%rsp)
leaq 0xea856(%rip), %rsi     # 0x1edb4a
movl %r13d, %edx
xorl %eax, %eax
callq 0x22b0
jmp 0x103331
movq 0x14fcd9(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0xea7e7(%rip), %rdi     # 0x1edaf8
jmp 0x103324
movq 0x14fcc6(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0xea7dd(%rip), %rdi     # 0x1edb01
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
xorl %ebp, %ebp
movzbl %bpl, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq