// File: 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
movq %rsp, %rbp
subq $0xa0, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x1dc665
movq -0x20(%rbp), %rax
movl (%rax), %eax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x1dc676
movq -0x30(%rbp), %rax
movl (%rax), %eax
movq %rax, -0x50(%rbp)
cmpl $-0x1, -0x14(%rbp)
je 0x1dcbeb
cmpl $-0x1, -0x24(%rbp)
je 0x1dcbeb
movl -0x14(%rbp), %eax
shrl %eax
movl -0x24(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
jne 0x1dc9de
cmpq $0x0, -0x20(%rbp)
jne 0x1dc6c4
cmpq $0x0, -0x30(%rbp)
jne 0x1dc6c4
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
shrl %esi
movl 0x10(%rbp), %r8d
leaq -0x40(%rbp), %rdx
leaq -0x50(%rbp), %rcx
callq 0x1dc360
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
leaq -0x80(%rbp), %rdx
leaq -0x84(%rbp), %rcx
leaq -0x78(%rbp), %r8
leaq -0x6c(%rbp), %r9
xorl %eax, %eax
movq $0x0, (%rsp)
callq 0x1c4b20
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
leaq -0x88(%rbp), %rdx
leaq -0x8c(%rbp), %rcx
leaq -0x78(%rbp), %r8
leaq -0x6c(%rbp), %r9
xorl %eax, %eax
movq $0x0, (%rsp)
callq 0x1c4b20
movq $-0x1, -0x48(%rbp)
movl -0x14(%rbp), %eax
movl -0x80(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1dc73a
movq $0x1, -0x48(%rbp)
jmp 0x1dc7b2
movl -0x14(%rbp), %eax
movl -0x84(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1dc754
movq $0x0, -0x48(%rbp)
jmp 0x1dc7b0
movl -0x14(%rbp), %eax
movl -0x88(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1dc76e
movq $0x3, -0x48(%rbp)
jmp 0x1dc7ae
movl -0x14(%rbp), %eax
movl -0x8c(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1dc788
movq $0x2, -0x48(%rbp)
jmp 0x1dc7ac
movq 0x1e7851(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x1b008c(%rip), %rsi    # 0x38c825
movb $0x0, %al
callq 0x22a0
movl $0x0, -0x4(%rbp)
jmp 0x1dcd1a
jmp 0x1dc7ae
jmp 0x1dc7b0
jmp 0x1dc7b2
movq $-0x1, -0x58(%rbp)
movl -0x24(%rbp), %eax
movl -0x80(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1dc7d1
movq $0x1, -0x58(%rbp)
jmp 0x1dc849
movl -0x24(%rbp), %eax
movl -0x84(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1dc7eb
movq $0x0, -0x58(%rbp)
jmp 0x1dc847
movl -0x24(%rbp), %eax
movl -0x88(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1dc805
movq $0x3, -0x58(%rbp)
jmp 0x1dc845
movl -0x24(%rbp), %eax
movl -0x8c(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1dc81f
movq $0x2, -0x58(%rbp)
jmp 0x1dc843
movq 0x1e77ba(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x1afffe(%rip), %rsi    # 0x38c82e
movb $0x0, %al
callq 0x22a0
movl $0x0, -0x4(%rbp)
jmp 0x1dcd1a
jmp 0x1dc845
jmp 0x1dc847
jmp 0x1dc849
movq -0x48(%rbp), %rax
shrq %rax
movq -0x58(%rbp), %rcx
shrq %rcx
xorq %rcx, %rax
andq $0x1, %rax
cmpq $0x1, %rax
je 0x1dc8f3
movq 0x1e7771(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x1affbe(%rip), %rsi    # 0x38c837
movb $0x0, %al
callq 0x22a0
movq 0x1e7759(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x14(%rbp), %edx
movq -0x40(%rbp), %rcx
movl -0x80(%rbp), %r8d
movl -0x84(%rbp), %r9d
movq -0x48(%rbp), %rax
leaq 0x1aff9a(%rip), %rsi    # 0x38c841
movq %rax, (%rsp)
movb $0x0, %al
callq 0x22a0
movq 0x1e7727(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x24(%rbp), %edx
movq -0x50(%rbp), %rcx
movl -0x88(%rbp), %r8d
movl -0x8c(%rbp), %r9d
movq -0x58(%rbp), %rax
leaq 0x1aff9b(%rip), %rsi    # 0x38c877
movq %rax, (%rsp)
movb $0x0, %al
callq 0x22a0
movl $0x0, -0x4(%rbp)
jmp 0x1dcd1a
movq -0x48(%rbp), %rax
andq $0x2, %rax
cmpq $0x0, %rax
je 0x1dc919
movq -0x40(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
andq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x58(%rbp), %rax
andq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
xorq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rcx
shlq %rcx
orq -0x48(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rcx
shlq $0x20, %rcx
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rcx
addq $0x0, %rcx
movq %rcx, (%rax)
movq -0x50(%rbp), %rax
shlq %rax
orq -0x58(%rbp), %rax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x38(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x80000000, %ecx       # imm = 0x80000000
orl $0x0, %ecx
movl %ecx, 0xc(%rax)
movq -0x38(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, 0xc(%rax)
movq -0x38(%rbp), %rax
movw 0x10(%rax), %cx
andw $0xbfff, %cx            # imm = 0xBFFF
orw $0x4000, %cx            # imm = 0x4000
movw %cx, 0x10(%rax)
movq -0x38(%rbp), %rax
movw 0x10(%rax), %cx
andw $0x7fff, %cx            # imm = 0x7FFF
orw $0x8000, %cx            # imm = 0x8000
movw %cx, 0x10(%rax)
movq -0x38(%rbp), %rax
movb $0x1, 0x12(%rax)
jmp 0x1dcbe6
cmpq $0x0, -0x20(%rbp)
jne 0x1dc9ff
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
shrl %esi
movl 0x10(%rbp), %r8d
leaq -0x40(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x1dc360
cmpq $0x0, -0x30(%rbp)
jne 0x1dca20
movq -0x10(%rbp), %rdi
movl -0x24(%rbp), %esi
shrl %esi
movl 0x10(%rbp), %r8d
leaq -0x50(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x1dc360
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
leaq -0x64(%rbp), %rdx
leaq -0x68(%rbp), %rcx
leaq -0x78(%rbp), %r8
leaq -0x6c(%rbp), %r9
xorl %eax, %eax
movq $0x0, (%rsp)
callq 0x1c4b20
movq $-0x1, -0x48(%rbp)
movl -0x14(%rbp), %eax
movl -0x64(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1dca66
movq $0x1, -0x48(%rbp)
jmp 0x1dcaa3
movl -0x14(%rbp), %eax
movl -0x68(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1dca7d
movq $0x0, -0x48(%rbp)
jmp 0x1dcaa1
movq 0x1e755c(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x1afd97(%rip), %rsi    # 0x38c825
movb $0x0, %al
callq 0x22a0
movl $0x0, -0x4(%rbp)
jmp 0x1dcd1a
jmp 0x1dcaa3
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
leaq -0x64(%rbp), %rdx
leaq -0x68(%rbp), %rcx
leaq -0x78(%rbp), %r8
leaq -0x6c(%rbp), %r9
xorl %eax, %eax
movq $0x0, (%rsp)
callq 0x1c4b20
movq $-0x1, -0x58(%rbp)
movl -0x24(%rbp), %eax
movl -0x64(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1dcae9
movq $0x1, -0x58(%rbp)
jmp 0x1dcb26
movl -0x24(%rbp), %eax
movl -0x68(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1dcb00
movq $0x0, -0x58(%rbp)
jmp 0x1dcb24
movq 0x1e74d9(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x1afd1d(%rip), %rsi    # 0x38c82e
movb $0x0, %al
callq 0x22a0
movl $0x0, -0x4(%rbp)
jmp 0x1dcd1a
jmp 0x1dcb26
movq -0x48(%rbp), %rax
andq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x58(%rbp), %rax
andq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
xorq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rcx
shlq %rcx
orq -0x48(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rcx
shlq $0x20, %rcx
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rcx
addq $0x0, %rcx
movq %rcx, (%rax)
movq -0x50(%rbp), %rax
shlq %rax
orq -0x58(%rbp), %rax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x38(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x80000000, %ecx       # imm = 0x80000000
orl $0x0, %ecx
movl %ecx, 0xc(%rax)
movq -0x38(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, 0xc(%rax)
movq -0x38(%rbp), %rax
movw 0x10(%rax), %cx
andw $0xbfff, %cx            # imm = 0xBFFF
orw $0x4000, %cx            # imm = 0x4000
movw %cx, 0x10(%rax)
movq -0x38(%rbp), %rax
movw 0x10(%rax), %cx
andw $0x7fff, %cx            # imm = 0x7FFF
orw $0x8000, %cx            # imm = 0x8000
movw %cx, 0x10(%rax)
movq -0x38(%rbp), %rax
movb $0x1, 0x12(%rax)
jmp 0x1dcd13
movl $0xffffffff, -0x7c(%rbp) # imm = 0xFFFFFFFF
cmpl $-0x1, -0x14(%rbp)
je 0x1dcbfe
movl -0x14(%rbp), %eax
movl %eax, -0x7c(%rbp)
cmpl $-0x1, -0x24(%rbp)
je 0x1dcc0a
movl -0x24(%rbp), %eax
movl %eax, -0x7c(%rbp)
cmpl $-0x1, -0x7c(%rbp)
jne 0x1dcc1c
movl $0x0, -0x4(%rbp)
jmp 0x1dcd1a
cmpq $0x0, -0x20(%rbp)
jne 0x1dcc44
cmpq $0x0, -0x30(%rbp)
jne 0x1dcc44
movq -0x10(%rbp), %rdi
movl -0x7c(%rbp), %esi
shrl %esi
movl 0x10(%rbp), %r8d
leaq -0x40(%rbp), %rdx
leaq -0x50(%rbp), %rcx
callq 0x1dc360
cmpq $-0x1, -0x40(%rbp)
je 0x1dccac
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
leaq -0x64(%rbp), %rdx
leaq -0x68(%rbp), %rcx
leaq -0x78(%rbp), %r8
leaq -0x6c(%rbp), %r9
xorl %eax, %eax
movq $0x0, (%rsp)
callq 0x1c4b20
movl -0x7c(%rbp), %eax
movl -0x64(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1dcc8b
movl $0x1, -0x4(%rbp)
jmp 0x1dcd1a
movl -0x7c(%rbp), %eax
movl -0x68(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1dcca1
movl $0x1, -0x4(%rbp)
jmp 0x1dcd1a
jmp 0x1dcca3
movl $0x0, -0x4(%rbp)
jmp 0x1dcd1a
cmpq $-0x1, -0x50(%rbp)
je 0x1dcd11
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
leaq -0x64(%rbp), %rdx
leaq -0x68(%rbp), %rcx
leaq -0x78(%rbp), %r8
leaq -0x6c(%rbp), %r9
xorl %eax, %eax
movq $0x0, (%rsp)
callq 0x1c4b20
movl -0x7c(%rbp), %eax
movl -0x64(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1dccf0
movl $0x1, -0x4(%rbp)
jmp 0x1dcd1a
movl -0x7c(%rbp), %eax
movl -0x68(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1dcd06
movl $0x1, -0x4(%rbp)
jmp 0x1dcd1a
jmp 0x1dcd08
movl $0x0, -0x4(%rbp)
jmp 0x1dcd1a
jmp 0x1dcd13
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)