// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/horder.cpp
// Function: update_sc_lay(sc_lay_t*, h_covs*)
void update_sc_lay(sc_lay_t *sl, h_covs *b)
{
    uint64_t k, l, i, pidx, cidx;
    lay_t *s = NULL;
    lay_t *p = NULL;
    for (k = 1, l = 0; k <= b->n; ++k) 
    {   
        if (k == b->n || (b->a[k].s != b->a[l].s)) 
        {
            s = &(sl->a[b->a[l].s]);
            for (i = l, pidx = 0; i < k; i++){
                cidx = b->a[i].dp;
                kv_pushp(lay_t, *sl, &p);
                kv_init(*p);
                p->n = p->m = (cidx - pidx + 1)<<1;
                MALLOC(p->a, p->n);
                memcpy(p->a, s->a + (pidx<<1), sizeof(*(p->a))*p->n);
                pidx = cidx + 1;
            }

            if(pidx >= (s->n>>1)) fprintf(stderr, "ERROR-update\n");
            cidx = (s->n>>1)-1;
            kv_pushp(lay_t, *sl, &p);
            kv_init(*p);
            p->n = p->m = (cidx - pidx + 1)<<1;
            MALLOC(p->a, p->n);
            memcpy(p->a, s->a + (pidx<<1), sizeof(*(p->a))*p->n);
            free(s->a); s->n = s->m = 0;
            l = k;
        }
    }

    for (i = k = 0; i < sl->n; i++){
        if(!sl->a[i].a) continue;
        sl->a[k] = sl->a[i];
        sl->a[i].a = NULL; sl->a[i].n = sl->a[i].m = 0;
        if(sl->a[k].n == 2){
            sl->a[k].a[0] >>= 1; sl->a[k].a[0] <<= 1;
            sl->a[k].a[1] >>= 1; sl->a[k].a[1] <<= 1; sl->a[k].a[1]++;
        }
        k++;
    }
    sl->n = k;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbp
movq %rsi, (%rsp)
movq 0x8(%rsi), %rax
testq %rax, %rax
je 0x178040
movl $0x1, %esi
xorl %edi, %edi
movq %rbp, 0x18(%rsp)
cmpq %rax, %rsi
je 0x177e5e
movq (%rsp), %rax
movq (%rax), %rax
leaq (%rsi,%rsi,2), %rcx
movq (%rax,%rcx,8), %rcx
leaq (%rdi,%rdi,2), %rdx
cmpq (%rax,%rdx,8), %rcx
je 0x178020
movq (%rsp), %rax
movq (%rax), %rcx
leaq (%rdi,%rdi,2), %rax
movq (%rcx,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rbx
shlq $0x3, %rbx
addq (%rbp), %rbx
cmpq %rsi, %rdi
movq %rsi, 0x10(%rsp)
movq %rbx, 0x8(%rsp)
jae 0x177f62
leaq 0x10(,%rax,8), %r14
xorl %r12d, %r12d
movq %rdi, 0x20(%rsp)
movq (%rsp), %rax
movq (%rax), %rax
movq (%rax,%r14), %r15
movq 0x10(%rbp), %rax
cmpq %rax, 0x8(%rbp)
jne 0x177eda
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rbp)
movq (%rbp), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq %rax, (%rbp)
movq (%rbp), %rbx
movq 0x8(%rbp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rbp)
leaq (%rax,%rax,2), %rbp
movq %r15, %rax
subq %r12, %rax
leaq 0x2(,%rax,2), %rcx
addq %rax, %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rbx,%rbp,8)
movq %rcx, 0x10(%rbx,%rbp,8)
movq %rcx, 0x8(%rbx,%rbp,8)
leaq 0x8(,%rax,4), %r13
movq %r13, %rdi
callq 0x2280
movq %rax, (%rbx,%rbp,8)
movq 0x18(%rsp), %rbp
shlq $0x3, %r12
movq 0x8(%rsp), %rbx
addq (%rbx), %r12
movq %rax, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x2160
incq %r15
movq 0x20(%rsp), %rdi
incq %rdi
addq $0x18, %r14
movq %r15, %r12
cmpq %rdi, 0x10(%rsp)
jne 0x177e97
jmp 0x177f65
xorl %r15d, %r15d
movq 0x8(%rbx), %rax
shrq %rax
cmpq %rax, %r15
jae 0x178036
leaq 0x8(%rbx), %r14
movq (%r14), %r12
movq 0x10(%rbp), %rax
cmpq %rax, 0x8(%rbp)
jne 0x177faf
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rbp)
movq (%rbp), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq %rax, (%rbp)
movq (%rbp), %rbx
movq 0x8(%rbp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rbp)
leaq (%rax,%rax,2), %r13
subq %r15, %r12
subq %r15, %r12
andq $-0x2, %r12
xorps %xmm0, %xmm0
movups %xmm0, (%rbx,%r13,8)
movq %r12, 0x10(%rbx,%r13,8)
movq %r12, 0x8(%rbx,%r13,8)
shlq $0x2, %r12
movq %r12, %rdi
callq 0x2280
movq %rax, (%rbx,%r13,8)
shlq $0x3, %r15
movq 0x8(%rsp), %rbx
addq (%rbx), %r15
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2160
movq (%rbx), %rdi
callq 0x2220
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movq 0x10(%rsp), %rsi
movq %rsi, %rdi
incq %rsi
movq (%rsp), %rax
movq 0x8(%rax), %rax
cmpq %rax, %rsi
jbe 0x177e3c
jmp 0x178040
callq 0x22b04
jmp 0x177f75
cmpq $0x0, 0x8(%rbp)
je 0x1780b4
xorl %ecx, %ecx
xorps %xmm0, %xmm0
xorl %edx, %edx
xorl %eax, %eax
movq (%rbp), %rdi
cmpq $0x0, (%rdi,%rcx)
je 0x1780a5
leaq (%rdi,%rcx), %r8
leaq (,%rax,8), %rsi
leaq (%rsi,%rsi,2), %rsi
movq 0x10(%r8), %r9
movq %r9, 0x10(%rdi,%rsi)
movups (%r8), %xmm1
movups %xmm1, (%rdi,%rsi)
movq (%rbp), %rdi
movups %xmm0, (%rdi,%rcx)
movq $0x0, 0x10(%rdi,%rcx)
cmpq $0x2, 0x8(%rdi,%rsi)
jne 0x1780a2
addq %rsi, %rdi
movq (%rdi), %rsi
andl $-0x2, (%rsi)
orb $0x1, 0x4(%rsi)
incq %rax
incq %rdx
addq $0x18, %rcx
cmpq 0x8(%rbp), %rdx
jb 0x178050
jmp 0x1780b6
xorl %eax, %eax
movq %rax, 0x8(%rbp)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq