// File: /workspace/github_cpp_makefile_star2_O2/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), %r14
movl 0x14(%r15), %ebx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rbx, %rcx
andq %rax, %rcx
movl 0x14(%r14), %r12d
movl %ecx, 0x14(%r15)
andb $0x7f, 0x7(%r15)
andq %rax, %r12
movq %rcx, 0x8(%rsp)
leaq 0x4(,%rcx,8), %rbp
xorl %r13d, %r13d
cmpq %r13, %r12
je 0x91e94
movq 0x8(%rsp), %rax
leal (%rax,%r13), %esi
movq 0x20(%r14), %rax
movl (%rax,%r13,8), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
shrl $0x1f, %ecx
movq %r15, %rdi
callq 0x69316
movq 0x20(%r14), %rax
movb 0x4(%rax,%r13,8), %al
movq 0x20(%r15), %rcx
addq %rbp, %rcx
movb %al, (%rcx,%r13,8)
incq %r13
jmp 0x91e52
movq %r12, 0x10(%rsp)
movq 0x30(%r15), %rdi
movl 0x14(%r15), %esi
addl %esi, %esi
callq 0x2370
movq %rax, 0x30(%r15)
movq 0x8(%rsp), %rbp
shlq $0x21, %rbp
addl %ebx, %ebx
xorl %r13d, %r13d
xorl %r12d, %r12d
movl 0x4(%r14), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %r15, %rdi
cmpq %rax, %r12
jae 0x91ef7
callq 0x6c45d
movq 0x8(%r14), %rcx
movups (%rcx,%r13), %xmm0
movups %xmm0, (%rax)
movq 0x10(%rcx,%r13), %rcx
addq %rbp, (%rax)
movq %rcx, 0x10(%rax)
addl %ebx, 0x8(%rax)
incq %r12
addq $0x18, %r13
jmp 0x91ebd
callq 0x694eb
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl 0x14(%r15), %eax
movl %eax, 0x18(%r15)
movl 0x38(%r14), %r13d
testl %r13d, %r13d
je 0x91f63
cmpq $0x0, 0x40(%r14)
je 0x91f63
addl 0x38(%r15), %r13d
movq 0x40(%r15), %rdi
imulq $0x28, %r13, %rsi
callq 0x2370
movq %rax, 0x40(%r15)
movl 0x38(%r15), %ecx
imulq $0x28, %rcx, %rdi
addq %rax, %rdi
movq 0x40(%r14), %rbx
movl 0x38(%r14), %eax
imulq $0x28, %rax, %rdx
movq %rbx, %rsi
callq 0x2160
movl %r13d, 0x38(%r15)
movq %rbx, %rdi
callq 0x2220
andq $0x0, 0x40(%r14)
andl $0x0, 0x38(%r14)
movq 0x18(%rsp), %rbp
movq (%rbp), %rbx
movq (%rbx), %r14
testq %r14, %r14
movq 0x20(%rsp), %r13
je 0x91fc8
movq (%r13), %r12
addq (%r12), %r14
movq 0x10(%r12), %rdi
imulq $0x28, %r14, %rsi
callq 0x2370
movq %rax, 0x10(%r12)
imulq $0x28, (%r12), %rdi
addq %rax, %rdi
movq 0x10(%rbx), %r15
imulq $0x28, (%rbx), %rdx
movq %r15, %rsi
callq 0x2160
movq %r14, 0x8(%r12)
movq %r14, (%r12)
movq %r15, %rdi
callq 0x2220
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
movq (%r13), %rax
movq 0x20(%rax), %rcx
pushq $0x2
popq %r14
cmpq 0x28(%rax), %rcx
jne 0x92006
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %r14, %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 0x10(%rsp), %rbx
movq 0x30(%rax), %rdi
leaq 0x1(%rcx), %rdx
movq %rdx, 0x20(%rax)
movq 0x8(%rsp), %rdx
movq %rdx, (%rdi,%rcx,8)
movq 0x20(%rax), %rcx
cmpq 0x28(%rax), %rcx
jne 0x92056
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %r14, %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
leaq 0x1(%rcx), %rdx
movq %rdx, 0x20(%rax)
movq %rbx, (%rdi,%rcx,8)
movq (%rbp), %rdi
callq 0x6921d
movq (%r13), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq