// File: /workspace/github_cpp_makefile_star2_O3/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 0x1365ef
movsd %xmm0, 0x20(%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, 0x18(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x80(%rsp)
movupd %xmm0, 0x70(%rsp)
movupd %xmm0, 0x60(%rsp)
movupd %xmm0, 0x50(%rsp)
movupd %xmm0, 0x40(%rsp)
movupd %xmm0, 0x30(%rsp)
andq $0x0, 0x90(%rsp)
addl %ebp, %ebp
pushq $0x38
popq %rsi
movq %rbp, %rdi
callq 0x2120
movq %rax, 0x10(%rsp)
movq %rax, 0x28(%rsp)
movq (%rbx), %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x20e0
movq %r15, (%rsp)
movq (%r15), %r12
movq 0x18(%rsp), %r15
movq (%rbx), %rbp
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %rbp, %rcx
movq %r15, %r8
callq 0x15847f
cmpl $-0x1, %eax
jne 0x18d9a
movq $0x0, 0x8(%rsp)
xorl %r13d, %r13d
xorl %ebp, %ebp
xorl %r12d, %r12d
movq 0x10(%rsp), %rdi
jmp 0x18f30
xorpd %xmm2, %xmm2
movq %r13, 0x8(%rsp)
movl %eax, %ecx
shrl %ecx
testb $0x1, %al
jne 0x18e06
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 0x28(%rsp), %rcx
movq %r14, %r8
movq %rbx, %r9
callq 0x157b80
movq (%rsp), %r12
movq (%r12), %rdi
movl %ebp, %esi
movl %r15d, %edx
movq %r13, %r15
movq 0x8(%rsp), %r13
leaq 0x28(%rsp), %rcx
movq %r14, %r8
movq %rbx, %r9
callq 0x157b80
jmp 0x18ee7
movq 0x28(%r14), %rax
movq (%rax,%rcx,8), %rax
testl %eax, %eax
je 0x18e80
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 0x18e59
movl -0x14(%rax,%rsi), %edi
cmpb $0x0, (%rbp,%rdi)
jle 0x18e51
addsd -0x8(%rax,%rsi), %xmm0
jmp 0x18e59
jns 0x18e59
addsd -0x8(%rax,%rsi), %xmm1
addq $0x30, %rsi
cmpq %rsi, %rdx
jne 0x18e38
subsd %xmm1, %xmm0
ucomisd %xmm0, %xmm2
jbe 0x18e73
movb $0x1, (%rbp,%rcx)
jmp 0x18ee3
ucomisd %xmm2, %xmm0
jbe 0x18e80
movb $-0x1, (%rbp,%rcx)
jmp 0x18ee3
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 0x15847f
cmpl $-0x1, %eax
xorpd %xmm2, %xmm2
jne 0x18da3
movq 0x28(%rsp), %rdi
movq 0x40(%rsp), %rbp
movq 0x58(%rsp), %r13
movq 0x70(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x88(%rsp), %r12
callq 0x2220
movq %rbp, %rdi
callq 0x2220
movq %r13, %rdi
callq 0x2220
movq 0x8(%rsp), %rdi
callq 0x2220
movq %r12, %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 0x18fb1
movq 0x27c066(%rip), %rax    # 0x294fe0
movq (%rax), %rbx
callq 0x1365ef
subsd 0x20(%rsp), %xmm0
leaq 0x222c5c(%rip), %rsi    # 0x23bbeb
leaq 0x223290(%rip), %rdx    # 0x23c226
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 0x21fec9(%rip), %r12    # 0x238e84
pushq $0x6
popq %r13
pushq $0x1
popq %rbp
movq (%rbx), %rax
cmpb $0x0, (%rax,%r15)
je 0x18ffb
movq 0x28(%r14), %rax
cmpl $0x0, (%rax,%r15,8)
jne 0x18fdf
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 0x18fc2
jmp 0x18f73
movq 0x27bfde(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x2410
movq (%rsp), %rcx
jmp 0x18fcc