// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/horder.cpp
// Function: get_update_trans_idx(horder_t*, trans_col_t*)
kv_u_trans_t *get_update_trans_idx(horder_t *h, trans_col_t *t_idx)
{
    uint64_t i, k, l;
    uint32_t uid/**, q_n, t_n**/;
    ma_ug_t *ug = h->ug;
    asg_t *rg = h->r_g;
    kv_u_trans_t *idx = NULL; CALLOC(idx, 1);
    u_trans_hit_idx iter;
    u_trans_hit_t hit;
    kvec_t(u_hit_t) b; kv_init(b);
    uint64_t *b_idx = NULL; CALLOC(b_idx, t_idx->ref->idx.n);
    /**u_hit_t *q, *t;**/
    u_hit_t *p = NULL;
    for (i = 0; i < ug->u.n; i++)
    {
        uid = i<<1;
        reset_u_trans_hit_idx(&iter, &uid, 1, ug, rg, t_idx->idx, 0, ug->u.a[i].len); 
        while(get_u_trans_hit(&iter, &hit))///get [qScur, qEcur), [qSpre, qEpre)
        {
            kv_pushp(u_hit_t, b, &p);
            p->Scur = hit.qScur;
            p->Ecur = hit.qEcur;
            p->Spre = hit.qSpre;
            p->Epre = hit.qEpre;
            p->uPre = hit.qn;
            p->uCur = uid;
        }
    }

    radix_sort_u_hit(b.a, b.a + b.n);
    for (k = 1, l = 0; k <= b.n; ++k) 
    {   
        if (k == b.n || (b.a[k].uPre>>1) != (b.a[l].uPre>>1))
        {            
            b_idx[b.a[l].uPre>>1] = (uint64_t)l << 32 | (k - l);
            l = k;
        }
    }

    /**
    for (i = 0; i < t_idx->ref->idx.n; i++)
    {
        q_n = (uint32_t)b_idx[i];
        q = b.a + (b_idx[i]>>32);
        if(!q_n) continue;
    }
    **/
    
    // for (i = 0; i < b.n; i++)
    // {
        
    // }
    
    
    free(b_idx);
    kv_destroy(b);
    return idx;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, 0x20(%rsp)
movq 0xc8(%rdi), %r12
movq 0xd0(%rdi), %rax
movq %rax, 0x18(%rsp)
movl $0x1, %edi
movl $0x30, %esi
callq 0x2120
movq %rax, %rbx
cmpq $0x0, (%r12)
je 0x17c4dd
movq %rbx, 0x8(%rsp)
xorl %r14d, %r14d
leaq 0x60(%rsp), %rbp
xorl %r15d, %r15d
xorl %r13d, %r13d
xorl %ecx, %ecx
movq %r12, 0x10(%rsp)
leal (%rcx,%rcx), %eax
movl %eax, 0x4(%rsp)
movq 0x20(%rsp), %rax
movq 0x8(%rax), %r9
movq 0x10(%r12), %rax
movq %rcx, 0x28(%rsp)
leaq (%rcx,%rcx,4), %rcx
movl (%rax,%rcx,8), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
movq %rbp, %rdi
leaq 0x4(%rsp), %rsi
movl $0x1, %edx
movq %r12, %rcx
movq 0x18(%rsp), %r8
pushq %rax
pushq $0x0
callq 0xbd420
addq $0x10, %rsp
movq %rbp, %rdi
leaq 0x30(%rsp), %rsi
callq 0xbd461
testl %eax, %eax
je 0x17c4a8
leaq (%r14,%r14), %r12
leaq (%r14,%r14,2), %rax
leaq 0xa(,%rax,4), %rbx
cmpq %r15, %r14
jne 0x17c46f
testq %r14, %r14
movq %r12, %r15
movl $0x2, %eax
cmoveq %rax, %r15
leaq (,%r15,8), %rax
leaq (%rax,%rax,2), %rsi
movq %r13, %rdi
callq 0x2370
movq %rax, %r13
incq %r14
movaps 0x30(%rsp), %xmm0
movups %xmm0, -0x14(%r13,%rbx,2)
movl 0x40(%rsp), %eax
movl %eax, (%r13,%rbx,2)
movl 0x4(%rsp), %eax
movl %eax, -0x4(%r13,%rbx,2)
movq %rbp, %rdi
leaq 0x30(%rsp), %rsi
callq 0xbd461
addq $0x2, %r12
addq $0xc, %rbx
testl %eax, %eax
jne 0x17c444
movq 0x28(%rsp), %rcx
incq %rcx
movq 0x10(%rsp), %r12
cmpq (%r12), %rcx
jb 0x17c3da
leaq (%r14,%r14,2), %rax
leaq (,%rax,8), %rsi
addq %r13, %rsi
movq %r13, %rdi
callq 0x17462b
movq 0x8(%rsp), %rbx
jmp 0x17c4e9
xorl %r13d, %r13d
xorl %edi, %edi
xorl %esi, %esi
callq 0x17462b
movq %r13, %rdi
callq 0x2220
movq %rbx, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq