// File: /workspace/github_cpp_makefile_star2_O2/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
movl $0x0, 0x4(%rsp)
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movq %rdi, 0x8(%rsp)
movq %rsi, 0x20(%rsp)
movl %ecx, %ecx
cmpq %rcx, 0x18(%rsi)
jbe 0xfbf3a
movq 0x28(%rsi), %rax
movq %rcx, 0x28(%rsp)
movq (%rax,%rcx,8), %r14
movq %r14, %rax
shrq $0x20, %rax
imulq $0x30, %rax, %rbp
addq 0x10(%rsi), %rbp
xorl %eax, %eax
pushq $0x1
popq %r13
cmpl %r14d, %r13d
ja 0xfbf29
movl %eax, %ecx
movl %r13d, %edx
je 0xfbdaa
imulq $0x30, %rdx, %rsi
movl 0x14(%rbp,%rsi), %esi
imulq $0x30, %rcx, %rdi
cmpl 0x14(%rbp,%rdi), %esi
je 0xfbf21
imulq $0x30, %rcx, %rsi
leaq (%rsi,%rbp), %rax
addq %rbp, %rsi
cmpq %rdx, %rcx
jae 0xfbdd8
movsd 0x20(%rsi), %xmm0
ucomisd 0x20(%rax), %xmm0
movq %rsi, %rdi
ja 0xfbdcc
movq %rax, %rdi
incq %rcx
addq $0x30, %rsi
movq %rdi, %rax
jmp 0xfbdb5
movzbl 0x28(%rax), %ebx
movl %ebx, %ecx
andb $0x3f, %cl
cmpb $0x2, %cl
jne 0xfbe10
shrl $0x6, %ebx
movl 0x14(%rax), %r15d
andl $0x1, %ebx
je 0xfbe18
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 0xfbe2e
movl %r13d, %eax
jmp 0xfbf21
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 0xc7ff2
addq $0x20, %rsp
testb %bl, %bl
je 0xfbe9b
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 0xfbebc
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 0xfbbfa
addq $0x20, %rsp
testl %eax, %eax
js 0xfbf13
movq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0xfbf83
movupd 0x40(%rsp), %xmm0
movupd %xmm0, (%rax)
movq 0x50(%rsp), %rcx
movq %rcx, 0x10(%rax)
incl 0x4(%rsp)
movl %r13d, %eax
jmp 0xfbf1b
movl %r13d, %eax
movq 0x8(%rsp), %r12
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
incl %r13d
jmp 0xfbd84
movq 0x28(%rsp), %rcx
incl %ecx
movq 0x20(%rsp), %rsi
jmp 0xfbd56
cmpl $0x0, 0x4(%rsp)
je 0xfbf5f
movq 0x28(%r12), %rdi
callq 0x2220
andq $0x0, 0x28(%r12)
andb $0x7f, 0x7(%r12)
movq %r12, %rdi
callq 0x694eb
leaq 0x1577f2(%rip), %rax    # 0x253758
movl 0x110(%rax), %esi
movq %r12, %rdi
callq 0x701c4
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq