// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/horder.cpp
// Function: insert_sc(osg_t*, lay_t*, unsigned int)
void insert_sc(osg_t *g, lay_t *p, uint32_t uid)
{
    uint32_t i, b, e, vb, ve, max_i = (uint32_t)-1, is_found, ori, max_ori = (uint32_t)-1;
    osg_arc_t *bE = NULL, *eE = NULL;
    double w[2], s_w, max_w = -1;
    for (i = 1; i+1 < p->n; i++)///middle points
    {
        b = p->a[i]; e = p->a[i+1]; w[0] = w[1] = 0; 
        s_w = 0; ori = 0; is_found = 0;

        vb = (uid<<1); ve = (uid<<1)+1;
        bE = get_osg_arc(g, vb, b);
        eE = get_osg_arc(g, ve, e);
        if(bE || eE) ///different with slsa2
        {
            if(bE) w[0] += bE->nw;
            if(eE) w[0] += eE->nw;
            is_found++;
        }


        vb = (uid<<1)+1; ve = (uid<<1);
        bE = get_osg_arc(g, vb, b);
        eE = get_osg_arc(g, ve, e);
        if(bE || eE) ///different with slsa2
        {
            if(bE) w[1] += bE->nw;
            if(eE) w[1] += eE->nw;
            is_found++;
        }

        if(is_found > 0)
        {
            s_w = MAX(w[0], w[1]);
            ori = ((w[0] >= w[1])? 0 : 1);
            
            if(max_i == (uint32_t)-1 || max_w < s_w)
            {
                max_w = s_w;
                max_i = i;
                max_ori = ori;
            }
        }
    }


    ///beg point, ///different with slsa2
    i = 0;
    b = (uint32_t)-1; e = p->a[0]; w[0] = w[1] = 0; 
    s_w = 0; ori = 0; is_found = 0;

    vb = (uint32_t)-1; ve = (uid<<1)+1;
    bE = NULL;
    eE = get_osg_arc(g, ve, e);
    if(bE || eE) ///different with slsa2
    {
        if(bE) w[0] += bE->nw;
        if(eE) w[0] += eE->nw;
        is_found++;
    }

    vb = (uint32_t)-1; ve = (uid<<1);
    bE = NULL;
    eE = get_osg_arc(g, ve, e);
    if(bE || eE) ///different with slsa2
    {
        if(bE) w[1] += bE->nw;
        if(eE) w[1] += eE->nw;
        is_found++;
    }

    if(is_found > 0)
    {
        s_w = MAX(w[0], w[1]);
        ori = ((w[0] >= w[1])? 0 : 1);
        
        if(max_i == (uint32_t)-1 || max_w < s_w)
        {
            max_w = s_w;
            max_i = i;
            max_ori = ori;
        }
    }

    ///end point, ///different with slsa2
    i = p->n - 1;
    b = p->a[p->n - 1]; e = (uint32_t)-1; w[0] = w[1] = 0; 
    s_w = 0; ori = 0; is_found = 0;

    vb = (uid<<1); ve = (uint32_t)-1;
    bE = get_osg_arc(g, vb, b);
    eE = NULL;
    if(bE || eE) ///different with slsa2
    {
        if(bE) w[0] += bE->nw;
        if(eE) w[0] += eE->nw;
        is_found++;
    }

    vb = (uid<<1)+1; ve = (uint32_t)-1;
    bE = get_osg_arc(g, vb, b);
    eE = NULL;
    if(bE || eE) ///different with slsa2
    {
        if(bE) w[1] += bE->nw;
        if(eE) w[1] += eE->nw;
        is_found++;
    }

    if(is_found > 0)
    {
        s_w = MAX(w[0], w[1]);
        ori = ((w[0] >= w[1])? 0 : 1);
        
        if(max_i == (uint32_t)-1 || max_w < s_w)
        {
            max_w = s_w;
            max_i = i;
            max_ori = ori;
        }
    }

    if(max_i != 0 && max_i != (uint32_t)-1) max_i++;

    i = p->n;
    kv_resize(uint32_t, *p, p->n+2);
    p->n += 2; 
    while (i > max_i)
    {
        i--;
        p->a[i+2] = p->a[i];
    }
    
    p->a[max_i] = (uid<<1) + max_ori;
    p->a[max_i+1] = (uid<<1) + 1 - max_ori;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, 0x20(%rsp)
movq 0x8(%rsi), %r13
cmpq $0x3, %r13
movq %rdx, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
jb 0x176071
movq (%rsi), %rax
movq %rax, 0x58(%rsp)
leal (%rdx,%rdx), %eax
movl %eax, 0x28(%rsp)
leal 0x1(,%rdx,2), %eax
movl %eax, 0x30(%rsp)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movsd 0xaf613(%rip), %xmm0    # 0x225538
movsd %xmm0, 0x18(%rsp)
movl $0x2, %eax
movl $0x3, %ebp
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, 0x10(%rsp)
movq %r13, 0x60(%rsp)
leal -0x2(%rbp), %edx
movq 0x58(%rsp), %rcx
movq %rdx, 0x68(%rsp)
movl (%rcx,%rdx,4), %r14d
movl (%rcx,%rax,4), %r12d
movq 0x20(%rsp), %r15
movq %r15, %rdi
movl 0x28(%rsp), %esi
movl %r14d, %edx
callq 0x175e98
movq %rax, %rbx
movq %r15, %rdi
movl 0x30(%rsp), %esi
movl %r12d, %edx
callq 0x175e98
xorl %r15d, %r15d
movq %rbx, %rcx
orq %rax, %rcx
xorpd %xmm0, %xmm0
je 0x175fb0
testq %rbx, %rbx
je 0x175fa0
movsd 0x18(%rbx), %xmm0
addsd 0xaf578(%rip), %xmm0    # 0x225518
movl $0x1, %r15d
testq %rax, %rax
je 0x175fb0
addsd 0x18(%rax), %xmm0
movapd %xmm0, 0x70(%rsp)
movq 0x20(%rsp), %r13
movq %r13, %rdi
movl 0x30(%rsp), %esi
movl %r14d, %edx
callq 0x175e98
movq %rax, %rbx
movq %r13, %rdi
movl 0x28(%rsp), %esi
movl %r12d, %edx
callq 0x175e98
xorpd %xmm0, %xmm0
movq %rbx, %rcx
orq %rax, %rcx
movq 0x60(%rsp), %r13
movq 0x10(%rsp), %rcx
je 0x176014
testq %rbx, %rbx
je 0x176004
movsd 0x18(%rbx), %xmm0
addsd 0xaf514(%rip), %xmm0    # 0x225518
movl $0x1, %r15d
testq %rax, %rax
je 0x176014
addsd 0x18(%rax), %xmm0
testl %r15d, %r15d
movapd 0x70(%rsp), %xmm3
je 0x17605d
movapd %xmm0, %xmm1
cmpnlesd %xmm3, %xmm1
movapd %xmm1, %xmm2
andpd %xmm0, %xmm2
andnpd %xmm3, %xmm1
orpd %xmm2, %xmm1
cmpl $-0x1, %ecx
je 0x176045
ucomisd 0x18(%rsp), %xmm1
jbe 0x17605d
xorl %eax, %eax
ucomisd %xmm0, %xmm3
setb %al
movl %eax, 0xc(%rsp)
movq 0x68(%rsp), %rcx
movsd %xmm1, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movl %ebp, %eax
incl %ebp
cmpq %rax, %r13
ja 0x175f44
jmp 0x176091
movsd 0xaf4bf(%rip), %xmm0    # 0x225538
movsd %xmm0, 0x18(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x10(%rsp)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x28(%rsp)
movl (%rax), %r14d
movq 0x50(%rsp), %r15
movl %r15d, %eax
addl %r15d, %r15d
leal 0x1(,%rax,2), %ebp
movq 0x20(%rsp), %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0x175e98
testq %rax, %rax
je 0x1760dd
xorpd %xmm0, %xmm0
addsd 0x18(%rax), %xmm0
movapd %xmm0, 0x30(%rsp)
movl $0x1, %ebx
jmp 0x1760e9
xorl %ebx, %ebx
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq 0x20(%rsp), %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x175e98
testq %rax, %rax
xorpd %xmm2, %xmm2
je 0x17610c
addsd 0x18(%rax), %xmm2
movl $0x1, %ebx
testl %ebx, %ebx
movq 0x10(%rsp), %r12
je 0x17615e
movapd %xmm2, %xmm0
movapd 0x30(%rsp), %xmm3
cmpnlesd %xmm3, %xmm0
movapd %xmm0, %xmm1
andpd %xmm2, %xmm1
andnpd %xmm3, %xmm0
orpd %xmm1, %xmm0
cmpl $-0x1, %r12d
je 0x176142
ucomisd 0x18(%rsp), %xmm0
jbe 0x17615e
xorl %eax, %eax
movapd 0x30(%rsp), %xmm1
ucomisd %xmm2, %xmm1
setb %al
movl %eax, 0xc(%rsp)
xorl %r12d, %r12d
movsd %xmm0, 0x18(%rsp)
movq 0x28(%rsp), %rax
movl -0x4(%rax,%r13,4), %r14d
movq 0x20(%rsp), %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x175e98
testq %rax, %rax
je 0x176193
xorpd %xmm0, %xmm0
addsd 0x18(%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movl $0x1, %ebx
jmp 0x17619f
xorl %ebx, %ebx
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x20(%rsp), %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0x175e98
testq %rax, %rax
xorpd %xmm0, %xmm0
je 0x1761c1
addsd 0x18(%rax), %xmm0
movl $0x1, %ebx
testl %ebx, %ebx
movq %r12, %r14
movsd 0x10(%rsp), %xmm1
je 0x176204
leaq -0x1(%r13), %rax
cmpl $-0x1, %r14d
sete %dl
xorl %ecx, %ecx
ucomisd %xmm0, %xmm1
setb %cl
jb 0x1761e8
movapd %xmm1, %xmm0
ucomisd 0x18(%rsp), %xmm0
seta %sil
orb %sil, %dl
cmovnel %eax, %r14d
movl 0xc(%rsp), %eax
cmovnel %ecx, %eax
movl %eax, 0xc(%rsp)
leal -0x1(%r14), %eax
cmpl $-0x2, %eax
adcl $0x0, %r14d
leaq 0x2(%r13), %rax
movq 0x48(%rsp), %rbx
cmpq %rax, 0x10(%rbx)
jae 0x176270
leaq 0x1(%r13), %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x10(%rbx)
leaq 0x4(,%rcx,4), %rsi
movq 0x28(%rsp), %rdi
callq 0x2370
movq %rax, (%rbx)
addq $0x2, 0x8(%rbx)
movl %r14d, %eax
cmpl %r13d, %r14d
jae 0x176298
movq (%rbx), %rcx
movl %r13d, %edx
leaq -0x1(%rdx), %rsi
movl -0x4(%rcx,%rdx,4), %edi
incl %edx
movl %edi, (%rcx,%rdx,4)
movq %rsi, %rdx
cmpq %rax, %rsi
ja 0x176283
movl 0xc(%rsp), %edx
addl %edx, %r15d
movq (%rbx), %rcx
movl %r15d, (%rcx,%rax,4)
subl %edx, %ebp
incl %r14d
movl %ebp, (%rcx,%r14,4)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq