// File: /workspace/github_cpp_makefile_star2_O2/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 $0x68, %rsp
movq %rsi, 0x30(%rsp)
movq %rdi, %r12
leaq 0x28(%rsp), %r14
andq $0x0, (%r14)
xorl %edx, %edx
movq %rsp, %r15
movq $0x0, 0x10(%rsp)
xorl %ebp, %ebp
xorl %r8d, %r8d
xorl %edi, %edi
movq %r12, 0x38(%rsp)
movl %edx, %edx
cmpq %rdx, 0x18(%r12)
jbe 0x909d3
movq 0x10(%r12), %rax
movq 0x28(%r12), %rcx
movq %rdx, 0x50(%rsp)
movq (%rcx,%rdx,8), %rcx
movq %rcx, 0x60(%rsp)
shrq $0x20, %rcx
imulq $0x30, %rcx, %rcx
leaq (%rax,%rcx), %r9
addq %rcx, %rax
addq $0x28, %rax
movq %rax, 0x58(%rsp)
xorl %ebx, %ebx
pushq $0x1
popq %rax
movq %r9, 0x18(%rsp)
cmpl 0x60(%rsp), %eax
ja 0x909c7
movl %eax, 0x4(%rsp)
movl %eax, %eax
movl %ebx, %edx
movq %rax, 0x20(%rsp)
jne 0x90566
imulq $0x30, %rdx, %rax
movl 0x14(%r9,%rax), %esi
jmp 0x90583
imulq $0x30, %rax, %rax
imulq $0x30, %rdx, %rcx
movl 0x14(%r9,%rcx), %esi
cmpl %esi, 0x14(%r9,%rax)
jne 0x90583
movl 0x4(%rsp), %eax
jmp 0x909c0
movq %rdi, %r13
movq %rbp, 0x8(%rsp)
movq %r8, %rbp
movq %rdx, 0x48(%rsp)
imulq $0x30, %rdx, %rax
movq %rax, 0x40(%rsp)
movl 0x8(%r9,%rax), %edx
movq %r12, %rdi
movq %r14, %rcx
movq %r15, %r8
callq 0x8feef
incl %ebx
movl 0x4(%rsp), %eax
cmpl %ebx, %eax
jne 0x905d1
cmpl $0x0, (%rsp)
jne 0x905d1
movl %eax, %ebx
movq %rbp, %r8
movq 0x8(%rsp), %rbp
movq %r13, %rdi
jmp 0x909bb
movq 0x18(%rsp), %rax
movq 0x40(%rsp), %rcx
leaq (%rax,%rcx), %rbx
movq 0x48(%rsp), %r12
xorl %r14d, %r14d
xorl %r15d, %r15d
movq %rbp, %r8
movq 0x8(%rsp), %rbp
movq %r13, %rdi
movq 0x20(%rsp), %rcx
cmpq %rcx, %r12
jae 0x906c9
movb 0x28(%rbx), %al
testb %al, %al
js 0x906bd
cmpb $0x40, %al
jae 0x90669
cmpq %rbp, %r14
jne 0x9065b
movq %rbp, %rax
addq %rbp, %rbp
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rbp
imulq $0x30, %rbp, %rsi
movq %r8, %r13
movq %r15, 0x8(%rsp)
movq %r14, %r15
movq %rdi, %r14
movq 0x10(%rsp), %rdi
callq 0x2370
movq 0x20(%rsp), %rcx
movq %r14, %rdi
movq %r15, %r14
movq 0x8(%rsp), %r15
movq %r13, %r8
movq %rax, 0x10(%rsp)
imulq $0x30, %r14, %rax
incq %r14
addq 0x10(%rsp), %rax
jmp 0x906a3
cmpq %rdi, %r15
jne 0x90699
movq %rbp, %r13
leaq (%rdi,%rdi), %rbp
testq %rdi, %rdi
pushq $0x2
popq %rax
cmoveq %rax, %rbp
imulq $0x30, %rbp, %rsi
movq %r8, %rdi
callq 0x2370
movq 0x20(%rsp), %rcx
movq %rax, %r8
movq %rbp, %rdi
movq %r13, %rbp
imulq $0x30, %r15, %rax
incq %r15
addq %r8, %rax
movupd (%rbx), %xmm0
movupd 0x10(%rbx), %xmm1
movups 0x20(%rbx), %xmm2
movups %xmm2, 0x20(%rax)
movupd %xmm1, 0x10(%rax)
movupd %xmm0, (%rax)
incq %r12
addq $0x30, %rbx
jmp 0x905fa
xorl %ebx, %ebx
xorl %r12d, %r12d
movq 0x18(%rsp), %r9
movl (%rsp), %eax
cmpq %rax, %r12
jae 0x907d1
movq 0x28(%rsp), %rax
movb 0x28(%rax,%rbx), %al
testb %al, %al
js 0x907c5
cmpb $0x40, %al
jae 0x9074b
cmpq %rbp, %r14
jne 0x9073d
movq %rbp, %rax
addq %rbp, %rbp
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rbp
imulq $0x30, %rbp, %rsi
movq %r8, %r13
movq %r15, 0x8(%rsp)
movq %r14, %r15
movq %rdi, %r14
movq 0x10(%rsp), %rdi
callq 0x2370
movq %r14, %rdi
movq %r15, %r14
movq 0x8(%rsp), %r15
movq %r13, %r8
movq 0x18(%rsp), %r9
movq %rax, 0x10(%rsp)
imulq $0x30, %r14, %rax
incq %r14
addq 0x10(%rsp), %rax
jmp 0x90785
cmpq %rdi, %r15
jne 0x9077b
movq %rbp, %r13
leaq (%rdi,%rdi), %rbp
testq %rdi, %rdi
pushq $0x2
popq %rax
cmoveq %rax, %rbp
imulq $0x30, %rbp, %rsi
movq %r8, %rdi
callq 0x2370
movq %rax, %r8
movq %rbp, %rdi
movq %r13, %rbp
movq 0x18(%rsp), %r9
imulq $0x30, %r15, %rax
incq %r15
addq %r8, %rax
movq 0x28(%rsp), %rcx
movupd (%rcx,%rbx), %xmm0
movupd 0x10(%rcx,%rbx), %xmm1
movups 0x20(%rcx,%rbx), %xmm2
movups %xmm2, 0x20(%rax)
movupd %xmm1, 0x10(%rax)
movupd %xmm0, (%rax)
movl 0x14(%rcx,%rbx), %edx
movl %edx, 0x8(%rax)
movq 0xc(%rcx,%rbx), %rdx
movq %rdx, (%rax)
movl 0x8(%rcx,%rbx), %edx
movl %edx, 0x14(%rax)
movq (%rcx,%rbx), %rcx
movq %rcx, 0xc(%rax)
incq %r12
addq $0x30, %rbx
jmp 0x906d3
leaq (%r15,%r14), %rax
cmpq $0x2, %rax
jb 0x90805
movq 0x40(%rsp), %rdx
addq 0x58(%rsp), %rdx
movq 0x38(%rsp), %r12
movq 0x20(%rsp), %rax
movq 0x48(%rsp), %rcx
cmpq %rax, %rcx
jae 0x9081d
orb $-0x80, (%rdx)
incq %rcx
addq $0x30, %rdx
jmp 0x907f4
movl 0x4(%rsp), %eax
movl %eax, %ebx
movq 0x38(%rsp), %r12
leaq 0x28(%rsp), %r14
movq %rsp, %r15
jmp 0x909c0
pushq $0x28
popq %rax
xorl %ecx, %ecx
movl (%rsp), %edx
cmpq %rdx, %rcx
jae 0x9083c
movq 0x28(%rsp), %rdx
orb $-0x80, (%rdx,%rax)
incq %rcx
addq $0x30, %rax
jmp 0x90822
movq %rdi, %r13
movq %rbp, 0x8(%rsp)
movq %r8, %rbp
movq 0x10(%rsp), %rdi
movl %r14d, %esi
movq 0x30(%rsp), %rbx
movq %rbx, %rdx
callq 0x8ff85
movsd %xmm0, 0x20(%rsp)
movq %rbp, %rdi
movl %r15d, %esi
movq %rbx, %rdx
callq 0x8ff85
movsd 0x20(%rsp), %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
jae 0x90911
leaq 0x28(%rsp), %r14
movq %rbp, %r8
movq %r13, %rdi
movl %eax, %ebx
cmpq %rbx, %r15
jbe 0x909a0
movq (%r12), %rcx
movq 0x10(%r12), %rax
cmpq 0x8(%r12), %rcx
jne 0x908d6
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%r12)
imulq $0x30, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %r13, %rdi
movq %rbp, %r8
movq %rax, 0x10(%r12)
movq (%r12), %rcx
imulq $0x30, %rbx, %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r12)
imulq $0x30, %rcx, %rcx
movupd (%r8,%rdx), %xmm0
movupd 0x10(%r8,%rdx), %xmm1
movups 0x20(%r8,%rdx), %xmm2
movups %xmm2, 0x20(%rax,%rcx)
movupd %xmm1, 0x10(%rax,%rcx)
movupd %xmm0, (%rax,%rcx)
leal 0x1(%rbx), %eax
jmp 0x9088d
movq %rsp, %r15
movq %rbp, %r8
movq %r13, %rdi
movl %eax, %ebx
cmpq %rbx, %r14
jbe 0x909ab
movq (%r12), %rcx
movq 0x10(%r12), %rax
cmpq 0x8(%r12), %rcx
jne 0x90963
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%r12)
imulq $0x30, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %r13, %rdi
movq %rbp, %r8
movq %rax, 0x10(%r12)
movq (%r12), %rcx
imulq $0x30, %rbx, %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r12)
imulq $0x30, %rcx, %rcx
movq 0x10(%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)
leal 0x1(%rbx), %eax
jmp 0x9091a
movl 0x4(%rsp), %eax
movl %eax, %ebx
movq %rsp, %r15
jmp 0x909b6
movl 0x4(%rsp), %eax
movl %eax, %ebx
leaq 0x28(%rsp), %r14
movq 0x8(%rsp), %rbp
movq 0x18(%rsp), %r9
incl %eax
jmp 0x90542
movq 0x50(%rsp), %rdx
incl %edx
jmp 0x904fb
movq %r8, %rbx
movq 0x10(%rsp), %rdi
callq 0x2220
movq %rbx, %rdi
callq 0x2220
xorl %eax, %eax
xorl %ecx, %ecx
movl %eax, %eax
movl %ecx, %edx
cmpq %rax, (%r12)
jbe 0x90a2c
movq 0x10(%r12), %rsi
imulq $0x30, %rax, %rdi
cmpb $0x0, 0x28(%rsi,%rdi)
js 0x90a28
addq %rsi, %rdi
imulq $0x30, %rdx, %rdx
movups (%rdi), %xmm0
movups 0x10(%rdi), %xmm1
movups 0x20(%rdi), %xmm2
movups %xmm2, 0x20(%rsi,%rdx)
movups %xmm1, 0x10(%rsi,%rdx)
movups %xmm0, (%rsi,%rdx)
incl %ecx
incl %eax
jmp 0x909ec
movq %rdx, (%r12)
imulq $0x30, %rdx, %rbx
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0x90ae1
movq 0x10(%r12), %rax
cmpb $0x0, 0x28(%rax,%r14)
js 0x90ad8
movq (%r12), %rcx
cmpq 0x8(%r12), %rcx
jne 0x90a84
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%r12)
imulq $0x30, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r12)
imulq $0x30, %rcx, %rcx
movups (%rax,%r14), %xmm0
movups 0x10(%rax,%r14), %xmm1
movups 0x20(%rax,%r14), %xmm2
movups %xmm2, 0x20(%rax,%rcx)
movups %xmm1, 0x10(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
movq 0x10(%r12), %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), %rdx
movq %rdx, 0xc(%rax,%rcx)
addq $0x30, %r14
jmp 0x90a37
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rax
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl 0x14(%rax), %esi
movq %r12, %rdi
callq 0x88a31
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq