// File: /workspace/github_cpp_makefile_star2_O1/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
andq $0x7fffffff, %rcx       # imm = 0x7FFFFFFF
je 0xf0dfd
movq 0x20(%rax), %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rcx
xorl %edx, %edx
xorl %r12d, %r12d
cmpl $0x0, (%rax)
js 0xf0dee
movq 0x10(%r15), %rsi
cmpl $0x1, 0xc(%rsi,%rdx)
sbbq $-0x1, %r12
addq $0x8, %rax
addq $0x28, %rdx
cmpq %rdx, %rcx
jne 0xf0ddc
jmp 0xf0e00
xorl %r12d, %r12d
testq %r12, %r12
je 0xf0f63
movq (%rbx), %rax
addq %r12, %rax
movq %rax, (%rbx)
cmpq 0x8(%rbx), %rax
jbe 0xf0e31
movq %rax, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,4), %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
subq %r12, (%rbx)
movq 0x18(%r15), %rax
testl $0x7fffffff, 0x14(%rax) # imm = 0x7FFFFFFF
je 0xf0f32
xorl %r12d, %r12d
xorl %ebp, %ebp
xorl %r13d, %r13d
movq 0x20(%rax), %rax
cmpl $0x0, (%rax,%r13,8)
js 0xf0f15
movq 0x10(%r15), %rsi
cmpl $0x0, 0xc(%rsi,%rbp)
je 0xf0f15
testq %r14, %r14
je 0xf0e7b
addq %rbp, %rsi
movq %r14, %rdi
callq 0xf0d73
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
leaq (%rcx,%rcx,4), %rcx
movq 0x10(%r15), %rdx
movl (%rdx,%rbp), %edx
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl %r8d, %edx
movl (%rax,%rcx,8), %esi
movl $0x80000000, %edi       # imm = 0x80000000
andl %edi, %esi
orl %edx, %esi
movl %esi, (%rax,%rcx,8)
movq 0x10(%r15), %rsi
movl (%rsi,%rbp), %esi
andl %edi, %esi
orl %edx, %esi
movl %esi, (%rax,%rcx,8)
movq 0x10(%r15), %rdx
movl 0x4(%rdx,%rbp), %esi
movl %esi, 0x4(%rax,%rcx,8)
movl 0x8(%rdx,%rbp), %esi
movl %esi, 0x8(%rax,%rcx,8)
movl 0xc(%rdx,%rbp), %esi
movl %esi, 0xc(%rax,%rcx,8)
movl %r12d, 0xc(%rdx,%rbp)
movl 0x10(%rdx,%rbp), %esi
movl %esi, 0x10(%rax,%rcx,8)
movl %r12d, 0x10(%rdx,%rbp)
movq 0x18(%rdx,%rbp), %rsi
movq %rsi, 0x18(%rax,%rcx,8)
movq %r12, 0x18(%rdx,%rbp)
movq 0x20(%rdx,%rbp), %rsi
movq %rsi, 0x20(%rax,%rcx,8)
movq %r12, 0x20(%rdx,%rbp)
movq 0x18(%rbx), %rdi
movl (%rbx), %esi
movl (%rax,%rcx,8), %edx
andl %r8d, %edx
xorl %ecx, %ecx
callq 0xa0115
incq (%rbx)
incq %r13
movq 0x18(%r15), %rax
movl 0x14(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addq $0x28, %rbp
cmpq %rcx, %r13
jb 0xf0e4d
movq 0x18(%rbx), %rax
movq 0x28(%rax), %rdi
testq %rdi, %rdi
je 0xf0f44
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 0xa02fa
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq