// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movq %rdi, %r15
movq %rsi, 0x8(%rsp)
movq 0x8(%rsi), %rax
testq %rax, %rax
je 0x17ece8
movl $0x1, %r13d
xorl %r8d, %r8d
movq %r15, 0x20(%rsp)
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
cmpq %rax, %r13
jne 0x17eace
leaq (%r8,%r8,2), %rax
movq (%rcx,%rax,8), %rdx
jmp 0x17eaeb
leaq (,%r13,2), %rsi
addq %r13, %rsi
leaq (%r8,%r8,2), %rdx
movq (%rcx,%rdx,8), %rdx
cmpq %rdx, (%rcx,%rsi,8)
je 0x17ecaf
movq (%r15), %rdi
leaq (%rdx,%rdx,2), %rax
leaq (%rdi,%rax,8), %rax
movq %rax, 0x10(%rsp)
cmpq %r13, %r8
jae 0x17ebea
movq 0x8(%r15), %rax
leaq (%r8,%r8,2), %rcx
leaq 0x10(,%rcx,8), %rbx
xorl %ebp, %ebp
movq %r13, 0x28(%rsp)
movq %r8, 0x18(%rsp)
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
movq (%rcx,%rbx), %r12
cmpq 0x10(%r15), %rax
jne 0x17eb5d
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%r15)
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, (%r15)
movq 0x8(%r15), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x30(%rsp)
movq %rcx, 0x8(%r15)
leaq (%rax,%rax,2), %r14
movq %r12, %rax
subq %rbp, %rax
leaq 0x2(,%rax,2), %rcx
addq %rax, %rax
movq %rcx, 0x10(%rdi,%r14,8)
movq %rcx, 0x8(%rdi,%r14,8)
leaq 0x8(,%rax,4), %r15
movq %rdi, %r13
movq %r15, %rdi
callq 0x2280
movq %rax, (%r13,%r14,8)
shlq $0x3, %rbp
movq 0x10(%rsp), %rcx
addq (%rcx), %rbp
movq %rax, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movq 0x20(%rsp), %r15
callq 0x2160
movq %r13, %rdi
incq %r12
movq 0x18(%rsp), %r8
incq %r8
addq $0x18, %rbx
movq 0x30(%rsp), %rax
movq %r12, %rbp
movq 0x28(%rsp), %r13
cmpq %r8, %r13
jne 0x17eb1b
jmp 0x17ebed
xorl %r12d, %r12d
movq 0x10(%rsp), %rax
leaq 0x8(%rax), %rbx
movq 0x8(%rax), %rbp
movq %rbp, %rax
shrq %rax
cmpq %rax, %r12
jae 0x17ecbd
movq 0x8(%r15), %rax
cmpq 0x10(%r15), %rax
movq %rbx, 0x18(%rsp)
jne 0x17ec43
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%r15)
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, (%r15)
movq 0x8(%r15), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%r15)
leaq (%rax,%rax,2), %rbx
subq %r12, %rbp
subq %r12, %rbp
andq $-0x2, %rbp
movq %rbp, 0x10(%rdi,%rbx,8)
movq %rbp, 0x8(%rdi,%rbx,8)
shlq $0x2, %rbp
movq %rdi, %r14
movq %rbp, %rdi
callq 0x2280
movq %rax, (%r14,%rbx,8)
shlq $0x3, %r12
movq 0x10(%rsp), %rbx
addq (%rbx), %r12
movq %rax, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x2160
movq (%rbx), %rdi
callq 0x2220
xorps %xmm0, %xmm0
movq 0x18(%rsp), %rax
movups %xmm0, (%rax)
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movq %r13, %r8
incq %r13
cmpq %rax, %r13
jbe 0x17eab7
jmp 0x17ece8
movq 0x11631c(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl $0xd, %esi
movl $0x1, %edx
leaq 0xbf1f7(%rip), %rdi     # 0x23decf
callq 0x2410
movq (%rbx), %rbp
movq (%r15), %rdi
jmp 0x17ec09
movq 0x8(%r15), %rdi
testq %rdi, %rdi
je 0x17ed5f
movq (%r15), %rcx
xorl %eax, %eax
xorps %xmm0, %xmm0
xorl %esi, %esi
xorl %edx, %edx
cmpq $0x0, (%rcx,%rax)
je 0x17ed51
leaq (%rcx,%rax), %r8
leaq (,%rdx,8), %rdi
leaq (%rdi,%rdi,2), %rdi
movq 0x10(%r8), %r9
movq %r9, 0x10(%rcx,%rdi)
movups (%r8), %xmm1
movups %xmm1, (%rcx,%rdi)
movq (%r15), %rcx
movups %xmm0, (%rcx,%rax)
movq $0x0, 0x10(%rcx,%rax)
cmpq $0x2, 0x8(%rcx,%rdi)
jne 0x17ed4a
addq %rcx, %rdi
movq (%rdi), %rdi
andl $-0x2, (%rdi)
orb $0x1, 0x4(%rdi)
incq %rdx
movq 0x8(%r15), %rdi
incq %rsi
addq $0x18, %rax
cmpq %rdi, %rsi
jb 0x17ecfd
jmp 0x17ed61
xorl %edx, %edx
movq %rdx, 0x8(%r15)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq