// File: chhylp123[P]hifiasm/hic.cpp
// Function: set_bub_idx(bubble_type*, ma_utg_t*, asg_t*, int, int, unsigned int, unsigned int)
inline void set_bub_idx(bubble_type* bub, ma_utg_t *bu, asg_t *untig_sg, int beg_idx, int end_idx, 
uint32_t is_to_hom, uint32_t check_het)
{
    int k;
    uint32_t rId, ori, root;
    uint64_t id0, id1, len0, len1;
    for (k = beg_idx; k <= end_idx; k++)
    {
        rId = bu->a[k]>>33;
        ori = bu->a[k]>>32&1;
        get_bubbles(bub, rId, ori == 1?&root:NULL, ori == 0?&root:NULL, NULL, NULL, NULL);

        if(is_to_hom && IF_HOM(root>>1, *bub)) continue;
        if(!is_to_hom && IF_HET(root>>1, *bub)) continue;

        
        get_bub_id(bub, root>>1, &id0, &id1, check_het);
        if(id0 == (uint64_t)-1 || id1 == (uint64_t)-1) continue;
        get_bubbles(bub, id0, NULL, NULL, NULL, NULL, &len0);
        get_bubbles(bub, id1, NULL, NULL, NULL, NULL, &len1);

        if(is_to_hom)
        {
            if(untig_sg->seq[root>>1].len > (MIN(len0, len1)*3)) continue;
            bub->index[root>>1] = (uint32_t)-1;
        }
        else
        {
            bub->index[root>>1] = bub->f_bub+1;
        }
    
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x20(%rbp), %eax
jg 0x214cf2
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
andq $0x1, %rax
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movl -0x2c(%rbp), %eax
movq %rax, -0x60(%rbp)
cmpl $0x1, -0x30(%rbp)
jne 0x214b28
leaq -0x34(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0x214b30
xorl %eax, %eax
movq %rax, -0x70(%rbp)
jmp 0x214b30
movq -0x70(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpl $0x0, -0x30(%rbp)
jne 0x214b48
leaq -0x34(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x214b50
xorl %eax, %eax
movq %rax, -0x80(%rbp)
jmp 0x214b50
movq -0x78(%rbp), %rdx
movq -0x60(%rbp), %rsi
movq -0x68(%rbp), %rdi
movq -0x80(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %r8
movq $0x0, (%rsp)
callq 0x1c4b20
cmpl $0x0, -0x24(%rbp)
je 0x214ba5
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x34(%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
jbe 0x214ba5
jmp 0x214ce4
cmpl $0x0, -0x24(%rbp)
jne 0x214bd5
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x34(%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 0x214bd5
jmp 0x214ce4
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
shrl %esi
movl 0x10(%rbp), %r8d
leaq -0x40(%rbp), %rdx
leaq -0x48(%rbp), %rcx
callq 0x1dc360
cmpq $-0x1, -0x40(%rbp)
je 0x214bfd
cmpq $-0x1, -0x48(%rbp)
jne 0x214c02
jmp 0x214ce4
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
xorl %eax, %eax
movl %eax, %r9d
leaq -0x50(%rbp), %rax
movq %r9, %rdx
movq %r9, %rcx
movq %r9, %r8
movq %rax, (%rsp)
callq 0x1c4b20
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
xorl %eax, %eax
movl %eax, %r9d
leaq -0x58(%rbp), %rax
movq %r9, %rdx
movq %r9, %rcx
movq %r9, %r8
movq %rax, (%rsp)
callq 0x1c4b20
cmpl $0x0, -0x24(%rbp)
je 0x214cc0
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x88(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x58(%rbp), %rax
ja 0x214c85
movq -0x50(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x214c90
movq -0x58(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rax
movq -0x90(%rbp), %rcx
imulq $0x3, %rcx, %rcx
cmpq %rcx, %rax
jbe 0x214ca9
jmp 0x214ce4
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
jmp 0x214ce2
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
addq $0x1, %rax
movl %eax, %edx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl %edx, (%rax,%rcx,4)
jmp 0x214ce4
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x214acb
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax,%rax)