// File: /workspace/github_cpp_makefile_star2_O1/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 %rdi, 0x20(%rsp)
movq (%rdi), %rax
movq 0x18(%rax), %r15
movq %rsi, 0x18(%rsp)
movq (%rsi), %rax
movq 0x18(%rax), %rbp
movl 0x14(%r15), %r13d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl 0x14(%rbp), %r12d
andb $0x7f, 0x7(%r15)
movq %r13, 0x8(%rsp)
andq %rax, %r13
movl %r13d, 0x14(%r15)
andq %rax, %r12
je 0xcc171
leaq 0x4(,%r13,8), %rbx
xorl %r14d, %r14d
leal (%r14,%r13), %esi
movq 0x20(%rbp), %rax
movl (%rax,%r14,8), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
shrl $0x1f, %ecx
movq %r15, %rdi
callq 0xa0115
movq 0x20(%rbp), %rax
movb 0x4(%rax,%r14,8), %al
movq 0x20(%r15), %rcx
addq %rbx, %rcx
movb %al, (%rcx,%r14,8)
incq %r14
cmpq %r14, %r12
jne 0xcc136
movq %r13, (%rsp)
movq %r12, 0x10(%rsp)
movq 0x30(%r15), %rdi
movl 0x14(%r15), %esi
addl %esi, %esi
callq 0x2370
movq %rax, 0x30(%r15)
testl $0x7fffffff, 0x4(%rbp)  # imm = 0x7FFFFFFF
movq 0x8(%rsp), %rbx
je 0xcc256
movq (%rsp), %r14
shlq $0x21, %r14
addl %ebx, %ebx
xorl %r12d, %r12d
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
xorl %r13d, %r13d
movl 0x4(%r15), %ecx
andl %r8d, %ecx
movl (%r15), %eax
cmpl %eax, %ecx
jne 0xcc1fa
leal (%rax,%rax), %ecx
testl %eax, %eax
movl $0x10, %eax
cmovel %eax, %ecx
movl %ecx, (%r15)
movq 0x8(%r15), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq %rax, 0x8(%r15)
movq 0x8(%r15), %rax
movl 0x4(%r15), %ecx
movq %rcx, %rdx
andq %r9, %rdx
leal 0x1(%rcx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %esi, %ecx
movl %ecx, 0x4(%r15)
leaq (%rdx,%rdx,2), %rcx
movq 0x8(%rbp), %rdx
movups (%rdx,%r12), %xmm0
movups %xmm0, (%rax,%rcx,8)
movq 0x10(%rdx,%r12), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
addq %r14, (%rax,%rcx,8)
addl %ebx, 0x8(%rax,%rcx,8)
incq %r13
movl 0x4(%rbp), %eax
andq %r9, %rax
addq $0x18, %r12
cmpq %rax, %r13
jb 0xcc1bb
movq %r15, %rdi
callq 0xa02fa
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl 0x14(%r15), %eax
movl %eax, 0x18(%r15)
movl 0x38(%rbp), %ebx
testl %ebx, %ebx
je 0xcc2d2
cmpq $0x0, 0x40(%rbp)
je 0xcc2d2
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(%rbp), %rsi
movl 0x38(%rbp), %eax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rdx
callq 0x2160
movl %ebx, 0x38(%r15)
movq 0x40(%rbp), %rdi
callq 0x2220
movq $0x0, 0x40(%rbp)
movl $0x0, 0x38(%rbp)
movq 0x18(%rsp), %r13
movq (%r13), %rbx
movq (%rbx), %r14
testq %r14, %r14
movq 0x20(%rsp), %r12
je 0xcc345
movq (%r12), %r15
addq (%r15), %r14
movq 0x10(%r15), %rdi
leaq (,%r14,8), %rax
leaq (%rax,%rax,4), %rsi
callq 0x2370
movq %rax, 0x10(%r15)
movq (%r15), %rcx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rdi
movq (%rbx), %rax
movq 0x10(%rbx), %rsi
shlq $0x3, %rax
leaq (%rax,%rax,4), %rdx
callq 0x2160
movq %r14, 0x8(%r15)
movq %r14, (%r15)
movq 0x10(%rbx), %rdi
callq 0x2220
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
movq (%r12), %rax
movq 0x28(%rax), %rcx
cmpq %rcx, 0x20(%rax)
jne 0xcc37c
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 (%r12), %rcx
movq %rax, 0x30(%rcx)
movq (%r12), %rax
movq 0x20(%rax), %rcx
movq 0x30(%rax), %rdi
leaq 0x1(%rcx), %rdx
movq %rdx, 0x20(%rax)
movq (%rsp), %rdx
movq %rdx, (%rdi,%rcx,8)
movq 0x28(%rax), %rcx
cmpq %rcx, 0x20(%rax)
jne 0xcc3c7
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rdx, %rsi
movq %rsi, 0x28(%rax)
shlq $0x3, %rsi
callq 0x2370
movq (%r12), %rcx
movq %rax, 0x30(%rcx)
movq (%r12), %rax
movq 0x20(%rax), %rcx
movq 0x30(%rax), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x20(%rax)
movq 0x10(%rsp), %rax
movq %rax, (%rdx,%rcx,8)
movq (%r13), %rdi
callq 0xa0004
movq (%r12), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq