// File: chhylp123[P]hifiasm/horder.cpp
// Function: get_long_switch_scaffolds(horder_t*, sc_lay_t*, osg_t*)
void get_long_switch_scaffolds(horder_t *h, sc_lay_t *sl, osg_t *lg)
{
    fprintf(stderr, "\n[M::%s::]\n", __func__);
    uint32_t i, k, r_i, ori, sw[3], sw_inner[3];
    uint64_t v, len;
    kvec_t(uint64_t) idx; kv_init(idx);
    lay_t *p = NULL;
    ma_utg_t *u = NULL;
    for (i = 0; i < sl->n; i++)
    {
        p = &(sl->a[i]);
        sw[0] = sw[1] = sw[2] = 0;
        for (k = 0; k < p->n; k += 2)
        {
            u = &(h->ug->u.a[p->a[k]>>1]);
            ori = p->a[k]&1;
            for (r_i = 0; r_i < u->n; r_i++)
            {
                v = (ori?u->a[u->n - r_i - 1]:u->a[r_i]);
                if(v != (uint64_t)-1)
                {
                    v >>= 33;
                    sw[R_INF.trio_flag[v]]++;
                }
            }
        }

        v = MIN(sw[FATHER], sw[MOTHER]);
        v = ((uint32_t)-1) - v;
        v <<= 32; v |= i;
        kv_push(uint64_t, idx, v);
    }

    radix_sort_ho64(idx.a, idx.a+idx.n);
    for (i = 0; i < sl->n; i++)
    {
        p = &(sl->a[(uint32_t)(idx.a[i])]);
        fprintf(stderr, "\nscaf-%u-th, occ-%u\n", (uint32_t)(idx.a[i]), (uint32_t)(p->n>>1));
        sw[0] = sw[1] = sw[2] = len = 0;
        for (k = 0; k < p->n; k += 2)
        {
            sw_inner[0] = sw_inner[1] = sw_inner[2] = 0;
            u = &(h->ug->u.a[p->a[k]>>1]);
            ori = p->a[k]&1;
            for (r_i = 0; r_i < u->n; r_i++)
            {
                v = (ori?u->a[u->n - r_i - 1]:u->a[r_i]);
                if(v != (uint64_t)-1)
                {
                    v >>= 33;
                    if(R_INF.trio_flag[v] == FATHER || R_INF.trio_flag[v] == MOTHER)
                    {
                        sw[R_INF.trio_flag[v]]++;
                        sw_inner[R_INF.trio_flag[v]]++;
                    }
                }
            }
            fprintf(stderr, "utg%.6ul (ori: %u), u->len-%u, sw_in[FATHER]-%u, sw_in[MOTHER]-%u\n", 
            (p->a[k]>>1)+1, p->a[k]&1, u->len, sw_inner[FATHER], sw_inner[MOTHER]);
            len += u->len + ((k + 2)< p->n? GAP_LEN:0);
        }
        fprintf(stderr, "sw[FATHER]-%u, sw[MOTHER]-%u, len-%lu\n", sw[FATHER], sw[MOTHER], len);
    }
    kv_destroy(idx);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq 0x17ece2(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x149408(%rip), %rsi    # 0x38e710
leaq 0x14940d(%rip), %rdx    # 0x38e71c
movb $0x0, %al
callq 0x22a0
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x245546
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x70(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x245480
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rax
movq 0x10(%rax), %rax
movq -0x70(%rbp), %rcx
movq (%rcx), %rcx
movl -0x20(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
movq (%rax), %rax
movl -0x20(%rbp), %ecx
movl (%rax,%rcx,4), %eax
andl $0x1, %eax
movl %eax, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x78(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x245470
cmpl $0x0, -0x28(%rbp)
je 0x245414
movq -0x78(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x78(%rbp), %rcx
movl 0x10(%rcx), %ecx
subl -0x24(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x80(%rbp)
jmp 0x245427
movq -0x78(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x24(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $-0x1, -0x48(%rbp)
je 0x245460
movq -0x48(%rbp), %rax
shrq $0x21, %rax
movq %rax, -0x48(%rbp)
leaq 0x17fe87(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movq -0x48(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl -0x34(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0x34(%rbp,%rax,4)
jmp 0x245462
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2453dd
jmp 0x245472
movl -0x20(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x20(%rbp)
jmp 0x245387
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
ja 0x245493
movl -0x30(%rbp), %eax
movl %eax, -0x84(%rbp)
jmp 0x24549c
movl -0x2c(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
movl %eax, %eax
movq %rax, -0x48(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
subq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
shlq $0x20, %rax
movq %rax, -0x48(%rbp)
movl -0x1c(%rbp), %eax
orq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x60(%rbp), %rax
jne 0x24551b
cmpq $0x0, -0x60(%rbp)
je 0x2454ed
movq -0x60(%rbp), %rax
shlq %rax
movq %rax, -0x90(%rbp)
jmp 0x2454fb
movl $0x2, %eax
movq %rax, -0x90(%rbp)
jmp 0x2454fb
movq -0x90(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rdx
movq -0x58(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x68(%rbp)
movq %rdx, (%rax,%rcx,8)
jmp 0x245538
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x245345
movq -0x58(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x68(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x22e3a0
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x245808
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x58(%rbp), %rcx
movl -0x1c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq 0x17ea44(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x58(%rbp), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %edx
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rax
shrq %rax
movl %eax, %ecx
leaq 0x149176(%rip), %rsi    # 0x38e736
movb $0x0, %al
callq 0x22a0
movq $0x0, -0x50(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x70(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x2457d8
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rax
movq 0x10(%rax), %rax
movq -0x70(%rbp), %rcx
movq (%rcx), %rcx
movl -0x20(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
movq (%rax), %rax
movl -0x20(%rbp), %ecx
movl (%rax,%rcx,4), %eax
andl $0x1, %eax
movl %eax, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x78(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x245742
cmpl $0x0, -0x28(%rbp)
je 0x245690
movq -0x78(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x78(%rbp), %rcx
movl 0x10(%rcx), %ecx
subl -0x24(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x98(%rbp)
jmp 0x2456a6
movq -0x78(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x24(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $-0x1, -0x48(%rbp)
je 0x245732
movq -0x48(%rbp), %rax
shrq $0x21, %rax
movq %rax, -0x48(%rbp)
leaq 0x17fc05(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movq -0x48(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x1, %eax
je 0x2456f4
leaq 0x17fbed(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movq -0x48(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x2, %eax
jne 0x245730
leaq 0x17fbd5(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movq -0x48(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl -0x34(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0x34(%rbp,%rax,4)
leaq 0x17fbb7(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movq -0x48(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl -0x40(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0x40(%rbp,%rax,4)
jmp 0x245732
jmp 0x245734
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x245656
movq 0x17e897(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x70(%rbp), %rax
movq (%rax), %rax
movl -0x20(%rbp), %ecx
movl (%rax,%rcx,4), %edx
shrl %edx
addl $0x1, %edx
movq -0x70(%rbp), %rax
movq (%rax), %rax
movl -0x20(%rbp), %ecx
movl (%rax,%rcx,4), %ecx
andl $0x1, %ecx
movq -0x78(%rbp), %rax
movl (%rax), %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movl -0x3c(%rbp), %r9d
movl -0x38(%rbp), %eax
leaq 0x148fc1(%rip), %rsi    # 0x38e74b
movl %eax, (%rsp)
movb $0x0, %al
callq 0x22a0
movq -0x78(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl -0x20(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movl %ecx, %esi
movq -0x70(%rbp), %rcx
movq 0x8(%rcx), %rdi
xorl %ecx, %ecx
movl $0x64, %edx
cmpq %rdi, %rsi
cmovbl %edx, %ecx
addl %ecx, %eax
cltq
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movl -0x20(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x20(%rbp)
jmp 0x2455eb
movq 0x17e801(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x30(%rbp), %edx
movl -0x2c(%rbp), %ecx
movq -0x50(%rbp), %r8
leaq 0x148f9b(%rip), %rsi    # 0x38e78e
movb $0x0, %al
callq 0x22a0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x245565
movq -0x58(%rbp), %rdi
callq 0x2210
addq $0xa0, %rsp
popq %rbp
retq
nopw (%rax,%rax)