// File: chhylp123[P]hifiasm/hic.cpp
// Function: init_phase(ha_ug_index*, kv_u_trans_t*, bubble_type*, ps_t*)
void init_phase(ha_ug_index* idx, kv_u_trans_t *ta, bubble_type* bub, ps_t *st)
{
    double index_time = yak_realtime();
    uint8_t *vis = NULL; CALLOC(vis, idx->ug->g->n_seq);
    bub_p_t_warp b; memset(&b, 0, sizeof(bub_p_t_warp));
    CALLOC(b.a, idx->ug->g->n_seq*2);
    uint32_t i, k, *a = NULL, n, beg, end;
    memset(st->s, 0, sizeof(int8_t)*idx->ug->g->n_seq);
    
    double z[2];
    u_trans_t *e = NULL;
    uint32_t e_n;
    while(1)
    {
        i = get_weightest_node(ta, bub, idx->ug, st->s, vis);
        if(i == (uint32_t)-1) break;
        if(i&1)
        {
            i>>=1;
            z[0] = z[1] = 0;
            e = u_trans_a(*ta, i);
            e_n = u_trans_n(*ta, i);
            for (k = 0; k < e_n; k++)
            {
                if(e[k].del) continue;
                if(st->s[e[k].tn] > 0) z[0] += e[k].nw;
                else if(st->s[e[k].tn] < 0) z[1] += e[k].nw;
            }
            if(z[0] - z[1] < 0)
            {
                st->s[i] = 1;
            } 
            else if(z[0] - z[1] > 0)
            {
                st->s[i] = -1;
            }
            else
            {
                st->xs = kr_splitmix64(st->xs);
                st->s[i] = st->xs&1? 1 : -1;
            }
        }
        else
        {
            i>>=1;
            get_bubbles(bub, i, &beg, &end, &a, &n, NULL);
            bub_phase(idx->ug, beg, end, &b, ta, st);
            bub_phase(idx->ug, beg, end, &b, ta, st);
        }
    }
    free(b.a); free(b.S.a); free(b.T.a); free(b.b.a); free(b.e.a);
    free(vis);

    for (i = 0; i < idx->ug->g->n_seq; i++)
    {
        if(st->s[i] == 0) fprintf(stderr, "ERROR\n");
        if(u_trans_n(*ta, i) == 0) st->s[i] = 0;
    }

    fprintf(stderr, "[M::%s::%.3f]\n", __func__, yak_realtime()-index_time);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
callq 0x1b7ca0
movsd %xmm0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edi
movl $0x1, %esi
callq 0x2140
movq %rax, -0x30(%rbp)
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
movl $0x70, %edx
callq 0x2100
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movslq %eax, %rdi
movl $0x38, %esi
callq 0x2140
movq %rax, -0xa0(%rbp)
movq $0x0, -0xb0(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edx
shlq $0x0, %rdx
xorl %esi, %esi
callq 0x2100
movq $0x0, -0xd8(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x8(%rbp), %rax
movq (%rax), %rdx
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movq -0x30(%rbp), %r8
callq 0x1f7170
movl %eax, -0xa4(%rbp)
cmpl $-0x1, -0xa4(%rbp)
jne 0x1f7a30
jmp 0x1f7ce1
movl -0xa4(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1f7c49
movl -0xa4(%rbp), %eax
shrl %eax
movl %eax, -0xa4(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xc8(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xd0(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0xa4(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xd8(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0xa4(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0xdc(%rbp)
movl $0x0, -0xa8(%rbp)
movl -0xa8(%rbp), %eax
cmpl -0xdc(%rbp), %eax
jae 0x1f7ba3
movq -0xd8(%rbp), %rax
movl -0xa8(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movb 0x28(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
je 0x1f7ae9
jmp 0x1f7b8f
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0xd8(%rbp), %rcx
movl -0xa8(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
movl 0x14(%rcx), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jle 0x1f7b3b
movq -0xd8(%rbp), %rax
movl -0xa8(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
addsd -0xd0(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
jmp 0x1f7b8d
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0xd8(%rbp), %rcx
movl -0xa8(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
movl 0x14(%rcx), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jge 0x1f7b8b
movq -0xd8(%rbp), %rax
movl -0xa8(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
addsd -0xc8(%rbp), %xmm0
movsd %xmm0, -0xc8(%rbp)
jmp 0x1f7b8d
jmp 0x1f7b8f
movl -0xa8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa8(%rbp)
jmp 0x1f7ab4
movsd -0xd0(%rbp), %xmm1
subsd -0xc8(%rbp), %xmm1
xorps %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1f7bcf
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl -0xa4(%rbp), %ecx
movb $0x1, (%rax,%rcx)
jmp 0x1f7c44
movsd -0xd0(%rbp), %xmm0
subsd -0xc8(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1f7bfb
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl -0xa4(%rbp), %ecx
movb $-0x1, (%rax,%rcx)
jmp 0x1f7c42
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x1f60c0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdx
andq $0x1, %rdx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl -0xa4(%rbp), %ecx
movb %dl, (%rax,%rcx)
jmp 0x1f7c44
jmp 0x1f7cdc
movl -0xa4(%rbp), %eax
shrl %eax
movl %eax, -0xa4(%rbp)
movq -0x18(%rbp), %rdi
movl -0xa4(%rbp), %eax
movl %eax, %esi
leaq -0xb8(%rbp), %rdx
leaq -0xbc(%rbp), %rcx
leaq -0xb0(%rbp), %r8
leaq -0xb4(%rbp), %r9
xorl %eax, %eax
movq $0x0, (%rsp)
callq 0x1c4b20
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movl -0xb8(%rbp), %esi
movl -0xbc(%rbp), %edx
movq -0x10(%rbp), %r8
movq -0x20(%rbp), %r9
leaq -0xa0(%rbp), %rcx
callq 0x1f6140
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movl -0xb8(%rbp), %esi
movl -0xbc(%rbp), %edx
movq -0x10(%rbp), %r8
movq -0x20(%rbp), %r9
leaq -0xa0(%rbp), %rcx
callq 0x1f6140
jmp 0x1f79fd
movq -0xa0(%rbp), %rdi
callq 0x2210
movq -0x88(%rbp), %rdi
callq 0x2210
movq -0x70(%rbp), %rdi
callq 0x2210
movq -0x58(%rbp), %rdi
callq 0x2210
movq -0x40(%rbp), %rdi
callq 0x2210
movq -0x30(%rbp), %rdi
callq 0x2210
movl $0x0, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
movq 0x18(%rcx), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x1f7db1
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl -0xa4(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1f7d73
movq 0x1cc27e(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x191d43(%rip), %rsi    # 0x389aaf
movb $0x0, %al
callq 0x22a0
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0xa4(%rbp), %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x0, %eax
jne 0x1f7d9b
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl -0xa4(%rbp), %ecx
movb $0x0, (%rax,%rcx)
jmp 0x1f7d9d
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x1f7d27
movq 0x1cc228(%rip), %rax    # 0x3c3fe0
movq (%rax), %rax
movq %rax, -0xe8(%rbp)
callq 0x1b7ca0
movq -0xe8(%rbp), %rdi
subsd -0x28(%rbp), %xmm0
leaq 0x194a2e(%rip), %rsi    # 0x38c808
leaq 0x1950a6(%rip), %rdx    # 0x38ce87
movb $0x1, %al
callq 0x22a0
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)