// File: /workspace/github_cpp_makefile_star2_O3/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 0x18(%rsi), %rax
movl 0x14(%rax), %edx
andq $0x7fffffff, %rdx       # imm = 0x7FFFFFFF
je 0xf2dc3
movq %rsi, %r15
movq %rdi, %rbx
movq 0x20(%rax), %rcx
shlq $0x3, %rdx
leaq (%rdx,%rdx,4), %rdx
xorl %esi, %esi
xorl %r12d, %r12d
cmpl $0x0, (%rcx)
js 0xf2c40
movq 0x10(%r15), %rdi
cmpl $0x1, 0xc(%rdi,%rsi)
sbbq $-0x1, %r12
addq $0x8, %rcx
addq $0x28, %rsi
cmpq %rsi, %rdx
jne 0xf2c2e
testq %r12, %r12
je 0xf2dc3
movq (%rbx), %rcx
addq %r12, %rcx
movq %rcx, (%rbx)
cmpq 0x8(%rbx), %rcx
jbe 0xf2c85
movq %rcx, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
movq 0x18(%r15), %rax
subq %r12, %rcx
movq %rcx, (%rbx)
testl $0x7fffffff, 0x14(%rax) # imm = 0x7FFFFFFF
je 0xf2d8f
xorl %r12d, %r12d
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movl $0x80000000, %r13d      # imm = 0x80000000
movq 0x20(%rax), %rdx
cmpl $0x0, (%rdx,%r12,8)
js 0xf2d7a
movq 0x10(%r15), %rdx
leaq (%r12,%r12,4), %rsi
cmpl $0x0, 0xc(%rdx,%rsi,8)
je 0xf2d7a
testq %r14, %r14
je 0xf2cff
leaq (%rdx,%rsi,8), %rax
cmpl $0x0, 0x10(%rax)
je 0xf2cff
xorl %ecx, %ecx
movq 0x10(%r14), %rdx
movq 0x18(%rax), %rsi
movq (%rsi,%rcx,8), %rsi
shrq $0x21, %rsi
movb $0x0, (%rdx,%rsi)
incq %rcx
movl 0x10(%rax), %edx
cmpq %rdx, %rcx
jb 0xf2cd9
movq (%rbx), %rcx
movq 0x10(%r15), %rdx
movq 0x10(%rbx), %rax
leaq (%rcx,%rcx,4), %rcx
leaq (,%r12,8), %rsi
leaq (%rsi,%rsi,4), %rsi
movl (%rdx,%rsi), %edx
andl %ebp, %edx
movl (%rax,%rcx,8), %edi
andl %r13d, %edi
orl %edx, %edi
movl %edi, (%rax,%rcx,8)
movq 0x10(%r15), %rdi
movl (%rdi,%rsi), %edi
andl %r13d, %edi
orl %edx, %edi
movl %edi, (%rax,%rcx,8)
movq 0x10(%r15), %rdx
movups 0x4(%rdx,%rsi), %xmm0
movups %xmm0, 0x4(%rax,%rcx,8)
movq $0x0, 0xc(%rdx,%rsi)
movups 0x18(%rdx,%rsi), %xmm0
movups %xmm0, 0x18(%rax,%rcx,8)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rdx,%rsi)
movq 0x18(%rbx), %rdi
movl (%rbx), %esi
movl (%rax,%rcx,8), %edx
andl %ebp, %edx
xorl %ecx, %ecx
callq 0xa0887
movq (%rbx), %rcx
incq %rcx
movq %rcx, (%rbx)
movq 0x18(%r15), %rax
incq %r12
movl 0x14(%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpq %rdx, %r12
jb 0xf2ca6
movq 0x18(%rbx), %rdi
movq 0x28(%rdi), %rax
testq %rax, %rax
je 0xf2da8
movq %rax, %rdi
callq 0x2220
movq 0x18(%rbx), %rdi
movq $0x0, 0x28(%rdi)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa0a7d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq