// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: merge_utg(ma_ug_t**, ma_ug_t**)
ma_ug_t* merge_utg(ma_ug_t **dest, ma_ug_t **src)
{
    asg_t *g_d = (*dest)->g, *g_s = (*src)->g;
    uint64_t occ_d = g_d->n_seq, occ_s = g_s->n_seq, i;
    asg_arc_t *p = NULL;
    g_d->is_srt = g_d->is_symm = 0;
    
    for (i = 0; i < occ_s; i++)
    {
        asg_seq_set(g_d, i+occ_d, g_s->seq[i].len, g_s->seq[i].del);
        g_d->seq[i+occ_d].c = g_s->seq[i].c;
    }

    g_d->seq_vis = (uint8_t*)realloc(g_d->seq_vis, g_d->n_seq*2*sizeof(uint8_t));


    for (i = 0; i < g_s->n_arc; i++)
    {
        p = asg_arc_pushp(g_d);
        (*p) = g_s->arc[i];
        p->ul += (occ_d<<33);
        p->v += (occ_d<<1);
    }

    asg_cleanup(g_d);
    g_d->r_seq = g_d->n_seq;

    if(g_s->n_F_seq > 0 && g_s->F_seq)
    {
        uint64_t n_F_seq = g_d->n_F_seq + g_s->n_F_seq;
        g_d->F_seq = (ma_utg_t*)realloc(g_d->F_seq, n_F_seq*sizeof(ma_utg_t));
        memcpy(g_d->F_seq + g_d->n_F_seq, g_s->F_seq, g_s->n_F_seq*sizeof(ma_utg_t));
        g_d->n_F_seq = n_F_seq;
        free(g_s->F_seq);
        g_s->F_seq = NULL;
        g_s->n_F_seq = 0;
    }

    ma_utg_v *u_d = &((*dest)->u), *u_s = &((*src)->u);
    if(u_s->n > 0)
    {
        uint64_t n = u_d->n + u_s->n;
        u_d->a = (ma_utg_t*)realloc(u_d->a, n*sizeof(ma_utg_t));
        memcpy(u_d->a + u_d->n, u_s->a, u_s->n*sizeof(ma_utg_t));
        u_d->n = u_d->m = n;
        free(u_s->a);
        u_s->a = NULL;
        u_s->n = u_s->m = 0;
    }

    kv_push(uint64_t, (*dest)->occ, occ_d);
    kv_push(uint64_t, (*dest)->occ, occ_s);
    
    ma_ug_destroy(*src);
    return (*dest);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x30(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, 0x14(%rax)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, 0x4(%rax)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x114a7e
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rax
addq -0x28(%rbp), %rax
movl %eax, %esi
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x38(%rbp), %rcx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x38(%rbp), %rcx
movl (%rax,%rcx,8), %ecx
shrl $0x1f, %ecx
callq 0xcd8f0
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x38(%rbp), %rcx
movb 0x4(%rax,%rcx,8), %dl
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x38(%rbp), %rcx
addq -0x28(%rbp), %rcx
movb %dl, 0x4(%rax,%rcx,8)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x114a08
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movslq %eax, %rsi
shlq $0x0, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x30(%rax)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x20(%rbp), %rcx
movl 0x4(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x114b39
movq -0x18(%rbp), %rdi
callq 0xd4050
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
imulq $0x18, -0x38(%rbp), %rax
addq %rax, %rcx
movq -0x40(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rcx
shlq $0x21, %rcx
movq -0x40(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rdx
shlq %rdx
movq -0x40(%rbp), %rax
movl 0x8(%rax), %ecx
addq %rdx, %rcx
movl %ecx, 0x8(%rax)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x114ab3
movq -0x18(%rbp), %rdi
callq 0xcdd10
movq -0x18(%rbp), %rax
movl 0x14(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq -0x18(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jbe 0x114c03
movq -0x20(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0x114c03
movq -0x18(%rbp), %rax
movl 0x38(%rax), %eax
movq -0x20(%rbp), %rcx
addl 0x38(%rcx), %eax
movl %eax, %eax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdi
imulq $0x28, -0x48(%rbp), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x38(%rax), %eax
imulq $0x28, %rax, %rax
addq %rax, %rdi
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rsi
movq -0x20(%rbp), %rax
movl 0x38(%rax), %eax
imulq $0x28, %rax, %rdx
callq 0x2180
movq -0x48(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x2210
movq -0x20(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x38(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq $0x0, (%rax)
jbe 0x114cc1
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq -0x58(%rbp), %rcx
addq (%rcx), %rax
movq %rax, -0x60(%rbp)
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rdi
imulq $0x28, -0x60(%rbp), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x50(%rbp), %rax
imulq $0x28, (%rax), %rax
addq %rax, %rdi
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x58(%rbp), %rax
imulq $0x28, (%rax), %rdx
callq 0x2180
movq -0x60(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x50(%rbp), %rax
movq %rcx, (%rax)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2210
movq -0x58(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x58(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x58(%rbp), %rax
movq $0x0, (%rax)
jmp 0x114cc3
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
cmpq 0x28(%rcx), %rax
jne 0x114d44
movq -0x8(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, 0x28(%rax)
je 0x114cfd
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rax
shlq %rax
movq %rax, -0x68(%rbp)
jmp 0x114d08
movl $0x2, %eax
movq %rax, -0x68(%rbp)
jmp 0x114d08
movq -0x68(%rbp), %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x28(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x30(%rax)
movq -0x28(%rbp), %rdx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rsi
movq 0x20(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x20(%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x114d6f
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
cmpq 0x28(%rcx), %rax
jne 0x114df0
movq -0x8(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, 0x28(%rax)
je 0x114da9
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rax
shlq %rax
movq %rax, -0x70(%rbp)
jmp 0x114db4
movl $0x2, %eax
movq %rax, -0x70(%rbp)
jmp 0x114db4
movq -0x70(%rbp), %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x28(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x30(%rax)
movq -0x30(%rbp), %rdx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rsi
movq 0x20(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x20(%rsi)
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0xcd6f0
movq -0x8(%rbp), %rax
movq (%rax), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)