// File: chhylp123[P]hifiasm/hic.cpp
// Function: update_ug_by_trans(asg_t*, kv_u_trans_t*)
void update_ug_by_trans(asg_t *sg, kv_u_trans_t *ta)
{
    u_trans_t *a = NULL, *p = NULL;
    uint32_t i, k, st, occ, n, m;
    uint32_t qn, tn, qs, qe, ts, te, rev;
    asg_arc_t t, *e = NULL;
    long long r_qs, r_qe, r_ts, r_te;
    int r;

    for (k = occ = 0; k < ta->idx.n; k++)
    {
        a = u_trans_a(*ta, k);
        n = u_trans_n(*ta, k);
        for (st = 0, i = 1; i <= n; ++i)
        {
            if (i == n || a[i].tn != a[st].tn)
            {
                for (m = st, p = &(a[st]); m < i; m++)
                {
                    if(a[m].nw > p->nw) p = &(a[m]);
                }

                if(p->f == RC_2)///dis-connected
                {
                    rev = p->rev;
                    qn = p->qn; 
                    qs = p->qs; 
                    qe = p->qe - 1;
                    if(rev)
                    {
                        tn = p->tn;
                        ts = sg->seq[tn].len - (p->te - 1) - 1;
                        te = sg->seq[tn].len - p->ts - 1;
                    }
                    else
                    {
                        tn = p->tn; 
                        ts = p->ts; 
                        te = p->te - 1;
                    }

                    classify_hap_overlap(qs, qe, sg->seq[qn].len, ts, te, sg->seq[tn].len, 
                                                                            &r_qs, &r_qe, &r_ts, &r_te);
                    
                    qs = r_qs; qe = r_qe + 1;
                    if(rev)
                    {
                        ts = sg->seq[tn].len - r_te - 1;
                        te = sg->seq[tn].len - r_ts - 1 + 1;
                    }
                    else
                    {
                        ts = r_ts; te = r_te + 1;
                    }

                    r = get_trans_ug_arch(qn, qs, qe, sg->seq[qn].len, 
                                        tn, ts, te, sg->seq[tn].len, rev, &t);
                    if(r >= 0)
                    {
                        e = asg_arc_pushp(sg);
                        *e = t;
                        occ++;
                    }
                }
                st = i;
            }
        }
    }

    if(occ > 0)
    {
        free(sg->idx);
        sg->idx = 0;
        sg->is_srt = 0;
        asg_cleanup(sg);
    }
    asg_arc_del_trans(sg, asm_opt.gap_fuzz);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0xc8, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x80(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x1ceeeb
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x30(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x30(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x3c(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x1, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x3c(%rbp), %eax
ja 0x1ceedb
movl -0x2c(%rbp), %eax
cmpl -0x3c(%rbp), %eax
je 0x1cec0d
movq -0x20(%rbp), %rax
movl -0x2c(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movq -0x20(%rbp), %rcx
movl -0x34(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x14(%rcx), %eax
je 0x1ceecb
movl -0x34(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movl -0x34(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x1cec6a
movq -0x20(%rbp), %rax
movl -0x40(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
movq -0x28(%rbp), %rax
ucomisd 0x20(%rax), %xmm0
jbe 0x1cec5d
movq -0x20(%rbp), %rax
movl -0x40(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
jmp 0x1cec5f
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x1cec25
movq -0x28(%rbp), %rax
movb 0x28(%rax), %al
andb $0x3f, %al
movzbl %al, %eax
cmpl $0x2, %eax
jne 0x1ceec5
movq -0x28(%rbp), %rax
movb 0x28(%rax), %al
shrb $0x6, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x5c(%rbp)
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
subl $0x1, %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x1ced08
movq -0x28(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x48(%rbp), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x28(%rbp), %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
subl %ecx, %eax
subl $0x1, %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x48(%rbp), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x28(%rbp), %rcx
subl 0xc(%rcx), %eax
subl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x1ced29
movq -0x28(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x28(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x54(%rbp)
movq -0x28(%rbp), %rax
movl 0x10(%rax), %eax
subl $0x1, %eax
movl %eax, -0x58(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, %edi
movl -0x50(%rbp), %eax
movl %eax, %esi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x44(%rbp), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edx
movl -0x54(%rbp), %eax
movl %eax, %ecx
movl -0x58(%rbp), %eax
movl %eax, %r8d
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x48(%rbp), %r9d
movl (%rax,%r9,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %r9d
leaq -0x88(%rbp), %rbx
leaq -0x90(%rbp), %r11
leaq -0x98(%rbp), %r10
leaq -0xa0(%rbp), %rax
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x170800
movq -0x88(%rbp), %rax
movl %eax, -0x4c(%rbp)
movq -0x90(%rbp), %rax
addq $0x1, %rax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x1cee0d
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x48(%rbp), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
subq -0xa0(%rbp), %rax
subq $0x1, %rax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x48(%rbp), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
subq -0x98(%rbp), %rax
subq $0x1, %rax
addq $0x1, %rax
movl %eax, -0x58(%rbp)
jmp 0x1cee25
movq -0x98(%rbp), %rax
movl %eax, -0x54(%rbp)
movq -0xa0(%rbp), %rax
addq $0x1, %rax
movl %eax, -0x58(%rbp)
movl -0x44(%rbp), %edi
movl -0x4c(%rbp), %esi
movl -0x50(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x44(%rbp), %ecx
movl (%rax,%rcx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl -0x48(%rbp), %r8d
movl -0x54(%rbp), %r9d
movl -0x58(%rbp), %ebx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x48(%rbp), %r10d
movl (%rax,%r10,8), %r11d
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movl -0x5c(%rbp), %r10d
leaq -0x78(%rbp), %rax
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x1ce710
movl %eax, -0xa4(%rbp)
cmpl $0x0, -0xa4(%rbp)
jl 0x1ceec3
movq -0x10(%rbp), %rdi
callq 0x1cef50
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq -0x78(%rbp), %rcx
movq %rcx, (%rax)
movq -0x70(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x68(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1ceec5
movl -0x2c(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x1ceecd
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1cebd1
jmp 0x1ceedd
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x1ceb7a
cmpl $0x0, -0x38(%rbp)
jbe 0x1cef26
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x2210
movq -0x10(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rdi
callq 0xcdd10
movq -0x10(%rbp), %rdi
leaq 0x1f58c7(%rip), %rax    # 0x3c47f8
movl 0x110(%rax), %esi
callq 0xda630
addq $0xc8, %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)