// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: append_utg(ma_ug_t*, ma_ug_t*, trans_chain*)
void append_utg(ma_ug_t* ptg, ma_ug_t* atg, trans_chain* t_ch)
{
    uint64_t num_nodes = 0;
    asg_t* nsg = atg->g;
    uint32_t v, n_vtx = nsg->n_seq;
    ma_utg_t *p;
    for (v = 0; v < n_vtx; ++v) 
    {
        if(nsg->seq[v].del || atg->u.a[v].m == 0) continue;
        num_nodes++;
    }

    if(num_nodes == 0) return;

    ptg->u.n = ptg->u.n + num_nodes;
    if(ptg->u.n > ptg->u.m)
    {
        ptg->u.m = ptg->u.n;
        ptg->u.a = (ma_utg_t*)realloc(ptg->u.a, ptg->u.m*sizeof(ma_utg_t));     
    }
    ptg->u.n = ptg->u.n - num_nodes;

    for (v = 0; v < atg->g->n_seq; ++v) 
    {
        if(atg->g->seq[v].del || atg->u.a[v].m == 0) continue;
        if(t_ch) reset_trans_chain(t_ch, &(atg->u.a[v]));

        p = &(ptg->u.a[ptg->u.n]);
        p->len = atg->u.a[v].len;
        p->circ = atg->u.a[v].circ;
        p->start = atg->u.a[v].start;
        p->end = atg->u.a[v].end;
        p->m = atg->u.a[v].m; atg->u.a[v].m = 0;
        p->n = atg->u.a[v].n; atg->u.a[v].n = 0;
        p->a = atg->u.a[v].a; atg->u.a[v].a = 0;
        p->s = atg->u.a[v].s; atg->u.a[v].s = 0;
        asg_seq_set(ptg->g, ptg->u.n, p->len, 0);
        ptg->u.n++;
    }

    if(ptg->g->idx != 0) free(ptg->g->idx); 
    ptg->g->idx = 0;
    asg_cleanup(ptg->g);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq 0x18(%rsi), %rax
movl 0x14(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
pushq $0xc
popq %rdx
xorl %esi, %esi
xorl %r12d, %r12d
cmpq %rsi, %rcx
je 0xb36de
movq 0x20(%rax), %rdi
cmpl $0x0, (%rdi,%rsi,8)
js 0xb36d5
movq 0x10(%r15), %rdi
cmpl $0x1, (%rdi,%rdx)
sbbq $-0x1, %r12
incq %rsi
addq $0x28, %rdx
jmp 0xb36ba
testq %r12, %r12
je 0xb3814
movq (%rbx), %rax
addq %r12, %rax
movq %rax, (%rbx)
cmpq 0x8(%rbx), %rax
jbe 0xb370e
movq %rax, 0x8(%rbx)
movq 0x10(%rbx), %rdi
imulq $0x28, %rax, %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
subq %r12, %rax
movq %rax, (%rbx)
xorl %r12d, %r12d
movl $0x80000000, %r13d      # imm = 0x80000000
xorl %ebp, %ebp
movq 0x18(%r15), %rcx
movl 0x14(%rcx), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpq %rdx, %rbp
jae 0xb37eb
movq 0x20(%rcx), %rcx
cmpl $0x0, (%rcx,%rbp,8)
js 0xb37df
movq 0x10(%r15), %rsi
cmpl $0x0, 0xc(%rsi,%r12)
je 0xb37df
testq %r14, %r14
je 0xb376a
addq %r12, %rsi
movq %r14, %rdi
callq 0xb365e
movq (%rbx), %rax
movq 0x10(%r15), %rsi
movq 0x10(%rbx), %rcx
imulq $0x28, %rax, %rax
movl (%rsi,%r12), %edx
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl %r8d, %edx
movl (%rcx,%rax), %esi
andl %r13d, %esi
orl %edx, %esi
movl %esi, (%rcx,%rax)
movq 0x10(%r15), %rsi
movl (%rsi,%r12), %esi
andl %r13d, %esi
orl %edx, %esi
movl %esi, (%rcx,%rax)
movq 0x10(%r15), %rdx
movups 0x4(%rdx,%r12), %xmm0
movups %xmm0, 0x4(%rcx,%rax)
andq $0x0, 0xc(%rdx,%r12)
movups 0x18(%rdx,%r12), %xmm0
movups %xmm0, 0x18(%rcx,%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rdx,%r12)
movq 0x18(%rbx), %rdi
movl (%rbx), %esi
movl (%rcx,%rax), %edx
andl %r8d, %edx
xorl %ecx, %ecx
callq 0x69316
movq (%rbx), %rax
incq %rax
movq %rax, (%rbx)
incq %rbp
addq $0x28, %r12
jmp 0xb371f
movq 0x18(%rbx), %rax
movq 0x28(%rax), %rdi
callq 0x2220
movq 0x18(%rbx), %rdi
andq $0x0, 0x28(%rdi)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x694eb
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq