// File: /workspace/github_cpp_makefile_star2_O1/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, 0x28(%rsp)
movq 0xc8(%rdi), %r15
movq 0xd0(%rdi), %rax
movq %rax, 0x20(%rsp)
movl $0x1, %edi
movl $0x30, %esi
callq 0x2120
movq %rax, 0x10(%rsp)
cmpq $0x0, (%r15)
je 0x17593b
xorl %r14d, %r14d
leaq 0x60(%rsp), %rbp
leaq 0x38(%rsp), %r12
xorl %ebx, %ebx
xorl %r13d, %r13d
xorl %ecx, %ecx
movq %r15, 0x18(%rsp)
leal (%rcx,%rcx), %eax
movl %eax, 0xc(%rsp)
movq 0x28(%rsp), %rax
movq 0x8(%rax), %r9
movq 0x10(%r15), %rax
movq %rcx, 0x30(%rsp)
leaq (%rcx,%rcx,4), %rcx
movl (%rax,%rcx,8), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
movq %rbp, %rdi
leaq 0xc(%rsp), %rsi
movl $0x1, %edx
movq %r15, %rcx
movq 0x20(%rsp), %r8
pushq %rax
pushq $0x0
callq 0xbc36a
addq $0x10, %rsp
movq %rbp, %rdi
movq %r12, %rsi
callq 0xbc3ab
testl %eax, %eax
je 0x175923
leaq (%r14,%r14,2), %rax
leaq 0x14(,%rax,8), %r15
cmpq %rbx, %r14
jne 0x1758d3
movq %rbx, %rax
movq %rbp, %rbx
movq %r12, %rbp
leaq (%rax,%rax), %r12
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %r12
leaq (,%r12,8), %rax
leaq (%rax,%rax,2), %rsi
movq %r13, %rdi
callq 0x2370
movq %rax, %r13
movq %r12, %rax
movq %rbp, %r12
movq %rbx, %rbp
movq %rax, %rbx
incq %r14
movl 0x40(%rsp), %eax
movl %eax, -0xc(%r13,%r15)
movl 0x44(%rsp), %eax
movl %eax, -0x8(%r13,%r15)
movl 0x38(%rsp), %eax
movl %eax, -0x14(%r13,%r15)
movl 0x3c(%rsp), %eax
movl %eax, -0x10(%r13,%r15)
movl 0x48(%rsp), %eax
movl %eax, (%r13,%r15)
movl 0xc(%rsp), %eax
movl %eax, -0x4(%r13,%r15)
movq %rbp, %rdi
movq %r12, %rsi
callq 0xbc3ab
addq $0x18, %r15
testl %eax, %eax
jne 0x175892
movq 0x30(%rsp), %rcx
incq %rcx
movq 0x18(%rsp), %r15
cmpq (%r15), %rcx
jb 0x17582b
jmp 0x175941
xorl %r13d, %r13d
xorl %r14d, %r14d
leaq (%r14,%r14,2), %rax
leaq (,%rax,8), %rsi
addq %r13, %rsi
movq %r13, %rdi
callq 0x16dbfd
movq %r13, %rdi
callq 0x2220
movq 0x10(%rsp), %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq