// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r8
movq %rdi, 0x20(%rsp)
movq (%rdi), %rax
movq 0x18(%rax), %r15
movq (%rsi), %rax
movq 0x18(%rax), %r14
movl 0x14(%r15), %r12d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %r12, %rdx
movl 0x14(%r14), %ecx
andb $0x7f, 0x7(%r15)
andq %rax, %rdx
movl %edx, 0x14(%r15)
movl %edx, %esi
andq %rax, %rcx
movq %rcx, 0x8(%rsp)
movq %rdx, 0x10(%rsp)
movq %r8, 0x18(%rsp)
je 0xcd47b
movq 0x20(%r14), %rax
leaq 0x4(,%rdx,8), %rbx
xorl %r13d, %r13d
movq 0x8(%rsp), %rbp
leal (%rdx,%r13), %esi
movl (%rax,%r13,8), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
shrl $0x1f, %ecx
movq %r15, %rdi
callq 0xa0887
movq 0x20(%r14), %rax
movb 0x4(%rax,%r13,8), %cl
movq 0x20(%r15), %rdx
addq %rbx, %rdx
movb %cl, (%rdx,%r13,8)
movq 0x10(%rsp), %rdx
incq %r13
cmpq %r13, %rbp
jne 0xcd43b
movl 0x14(%r15), %esi
movq 0x30(%r15), %rdi
addl %esi, %esi
callq 0x2370
movq %rax, 0x30(%r15)
testl $0x7fffffff, 0x4(%r14)  # imm = 0x7FFFFFFF
je 0xcd545
movq 0x10(%rsp), %rbp
shlq $0x21, %rbp
addl %r12d, %r12d
xorl %r13d, %r13d
xorl %ebx, %ebx
movl 0x4(%r15), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl (%r15), %ecx
jne 0xcd4ed
leal (%rcx,%rcx), %eax
testl %ecx, %ecx
movl $0x10, %ecx
cmovel %ecx, %eax
movl %eax, (%r15)
movq 0x8(%r15), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
callq 0x2370
movq %rax, 0x8(%r15)
movl 0x4(%r15), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jmp 0xcd4f1
movq 0x8(%r15), %rax
leal 0x1(%rdx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %esi, %edx
movl %edx, 0x4(%r15)
movl %ecx, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x8(%r14), %rdx
movups (%rdx,%r13), %xmm0
movups %xmm0, (%rax,%rcx,8)
movq 0x10(%rdx,%r13), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
addq %rbp, (%rax,%rcx,8)
addl %r12d, 0x8(%rax,%rcx,8)
incq %rbx
movl 0x4(%r14), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq $0x18, %r13
cmpq %rax, %rbx
jb 0xcd4a9
movq %r15, %rdi
callq 0xa0a7d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl 0x14(%r15), %eax
movl %eax, 0x18(%r15)
movl 0x38(%r14), %ebx
testl %ebx, %ebx
je 0xcd5c6
cmpq $0x0, 0x40(%r14)
je 0xcd5c6
addl 0x38(%r15), %ebx
movq 0x40(%r15), %rdi
leaq (,%rbx,8), %rax
leaq (%rax,%rax,4), %rsi
callq 0x2370
movq %rax, 0x40(%r15)
movl 0x38(%r15), %ecx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rdi
movq 0x40(%r14), %r12
movl 0x38(%r14), %eax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rdx
movq %r12, %rsi
callq 0x2160
movl %ebx, 0x38(%r15)
movq %r12, %rdi
callq 0x2220
movq $0x0, 0x40(%r14)
movl $0x0, 0x38(%r14)
movq 0x18(%rsp), %rbp
movq (%rbp), %rbx
movq (%rbx), %r14
testq %r14, %r14
movq 0x20(%rsp), %r13
je 0xcd641
movq (%r13), %r12
addq (%r12), %r14
movq 0x10(%r12), %rdi
leaq (,%r14,8), %rax
leaq (%rax,%rax,4), %rsi
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %rcx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rdi
movq (%rbx), %rax
movq 0x10(%rbx), %r15
shlq $0x3, %rax
leaq (%rax,%rax,4), %rdx
movq %r15, %rsi
callq 0x2160
movq %r14, 0x8(%r12)
movq %r14, (%r12)
movq %r15, %rdi
callq 0x2220
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
movq (%r13), %rax
movq 0x20(%rax), %rcx
cmpq 0x28(%rax), %rcx
jne 0xcd680
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rdx, %rsi
movq %rsi, 0x28(%rax)
movq 0x30(%rax), %rdi
shlq $0x3, %rsi
callq 0x2370
movq (%r13), %rcx
movq %rax, 0x30(%rcx)
movq (%r13), %rax
movq 0x20(%rax), %rcx
movq 0x30(%rax), %rdi
leaq 0x1(%rcx), %rdx
movq %rdx, 0x20(%rax)
movq 0x10(%rsp), %rdx
movq %rdx, (%rdi,%rcx,8)
movq 0x20(%rax), %rcx
cmpq 0x28(%rax), %rcx
jne 0xcd6d0
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rdx, %rsi
movq %rsi, 0x28(%rax)
shlq $0x3, %rsi
callq 0x2370
movq (%r13), %rcx
movq %rax, 0x30(%rcx)
movq (%r13), %rax
movq 0x20(%rax), %rcx
movq 0x30(%rax), %rdi
movq 0x8(%rsp), %rsi
leaq 0x1(%rcx), %rdx
movq %rdx, 0x20(%rax)
movq %rsi, (%rdi,%rcx,8)
movq (%rbp), %rdi
callq 0xa0761
movq (%r13), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq