// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %r12
movq 0x18(%rsi), %rax
testq %rax, %rax
je 0x14366b
xorl %edx, %edx
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movl $0x0, 0x4(%rsp)
movq %r12, 0x8(%rsp)
movq %rsi, 0x20(%rsp)
movq 0x28(%rsi), %rcx
movq (%rcx,%rdx,8), %r13
testl %r13d, %r13d
je 0x143638
movq %rdx, 0x28(%rsp)
movq %r13, %rax
shrq $0x20, %rax
leaq (%rax,%rax,2), %r14
shlq $0x4, %r14
addq 0x10(%rsi), %r14
xorl %eax, %eax
movl $0x1, %ebp
movl %ebp, %ecx
cmpl %r13d, %ebp
jne 0x143416
movl %eax, %edi
jmp 0x143438
leaq (%rcx,%rcx,2), %rdx
shlq $0x4, %rdx
movl 0x14(%r14,%rdx), %edx
movl %eax, %edi
leaq (%rdi,%rdi,2), %rsi
shlq $0x4, %rsi
cmpl 0x14(%r14,%rsi), %edx
je 0x14361f
leaq (%rdi,%rdi,2), %rdx
shlq $0x4, %rdx
leaq (%r14,%rdx), %rsi
cmpl %ebp, %eax
jae 0x14346e
addq %r14, %rdx
subq %rdi, %rcx
movsd 0x20(%rdx), %xmm0
ucomisd 0x20(%rsi), %xmm0
movq %rdx, %rax
ja 0x143460
movq %rsi, %rax
addq $0x30, %rdx
movq %rax, %rsi
decq %rcx
jne 0x14344e
jmp 0x143471
movq %rsi, %rax
movzbl 0x28(%rax), %ebx
movl %ebx, %ecx
andb $0x3f, %cl
cmpb $0x2, %cl
jne 0x14361d
shrl $0x6, %ebx
movl 0x14(%rax), %r15d
andl $0x1, %ebx
je 0x1434ad
movq 0x20(%r12), %rdx
movl (%rdx,%r15,8), %r9d
andl %r10d, %r9d
movl %r9d, %ecx
subl 0x10(%rax), %ecx
movl 0xc(%rax), %r8d
notl %r8d
addl %r9d, %r8d
jmp 0x1434c3
movl 0xc(%rax), %ecx
movl 0x10(%rax), %r8d
decl %r8d
movq 0x20(%r12), %rdx
movl (%rdx,%r15,8), %r9d
andl %r10d, %r9d
movl 0x8(%rax), %r12d
movl (%rax), %edi
movl 0x4(%rax), %eax
decl %eax
movl %eax, %esi
movl (%rdx,%r12,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
movl %r8d, %r8d
movl %r9d, %r9d
leaq 0x10(%rsp), %rax
pushq %rax
leaq 0x20(%rsp), %rax
pushq %rax
leaq 0x40(%rsp), %rax
pushq %rax
leaq 0x50(%rsp), %rax
pushq %rax
callq 0x10a6e3
addq $0x20, %rsp
testb %bl, %bl
je 0x143530
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rcx
movl (%rcx,%r15,8), %eax
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andl %edi, %eax
movl 0x10(%rsp), %r9d
notl %r9d
addl %eax, %r9d
movl %eax, %r10d
subl 0x18(%rsp), %r10d
jmp 0x143551
movl 0x18(%rsp), %r9d
movl 0x10(%rsp), %r10d
incl %r10d
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rcx
movl (%rcx,%r15,8), %eax
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andl %edi, %eax
movl 0x30(%rsp), %edx
incl %edx
movl 0x38(%rsp), %esi
movl (%rcx,%r12,8), %ecx
andl %edi, %ecx
movl %r12d, %edi
movl %r15d, %r8d
leaq 0x40(%rsp), %r11
pushq %r11
pushq %rbx
pushq %rax
pushq %r10
callq 0x14327e
addq $0x20, %rsp
testl %eax, %eax
js 0x1435ce
movq 0x8(%rsp), %r12
movl 0x4(%r12), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl (%r12), %ecx
jne 0x1435dd
leal (%rcx,%rcx), %eax
testl %ecx, %ecx
movl $0x10, %ecx
cmovel %ecx, %eax
movl %eax, (%r12)
movq 0x8(%r12), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
callq 0x2370
movq %rax, 0x8(%r12)
movl 0x4(%r12), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jmp 0x1435e2
movl %ebp, %eax
movq 0x8(%rsp), %r12
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
jmp 0x14361f
movq 0x8(%r12), %rax
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
leal 0x1(%rdx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %esi, %edx
movl %edx, 0x4(%r12)
movl %ecx, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x50(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movupd 0x40(%rsp), %xmm0
movupd %xmm0, (%rax,%rcx,8)
incl 0x4(%rsp)
movl %ebp, %eax
incl %ebp
cmpl %r13d, %ebp
jbe 0x14340b
movq 0x20(%rsp), %rsi
movq 0x18(%rsi), %rax
movq 0x28(%rsp), %rdx
incl %edx
cmpq %rdx, %rax
ja 0x1433db
cmpl $0x0, 0x4(%rsp)
je 0x14366b
movq 0x28(%r12), %rdi
callq 0x2220
movq $0x0, 0x28(%r12)
andb $0x7f, 0x7(%r12)
movq %r12, %rdi
callq 0xa0a7d
leaq 0x1520e6(%rip), %rax    # 0x295758
movl 0x110(%rax), %esi
movq %r12, %rdi
callq 0xa9d09
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq