// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rcx, %rbx
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %r15
callq 0x1303c7
movsd %xmm0, 0x10(%rsp)
movq (%r15), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %ebp
movl %ebp, %r12d
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
pushq $0x1
popq %rsi
movq %r12, %rdi
callq 0x2120
movq %rax, 0x8(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x80(%rsp)
movapd %xmm0, 0x70(%rsp)
movapd %xmm0, 0x60(%rsp)
movapd %xmm0, 0x50(%rsp)
movapd %xmm0, 0x40(%rsp)
movapd %xmm0, 0x30(%rsp)
movapd %xmm0, 0x20(%rsp)
addl %ebp, %ebp
pushq $0x38
popq %rsi
movq %rbp, %rdi
callq 0x2120
movq %rax, 0x20(%rsp)
movq (%rbx), %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x20e0
movq %r15, (%rsp)
movq (%r15), %r12
movq 0x8(%rsp), %r15
movq (%rbx), %rbp
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %rbp, %rcx
movq %r15, %r8
callq 0x151d01
cmpl $-0x1, %eax
je 0x196d9
xorpd %xmm2, %xmm2
movq %r13, 0x18(%rsp)
movl %eax, %ecx
shrl %ecx
testb $0x1, %al
jne 0x195ca
movl %ecx, %eax
movq 0x28(%r13), %rcx
movq 0x40(%r13), %rdx
movl (%rdx,%rax,4), %eax
movl (%rcx,%rax,4), %ebp
incl %eax
movq %r15, %r13
movl (%rcx,%rax,4), %r15d
movq %r12, %rdi
movl %ebp, %esi
movl %r15d, %edx
leaq 0x20(%rsp), %rcx
movq %r14, %r8
movq %rbx, %r9
callq 0x1513b0
movq (%rsp), %r12
movq (%r12), %rdi
movl %ebp, %esi
movl %r15d, %edx
movq %r13, %r15
movq 0x18(%rsp), %r13
leaq 0x20(%rsp), %rcx
movq %r14, %r8
movq %rbx, %r9
callq 0x1513b0
jmp 0x196b1
movq 0x28(%r14), %rax
movq (%rax,%rcx,8), %rax
testl %eax, %eax
je 0x1962c
movq 0x10(%r14), %rdx
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %edi
imulq $0x30, %rsi, %rax
addq %rdx, %rax
addq $0x28, %rax
imulq $0x30, %rdi, %rdx
xorpd %xmm0, %xmm0
xorl %esi, %esi
xorpd %xmm1, %xmm1
cmpb $0x0, (%rax,%rsi)
js 0x1961d
movl -0x14(%rax,%rsi), %edi
cmpb $0x0, (%rbp,%rdi)
jle 0x19615
addsd -0x8(%rax,%rsi), %xmm0
jmp 0x1961d
jns 0x1961d
addsd -0x8(%rax,%rsi), %xmm1
addq $0x30, %rsi
cmpq %rsi, %rdx
jne 0x195fc
subsd %xmm1, %xmm0
jmp 0x19630
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm2
jbe 0x1963d
movb $0x1, (%rbp,%rcx)
jmp 0x196ad
ucomisd %xmm2, %xmm0
jbe 0x1964a
movb $-0x1, (%rbp,%rcx)
jmp 0x196ad
movq 0x8(%rbx), %rax
movabsq $-0x61c8864680b583eb, %rdx # imm = 0x9E3779B97F4A7C15
addq %rdx, %rax
movq %rax, %rdx
shrq $0x1e, %rdx
xorq %rax, %rdx
movabsq $-0x40a7b892e31b1a47, %rax # imm = 0xBF58476D1CE4E5B9
imulq %rax, %rdx
movq %rdx, %rax
shrq $0x1b, %rax
xorq %rdx, %rax
movabsq $-0x6b2fb644ecceee15, %rdx # imm = 0x94D049BB133111EB
imulq %rdx, %rax
movq %rax, %rdx
shrq $0x1f, %rdx
xorq %rax, %rdx
movq %rdx, 0x8(%rbx)
andl $0x1, %edx
cmpq $0x1, %rdx
movl $0x0, %eax
sbbl %eax, %eax
orb $0x1, %al
movb %al, (%rbp,%rcx)
movq (%rsp), %r12
movq (%r12), %r12
movq (%rbx), %rbp
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %rbp, %rcx
movq %r15, %r8
callq 0x151d01
cmpl $-0x1, %eax
xorpd %xmm2, %xmm2
jne 0x19567
movq 0x20(%rsp), %rdi
callq 0x2220
movq 0x38(%rsp), %rdi
callq 0x2220
movq 0x50(%rsp), %rdi
callq 0x2220
movq 0x68(%rsp), %rdi
callq 0x2220
movq 0x80(%rsp), %rdi
callq 0x2220
movq %r15, %rdi
callq 0x2220
movq (%rsp), %rcx
movq (%rcx), %rax
movq 0x18(%rax), %rax
testl $0x7fffffff, 0x14(%rax) # imm = 0x7FFFFFFF
jne 0x19768
movq 0x2708af(%rip), %rax    # 0x289fe0
movq (%rax), %rbx
callq 0x1303c7
subsd 0x10(%rsp), %xmm0
leaq 0x216255(%rip), %rsi    # 0x22f99b
leaq 0x2168cd(%rip), %rdx    # 0x23001a
movq %rbx, %rdi
movb $0x1, %al
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22b0
xorl %r15d, %r15d
leaq 0x213522(%rip), %r12    # 0x22cc94
pushq $0x6
popq %r13
pushq $0x1
popq %rbp
movq (%rbx), %rax
cmpb $0x0, (%rax,%r15)
je 0x197b2
movq 0x28(%r14), %rax
cmpl $0x0, (%rax,%r15,8)
jne 0x19796
movq (%rbx), %rax
movb $0x0, (%rax,%r15)
incq %r15
movq (%rcx), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %r15
jb 0x19779
jmp 0x1972a
movq 0x270827(%rip), %rax    # 0x289fe0
movq (%rax), %rcx
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x2410
movq (%rsp), %rcx
jmp 0x19783