// File: chhylp123[P]hifiasm/hic.cpp
// Function: set_path_hap(bub_p_t_warp*, unsigned int, H_partition*, unsigned int)
void set_path_hap(bub_p_t_warp *b, uint32_t root, H_partition* hap, uint32_t max_hap_label)
{
    uint32_t v, u, label;
    double w0 = 0, w1 = 0, cur_w0, cur_w1;
    ///v is the sink of this bubble
    v = b->S.a[0];
    do {
		u = b->a[v].p; // u->v
        if(v != b->S.a[0]) 
        {
            get_related_weight(v>>1, hap, &cur_w0, &cur_w1, &max_hap_label);
            w0 += cur_w0; w1 += cur_w1;
        }
		v = u;
	} while (v != root);

    if(w0 > w1)
    {
        label = max_hap_label | hap->m[0];
        b->exist_hap_label = hap->m[0];
    }
    else if(w0 < w1)
    {
        label = max_hap_label | hap->m[1];
        b->exist_hap_label = hap->m[1];
    }
    else
    {
        if(b->exist_hap_label == (uint32_t)-1)
        {
            label = max_hap_label | hap->m[0];
            b->exist_hap_label = hap->m[0];
        }
        else
        {
            if(b->exist_hap_label == hap->m[0])
            {
                label = max_hap_label | hap->m[1];
                b->exist_hap_label = hap->m[1];
            }
            else
            {
                label = max_hap_label | hap->m[0];
                b->exist_hap_label = hap->m[0];
            }
        }   
    }
    

	v = b->S.a[0];
    do {
		u = b->a[v].p; // u->v
        if(v != b->S.a[0]) hap->hap[v>>1] |= label;
		v = u;
	} while (v != root);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x20(%rbp), %ecx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x24(%rbp)
movl -0x20(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpl (%rcx), %eax
je 0x1ebc10
movl -0x20(%rbp), %edi
shrl %edi
movq -0x18(%rbp), %rsi
leaq -0x40(%rbp), %rdx
leaq -0x48(%rbp), %rcx
leaq -0x1c(%rbp), %r8
callq 0x1eb960
movsd -0x40(%rbp), %xmm0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x48(%rbp), %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0xc(%rbp), %eax
jne 0x1ebbb3
movsd -0x30(%rbp), %xmm0
ucomisd -0x38(%rbp), %xmm0
jbe 0x1ebc4a
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
orl 0x18(%rcx), %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movl 0x18(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x68(%rax)
jmp 0x1ebcec
movsd -0x30(%rbp), %xmm1
movsd -0x38(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1ebc77
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
orl 0x1c(%rcx), %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x68(%rax)
jmp 0x1ebcea
movq -0x8(%rbp), %rax
cmpl $-0x1, 0x68(%rax)
jne 0x1ebc9e
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
orl 0x18(%rcx), %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movl 0x18(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x68(%rax)
jmp 0x1ebce8
movq -0x8(%rbp), %rax
movl 0x68(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jne 0x1ebccb
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
orl 0x1c(%rcx), %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x68(%rax)
jmp 0x1ebce6
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
orl 0x18(%rcx), %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movl 0x18(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x68(%rax)
jmp 0x1ebce8
jmp 0x1ebcea
jmp 0x1ebcec
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x20(%rbp), %ecx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x24(%rbp)
movl -0x20(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpl (%rcx), %eax
je 0x1ebd36
movl -0x28(%rbp), %edx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x20(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
orl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl -0x24(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0xc(%rbp), %eax
jne 0x1ebcf9
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)