// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: kt_u_trans_t_symm(kv_u_trans_t*, ma_ug_t*)
void kt_u_trans_t_symm(kv_u_trans_t *ta, ma_ug_t *ug)
{
    u_trans_t *a = NULL, *r_a = NULL, *p = NULL;
    uint32_t k, n, r_n, st, i, m;
    double w0, w1;
    kvec_t(u_trans_t) e0; kv_init(e0);
    kvec_t(u_trans_t) e1; kv_init(e1);
    for (k = 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)
            {
                get_u_trans_spec(ta, a[st].tn, a[st].qn, &r_a, &r_n);
                if(i == st + 1 && r_n == 0) {///should be always here
                    st = i;
                    continue;
                } 

                e0.n = e1.n = 0;
                for (m = st; m < i; m++) {
                    if(a[m].del) continue;
                    if(a[m].rev) {
                        kv_push(u_trans_t, e1, a[m]);
                    } else {
                        kv_push(u_trans_t, e0, a[m]);
                    }
                }
                
                for (m = 0; m < r_n; m++) {
                    if(r_a[m].del) continue;
                    if(r_a[m].rev) {
                        kv_pushp(u_trans_t, e1, &p);
                    } else {
                        kv_pushp(u_trans_t, e0, &p);
                    }
                    (*p) = r_a[m];
                    p->qn = r_a[m].tn; p->qs = r_a[m].ts; p->qe = r_a[m].te;
                    p->tn = r_a[m].qn; p->ts = r_a[m].qs; p->te = r_a[m].qe;
                }
                

                if(e0.n + e1.n > 1) {
                    ///must be here
                    for (m = st; m < i; m++) a[m].del = 1;
                    for (m = 0; m < r_n; m++) r_a[m].del = 1;

                    w0 = merge_u_trans(e0.a, e0.n, ug);
                    w1 = merge_u_trans(e1.a, e1.n, ug);
                    if(w0 >= w1)
                    {
                        for (m = 0; m < e0.n; m++)
                        {
                            kv_push(u_trans_t, *ta, e0.a[m]);
                        }
                    }
                    else
                    {
                        for (m = 0; m < e1.n; m++)
                        {
                            kv_push(u_trans_t, *ta, e1.a[m]);
                        }
                    }
                }
                st = i;
            }
        }

    }
    kv_destroy(e0);
    kv_destroy(e1);
    for (i = m = 0; i < ta->n; ++i)
    {
        if(ta->a[i].del) continue;
        ta->a[m] = ta->a[i];
        m++;
    }
    ta->n = m;
    n = ta->n;
    for (i = 0; i < n; ++i)
    {
        if(ta->a[i].del) continue;
        kv_pushp(u_trans_t, *ta, &p);
        (*p) = ta->a[i];
        p->qn = ta->a[i].tn; p->qs = ta->a[i].ts; p->qe = ta->a[i].te;
        p->tn = ta->a[i].qn; p->ts = ta->a[i].qs; p->te = ta->a[i].qe;
    }
    kt_u_trans_t_idx(ta, ug->g->n_seq);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, 0x50(%rsp)
