// File: 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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jae 0x14e31d
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x2c(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x14e304
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0xc(%rax)
jne 0x14e306
jmp 0x14e312
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x14e2ce
cmpq $0x0, -0x20(%rbp)
jne 0x14e329
jmp 0x14e60d
movq -0x8(%rbp), %rax
movq (%rax), %rcx
addq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jbe 0x14e37c
movq -0x8(%rbp), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x8(%rbp), %rax
imulq $0x28, 0x8(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rcx
subq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x14e5d0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl -0x2c(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x14e3e3
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0xc(%rax)
jne 0x14e3e8
jmp 0x14e5c2
cmpq $0x0, -0x18(%rbp)
je 0x14e40a
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movl -0x2c(%rbp), %eax
imulq $0x28, %rax, %rax
addq %rax, %rsi
callq 0x14e220
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
imulq $0x28, (%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq -0x38(%rbp), %rax
movl (%rax), %ecx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %edx, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %edx
shrl $0x1f, %edx
movq -0x38(%rbp), %rax
movl (%rax), %ecx
andl $0x1, %edx
shll $0x1f, %edx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl %edx, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0xc(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq $0x0, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x20(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq $0x0, 0x20(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl %eax, %esi
movq -0x38(%rbp), %rax
movl (%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
callq 0xcd8f0
movq -0x8(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x14e395
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
cmpq $0x0, 0x28(%rax)
je 0x14e5f0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rdi
callq 0x2210
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq $0x0, 0x28(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0xcdd10
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)