// File: 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
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0xd0(%rax), %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x1, %edi
movl $0x30, %esi
callq 0x2140
movq %rax, -0x48(%rbp)
movq $0x0, -0xd8(%rbp)
movq $0x0, -0xe0(%rbp)
movq $0x0, -0xd0(%rbp)
movq $0x0, -0xe8(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rdi
movl $0x8, %esi
callq 0x2140
movq %rax, -0xe8(%rbp)
movq $0x0, -0xf0(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x24154c
movq -0x18(%rbp), %rax
shlq %rax
movl %eax, -0x2c(%rbp)
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
movq -0x10(%rbp), %rax
movq 0x8(%rax), %r9
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x18(%rbp), %rdx
addq %rdx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq -0xa0(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
movl $0x1, %edx
xorl %r10d, %r10d
movl $0x0, (%rsp)
movl %eax, 0x8(%rsp)
callq 0xf8900
leaq -0xa0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0xf89e0
cmpl $0x0, %eax
je 0x241539
jmp 0x24144a
movq -0xe0(%rbp), %rax
cmpq -0xd8(%rbp), %rax
jne 0x2414ae
cmpq $0x0, -0xd8(%rbp)
je 0x241477
movq -0xd8(%rbp), %rax
shlq %rax
movq %rax, -0xf8(%rbp)
jmp 0x241485
movl $0x2, %eax
movq %rax, -0xf8(%rbp)
jmp 0x241485
movq -0xf8(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xd0(%rbp), %rdi
imulq $0x18, -0xd8(%rbp), %rsi
callq 0x2360
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movq -0xe0(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0xe0(%rbp)
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xf0(%rbp)
movl -0xc0(%rbp), %ecx
movq -0xf0(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0xbc(%rbp), %ecx
movq -0xf0(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0xc8(%rbp), %ecx
movq -0xf0(%rbp), %rax
movl %ecx, (%rax)
movl -0xc4(%rbp), %ecx
movq -0xf0(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0xb8(%rbp), %ecx
movq -0xf0(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0x2c(%rbp), %ecx
movq -0xf0(%rbp), %rax
movl %ecx, 0x10(%rax)
jmp 0x24142c
jmp 0x24153b
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x2413c7
movq -0xd0(%rbp), %rdi
movq -0xd0(%rbp), %rsi
imulq $0x18, -0xe0(%rbp), %rax
addq %rax, %rsi
callq 0x231670
movq $0x1, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x20(%rbp), %rax
cmpq -0xe0(%rbp), %rax
ja 0x241613
movq -0x20(%rbp), %rax
cmpq -0xe0(%rbp), %rax
je 0x2415c4
movq -0xd0(%rbp), %rax
imulq $0x18, -0x20(%rbp), %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
shrl %eax
movq -0xd0(%rbp), %rcx
imulq $0x18, -0x28(%rbp), %rdx
addq %rdx, %rcx
movl 0x14(%rcx), %ecx
shrl %ecx
cmpl %ecx, %eax
je 0x241600
movq -0x28(%rbp), %rdx
shlq $0x20, %rdx
movq -0x20(%rbp), %rax
subq -0x28(%rbp), %rax
orq %rax, %rdx
movq -0xe8(%rbp), %rax
movq -0xd0(%rbp), %rcx
imulq $0x18, -0x28(%rbp), %rsi
addq %rsi, %rcx
movl 0x14(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x241602
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x24157a
movq -0xe8(%rbp), %rdi
callq 0x2210
movq -0xd0(%rbp), %rdi
callq 0x2210
movq -0x48(%rbp), %rax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopl (%rax,%rax)