movq %rdi, %rbp
movq $0x0, 0x8(%rsp)
movq 0x18(%rdi), %rax
xorl %ecx, %ecx
testq %rax, %rax
je 0xcc71d
leaq 0x8(%rsp), %r13
movq %rsp, %r8
xorl %r12d, %r12d
xorl %r10d, %r10d
movq $0x0, 0x38(%rsp)
movq $0x0, 0x20(%rsp)
movq %rbp, 0x58(%rsp)
movq %rcx, 0x40(%rsp)
movq 0x28(%rbp), %rcx
movq 0x40(%rsp), %rdx
movq (%rcx,%rdx,8), %r15
movq 0x40(%rsp), %rcx
testl %r15d, %r15d
je 0xcc710
movq 0x10(%rbp), %rax
movq %r15, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
leaq (%rax,%rcx), %rdx
movq %rdx, 0x48(%rsp)
addq %rcx, %rax
addq $0x28, %rax
movq %rax, 0x68(%rsp)
xorl %r9d, %r9d
movl $0x1, %edi
movq %r15, 0x28(%rsp)
movq %r10, 0x18(%rsp)
movl %edi, %r11d
movl %r9d, %r10d
cmpl %r15d, %edi
jne 0xcc20d
leaq (%r10,%r10,2), %rax
shlq $0x4, %rax
movq 0x48(%rsp), %rdx
movl 0x14(%rdx,%rax), %esi
jmp 0xcc236
leaq (%r11,%r11,2), %rax
shlq $0x4, %rax
leaq (%r10,%r10,2), %rcx
shlq $0x4, %rcx
movq 0x48(%rsp), %rdx
movl 0x14(%rdx,%rcx), %esi
cmpl %esi, 0x14(%rdx,%rax)
jne 0xcc236
movq 0x18(%rsp), %r10
jmp 0xcc6fc
movq %r11, 0x10(%rsp)
movl %edi, %ebx
movq %r9, %r14
movq %r10, 0x30(%rsp)
leaq (%r10,%r10,2), %rax
shlq $0x4, %rax
movq %rax, 0x60(%rsp)
movl 0x8(%rdx,%rax), %edx
movq %rbp, %rdi
movq %r13, %rcx
movq %r8, %r13
callq 0xcba40
leal 0x1(%r14), %ecx
xorl %ebx, %ecx
movl (%rsp), %eax
orl %eax, %ecx
jne 0xcc288
movl %ebx, %r9d
movq 0x18(%rsp), %r10
movl %ebx, %edi
movq %r13, %r8
leaq 0x8(%rsp), %r13
jmp 0xcc6fc
movl %ebx, 0x4(%rsp)
movq %r14, 0x70(%rsp)
cmpl %ebx, %r14d
jae 0xcc39b
movq 0x48(%rsp), %rax
movq 0x60(%rsp), %rcx
leaq (%rax,%rcx), %rbx
movq 0x10(%rsp), %rbp
subq 0x30(%rsp), %rbp
xorl %edi, %edi
xorl %r15d, %r15d
movq 0x18(%rsp), %r10
movq 0x20(%rsp), %r14
movb 0x28(%rbx), %al
testb %al, %al
js 0xcc389
cmpb $0x40, %al
jae 0xcc32a
cmpq 0x38(%rsp), %r15
jne 0xcc31a
leaq (%r15,%r15), %rcx
testq %r15, %r15
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, %rax
movq %rcx, 0x38(%rsp)
shlq $0x4, %rax
leaq (%rax,%rax,2), %rsi
movq %r15, %r13
movq %rdi, %r15
movq %r14, %rdi
movq %r12, %r14
movq %r10, %r12
callq 0x2370
movq %r15, %rdi
movq %r13, %r15
movq %r12, %r10
movq %r14, %r12
movq %rax, %r14
leaq (%r15,%r15,2), %rax
incq %r15
shlq $0x4, %rax
addq %r14, %rax
jmp 0xcc36f
cmpq %r12, %rdi
jne 0xcc361
leaq (%rdi,%rdi), %r12
testq %rdi, %rdi
movl $0x2, %eax
cmoveq %rax, %r12
movq %r12, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rsi
movq %r14, %r13
movq %rdi, %r14
movq %r10, %rdi
callq 0x2370
movq %r14, %rdi
movq %r13, %r14
movq %rax, %r10
leaq (%rdi,%rdi,2), %rax
incq %rdi
shlq $0x4, %rax
addq %r10, %rax
movupd (%rbx), %xmm0
movupd 0x10(%rbx), %xmm1
movups 0x20(%rbx), %xmm2
movups %xmm2, 0x20(%rax)
movupd %xmm1, 0x10(%rax)
movupd %xmm0, (%rax)
addq $0x30, %rbx
decq %rbp
jne 0xcc2c1
movl (%rsp), %eax
jmp 0xcc3aa
xorl %r15d, %r15d
xorl %edi, %edi
movq 0x18(%rsp), %r10
movq 0x20(%rsp), %r14
testl %eax, %eax
je 0xcc4c2
movq 0x8(%rsp), %rcx
xorl %ebp, %ebp
xorl %ebx, %ebx
movb 0x28(%rcx,%rbp), %dl
testb %dl, %dl
js 0xcc4ae
cmpb $0x40, %dl
jae 0xcc426
cmpq 0x38(%rsp), %r15
jne 0xcc416
leaq (%r15,%r15), %rcx
testq %r15, %r15
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, %rax
movq %rcx, 0x38(%rsp)
shlq $0x4, %rax
leaq (%rax,%rax,2), %rsi
movq %r15, %r13
movq %rdi, %r15
movq %r14, %rdi
movq %r12, %r14
movq %r10, %r12
callq 0x2370
movq %r15, %rdi
movq %r13, %r15
movq %r12, %r10
movq %r14, %r12
movq %rax, %r14
leaq (%r15,%r15,2), %rax
incq %r15
shlq $0x4, %rax
addq %r14, %rax
jmp 0xcc46b
cmpq %r12, %rdi
jne 0xcc45d
leaq (%rdi,%rdi), %r12
testq %rdi, %rdi
movl $0x2, %eax
cmoveq %rax, %r12
movq %r12, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rsi
movq %r14, %r13
movq %rdi, %r14
movq %r10, %rdi
callq 0x2370
movq %r14, %rdi
movq %r13, %r14
movq %rax, %r10
leaq (%rdi,%rdi,2), %rax
incq %rdi
shlq $0x4, %rax
addq %r10, %rax
movq 0x8(%rsp), %rcx
movupd (%rcx,%rbp), %xmm0
movupd 0x10(%rcx,%rbp), %xmm1
movups 0x20(%rcx,%rbp), %xmm2
movups %xmm2, 0x20(%rax)
movupd %xmm1, 0x10(%rax)
movupd %xmm0, (%rax)
movl 0x14(%rcx,%rbp), %edx
movl %edx, 0x8(%rax)
movq 0xc(%rcx,%rbp), %rdx
movq %rdx, (%rax)
movl 0x8(%rcx,%rbp), %edx
movl %edx, 0x14(%rax)
movq (%rcx,%rbp), %rdx
movq %rdx, 0xc(%rax)
movl (%rsp), %eax
incq %rbx
movl %eax, %edx
addq $0x30, %rbp
cmpq %rdx, %rbx
jb 0xcc3bb
jmp 0xcc4c4
xorl %eax, %eax
leaq (%rdi,%r15), %rcx
cmpq $0x2, %rcx
movq %r14, 0x20(%rsp)
jb 0xcc61a
movq 0x70(%rsp), %rcx
cmpl 0x4(%rsp), %ecx
movq 0x58(%rsp), %rbp
jae 0xcc50a
movq 0x60(%rsp), %rcx
addq 0x68(%rsp), %rcx
movq 0x10(%rsp), %rax
subq 0x30(%rsp), %rax
orb $-0x80, (%rcx)
addq $0x30, %rcx
decq %rax
jne 0xcc4fb
movl (%rsp), %eax
movq %rdi, 0x18(%rsp)
movq %r12, 0x10(%rsp)
movq %r10, %r12
testl %eax, %eax
je 0xcc53a
movl $0x28, %eax
xorl %ecx, %ecx
movq 0x8(%rsp), %rdx
orb $-0x80, (%rdx,%rax)
incq %rcx
movl (%rsp), %edx
addq $0x30, %rax
cmpq %rdx, %rcx
jb 0xcc522
movq %r14, %rdi
movl %r15d, %esi
movq 0x50(%rsp), %rbx
movq %rbx, %rdx
callq 0xcbaf4
movsd %xmm0, 0x30(%rsp)
movq %r12, %rdi
movq 0x18(%rsp), %r13
movl %r13d, %esi
movq %rbx, %rdx
callq 0xcbaf4
movsd 0x30(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0xcc633
testq %r13, %r13
je 0xcc6e0
movl $0x1, %ebx
xorl %r15d, %r15d
movq %r12, %r10
movq (%rbp), %rcx
movq 0x10(%rbp), %rax
cmpq 0x8(%rbp), %rcx
jne 0xcc5cc
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%rbp)
shlq $0x4, %rdx
leaq (%rdx,%rdx,2), %rsi
movq %rax, %rdi
callq 0x2370
movq 0x18(%rsp), %r13
movq %r12, %r10
movq %rax, 0x10(%rbp)
movq (%rbp), %rcx
leaq (%r15,%r15,2), %rdx
shlq $0x4, %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbp)
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movupd (%r10,%rdx), %xmm0
movupd 0x10(%r10,%rdx), %xmm1
movups 0x20(%r10,%rdx), %xmm2
movups %xmm2, 0x20(%rax,%rcx)
movupd %xmm1, 0x10(%rax,%rcx)
movupd %xmm0, (%rax,%rcx)
movl %ebx, %r15d
incl %ebx
cmpq %r15, %r13
ja 0xcc58a
jmp 0xcc6cf
movl 0x4(%rsp), %edi
movl %edi, %r9d
movq 0x58(%rsp), %rbp
leaq 0x8(%rsp), %r13
movq %rsp, %r8
jmp 0xcc6f7
testq %r15, %r15
je 0xcc6e0
movl $0x1, %ebx
xorl %r14d, %r14d
movq %r12, %r10
movq (%rbp), %rcx
movq 0x10(%rbp), %rax
cmpq 0x8(%rbp), %rcx
jne 0xcc684
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%rbp)
shlq $0x4, %rdx
leaq (%rdx,%rdx,2), %rsi
movq %rax, %rdi
callq 0x2370
movq %r12, %r10
movq %rax, 0x10(%rbp)
movq (%rbp), %rcx
leaq (%r14,%r14,2), %rdx
shlq $0x4, %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbp)
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movq 0x20(%rsp), %rsi
movupd (%rsi,%rdx), %xmm0
movupd 0x10(%rsi,%rdx), %xmm1
movups 0x20(%rsi,%rdx), %xmm2
movups %xmm2, 0x20(%rax,%rcx)
movupd %xmm1, 0x10(%rax,%rcx)
movupd %xmm0, (%rax,%rcx)
movl %ebx, %r14d
incl %ebx
cmpq %r14, %r15
ja 0xcc647
movl 0x4(%rsp), %edi
movl %edi, %r9d
leaq 0x8(%rsp), %r13
movq %rsp, %r8
jmp 0xcc6f2
movl 0x4(%rsp), %edi
movl %edi, %r9d
leaq 0x8(%rsp), %r13
movq %rsp, %r8
movq %r12, %r10
movq 0x10(%rsp), %r12
movq 0x28(%rsp), %r15
incl %edi
cmpl %r15d, %edi
jbe 0xcc1ea
movq 0x18(%rbp), %rax
movq 0x40(%rsp), %rcx
incl %ecx
cmpq %rcx, %rax
ja 0xcc195
jmp 0xcc729
movq $0x0, 0x20(%rsp)
xorl %r10d, %r10d
movq %r10, %rbx
movq 0x20(%rsp), %rdi
callq 0x2220
movq %rbx, %rdi
callq 0x2220
movq (%rbp), %rdx
testq %rdx, %rdx
je 0xcc86b
xorl %esi, %esi
movl $0x1, %eax
xorl %ecx, %ecx
movq 0x10(%rbp), %rdi
leaq (%rsi,%rsi,2), %rsi
shlq $0x4, %rsi
cmpb $0x0, 0x28(%rdi,%rsi)
js 0xcc797
addq %rdi, %rsi
movl %ecx, %edx
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
movupd (%rsi), %xmm0
movupd 0x10(%rsi), %xmm1
movups 0x20(%rsi), %xmm2
movups %xmm2, 0x20(%rdi,%rdx)
movupd %xmm1, 0x10(%rdi,%rdx)
movupd %xmm0, (%rdi,%rdx)
incl %ecx
movq (%rbp), %rdx
movl %eax, %esi
incl %eax
cmpq %rsi, %rdx
ja 0xcc754
movl %ecx, %edx
movq %rdx, (%rbp)
testl %ecx, %ecx
je 0xcc86b
movq 0x10(%rbp), %rax
shlq $0x4, %rdx
leaq (%rdx,%rdx,2), %rbx
xorl %r14d, %r14d
movl $0x2, %r15d
cmpb $0x0, 0x28(%rax,%r14)
js 0xcc85e
movq (%rbp), %rcx
cmpq 0x8(%rbp), %rcx
jne 0xcc800
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
cmoveq %r15, %rdx
movq %rdx, 0x8(%rbp)
shlq $0x4, %rdx
leaq (%rdx,%rdx,2), %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbp)
movq (%rbp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbp)
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movupd (%rax,%r14), %xmm0
movupd 0x10(%rax,%r14), %xmm1
movups 0x20(%rax,%r14), %xmm2
movups %xmm2, 0x20(%rax,%rcx)
movupd %xmm1, 0x10(%rax,%rcx)
movupd %xmm0, (%rax,%rcx)
movq 0x10(%rbp), %rdx
movl 0x14(%rdx,%r14), %esi
movl %esi, 0x8(%rax,%rcx)
movq 0xc(%rdx,%r14), %rsi
movq %rsi, (%rax,%rcx)
movl 0x8(%rdx,%r14), %esi
movl %esi, 0x14(%rax,%rcx)
movq (%rdx,%r14), %rsi
movq %rsi, 0xc(%rax,%rcx)
movq %rdx, %rax
addq $0x30, %r14
cmpq %r14, %rbx
jne 0xcc7c3
movq 0x50(%rsp), %rax
movq 0x18(%rax), %rax
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl 0x14(%rax), %esi
movq %rbp, %rdi
callq 0xc4edd
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq