// File: chhylp123[P]hifiasm/hic.cpp
// Function: get_bub_id(bubble_type*, unsigned int, unsigned long*, unsigned long*, unsigned int)
void get_bub_id(bubble_type* bub, uint32_t root, uint64_t* id0, uint64_t* id1, uint32_t check_het)
{
    if(id0) (*id0) = (uint64_t)-1;
    if(id1) (*id1) = (uint64_t)-1;
    uint64_t b_id0 = (uint64_t)-1, b_id1 = (uint64_t)-1;
    uint32_t beg, sink;

    if((bub->b_s_idx.a[root]&0xffffffff) != 0xffffffff)
    {
        b_id0 = bub->b_s_idx.a[root]&0xffffffff;
        if(check_het)
        {
            get_bubbles(bub, b_id0, &beg, &sink, NULL, NULL, NULL);
            if(((beg == (uint32_t)-1) || IF_HET(beg>>1, *bub)) && ((sink == (uint32_t)-1) || IF_HET(sink>>1, *bub))) b_id0 = (uint64_t)-1;
        } 
    }

    if((bub->b_s_idx.a[root]&0xffffffff00000000) != 0xffffffff00000000)
    {
        b_id1 = bub->b_s_idx.a[root]&0xffffffff00000000; b_id1 >>= 32;
        if(check_het)
        {
            get_bubbles(bub, b_id1, &beg, &sink, NULL, NULL, NULL);
            if(((beg == (uint32_t)-1) || IF_HET(beg>>1, *bub)) && ((sink == (uint32_t)-1) || IF_HET(sink>>1, *bub))) b_id1 = (uint64_t)-1;
        }        
    }

    if(b_id0 == (uint64_t)-1 && b_id1 != (uint64_t)-1)
    {
        b_id0 = b_id1;
        b_id1 = (uint64_t)-1;
    }

    if(id0) (*id0) = b_id0;
    if(id1) (*id1) = b_id1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x1dc38d
movq -0x18(%rbp), %rax
movq $-0x1, (%rax)
cmpq $0x0, -0x20(%rbp)
je 0x1dc39f
movq -0x20(%rbp), %rax
movq $-0x1, (%rax)
movq $-0x1, -0x30(%rbp)
movq $-0x1, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x70(%rax), %rcx
movl -0xc(%rbp), %eax
movl %eax, %edx
movabsq $0xffffffff, %rax       # imm = 0xFFFFFFFF
andq (%rcx,%rdx,8), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
je 0x1dc488
movq -0x8(%rbp), %rax
movq 0x70(%rax), %rcx
movl -0xc(%rbp), %eax
movl %eax, %edx
movabsq $0xffffffff, %rax       # imm = 0xFFFFFFFF
andq (%rcx,%rdx,8), %rax
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x1dc486
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq -0x3c(%rbp), %rdx
leaq -0x40(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %r8
movq $0x0, (%rsp)
callq 0x1c4b20
cmpl $-0x1, -0x3c(%rbp)
je 0x1dc451
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x3c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jne 0x1dc484
cmpl $-0x1, -0x40(%rbp)
je 0x1dc47c
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x40(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jne 0x1dc484
movq $-0x1, -0x30(%rbp)
jmp 0x1dc486
jmp 0x1dc488
movq -0x8(%rbp), %rax
movq 0x70(%rax), %rcx
movl -0xc(%rbp), %eax
movl %eax, %edx
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
andq (%rcx,%rdx,8), %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
cmpq %rcx, %rax
je 0x1dc572
movq -0x8(%rbp), %rax
movq 0x70(%rax), %rcx
movl -0xc(%rbp), %eax
movl %eax, %edx
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
andq (%rcx,%rdx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
shrq $0x20, %rax
movq %rax, -0x38(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x1dc570
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x3c(%rbp), %rdx
leaq -0x40(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %r8
movq $0x0, (%rsp)
callq 0x1c4b20
cmpl $-0x1, -0x3c(%rbp)
je 0x1dc53b
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x3c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jne 0x1dc56e
cmpl $-0x1, -0x40(%rbp)
je 0x1dc566
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x40(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jne 0x1dc56e
movq $-0x1, -0x38(%rbp)
jmp 0x1dc570
jmp 0x1dc572
cmpq $-0x1, -0x30(%rbp)
jne 0x1dc590
cmpq $-0x1, -0x38(%rbp)
je 0x1dc590
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
movq $-0x1, -0x38(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x1dc5a2
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, -0x20(%rbp)
je 0x1dc5b4
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)