// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0x1
popq %r8
xorl %r9d, %r9d
movq %rdi, (%rsp)
movq %rsi, 0x10(%rsp)
cmpq 0x8(%rsi), %r8
ja 0x13bf05
movq (%rsi), %rcx
jne 0x13bd21
imulq $0x18, %r9, %rax
movq (%rcx,%rax), %rax
jmp 0x13bd37
imulq $0x18, %r8, %rdx
imulq $0x18, %r9, %rax
movq (%rcx,%rax), %rax
cmpq %rax, (%rcx,%rdx)
je 0x13bed2
movq (%rdi), %r12
imulq $0x18, %rax, %rax
addq %r12, %rax
movq %rax, 0x8(%rsp)
imulq $0x18, %r9, %r14
addq $0x10, %r14
xorl %ebx, %ebx
movq %r8, 0x18(%rsp)
cmpq %r8, %r9
jae 0x13be16
movq %r9, 0x20(%rsp)
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq (%rax,%r14), %rbp
movq (%rsp), %r15
movq 0x8(%r15), %rax
cmpq 0x10(%r15), %rax
jne 0x13bda5
leaq (%rax,%rax), %rcx
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rcx
movq %rcx, 0x10(%r15)
imulq $0x18, %rcx, %rsi
movq %r12, %rdi
callq 0x2370
movq %rax, %r12
movq %rax, (%r15)
movq 0x8(%r15), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%r15)
imulq $0x18, %rax, %r15
movq %rbp, %rax
subq %rbx, %rax
leaq 0x2(,%rax,2), %rcx
addq %rax, %rax
movq %rcx, 0x10(%r12,%r15)
movq %rcx, 0x8(%r12,%r15)
leaq 0x8(,%rax,4), %r13
movq %r13, %rdi
callq 0x2280
movq %rax, (%r12,%r15)
shlq $0x3, %rbx
movq 0x8(%rsp), %rcx
addq (%rcx), %rbx
movq %rax, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x2160
incq %rbp
movq 0x20(%rsp), %r9
incq %r9
addq $0x18, %r14
movq %rbp, %rbx
movq 0x18(%rsp), %r8
jmp 0x13bd55
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %r15
movq 0x8(%rax), %r13
movq %r13, %rax
shrq %rax
cmpq %rax, %rbx
jae 0x13beda
movq (%rsp), %rbp
movq 0x8(%rbp), %rax
cmpq 0x10(%rbp), %rax
jne 0x13be69
leaq (%rax,%rax), %rcx
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rbp)
imulq $0x18, %rcx, %rsi
movq %r12, %rdi
callq 0x2370
movq %rax, %r12
movq %rax, (%rbp)
movq 0x8(%rbp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rbp)
imulq $0x18, %rax, %r14
subq %rbx, %r13
subq %rbx, %r13
andq $-0x2, %r13
movq %r13, 0x10(%r12,%r14)
movq %r13, 0x8(%r12,%r14)
shlq $0x2, %r13
movq %r13, %rdi
callq 0x2280
movq %rax, (%r12,%r14)
shlq $0x3, %rbx
movq 0x8(%rsp), %r14
addq (%r14), %rbx
movq %rax, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x2160
movq (%r14), %rdi
callq 0x2220
xorps %xmm0, %xmm0
movups %xmm0, (%r15)
movq 0x18(%rsp), %r8
movq %r8, %r9
movq %rbp, %rdi
movq 0x10(%rsp), %rsi
incq %r8
jmp 0x13bd08
movq 0x1170ff(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0xb3ea4(%rip), %rdi     # 0x1efd8f
pushq $0xd
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq (%r15), %r13
movq (%rsp), %rax
movq (%rax), %r12
jmp 0x13be32
xorl %eax, %eax
xorps %xmm0, %xmm0
xorl %ecx, %ecx
xorl %edx, %edx
cmpq 0x8(%rdi), %rdx
jae 0x13bf67
movq (%rdi), %r10
cmpq $0x0, (%r10,%rax)
je 0x13bf5e
leaq (%r10,%rax), %r8
imulq $0x18, %rcx, %rsi
movq 0x10(%r8), %r9
movq %r9, 0x10(%r10,%rsi)
movups (%r8), %xmm1
movups %xmm1, (%r10,%rsi)
movq (%rdi), %r8
andq $0x0, 0x10(%r8,%rax)
movups %xmm0, (%r8,%rax)
cmpq $0x2, 0x8(%r8,%rsi)
jne 0x13bf5b
addq %rsi, %r8
movq (%r8), %rsi
andl $-0x2, (%rsi)
orb $0x1, 0x4(%rsi)
incq %rcx
incq %rdx
addq $0x18, %rax
jmp 0x13bf0e
movq %rcx, 0x8(%rdi)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq