// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: merge_unitig_content(ma_utg_t*, ma_ug_t*, asg_t*, kvec_asg_arc_t_warp*)
void merge_unitig_content(ma_utg_t* collection, ma_ug_t* ug, asg_t* read_g, kvec_asg_arc_t_warp* edge)
{
    if(collection->m == 0) return;
    uint32_t i, j, index = 0, uId, ori;
    uint64_t totalLen;
    ma_utg_t* query = NULL;
    for (i = 0; i < collection->n; i++)
    {
        uId = collection->a[i]>>33;
        ori = collection->a[i]>>32&1;
        query = &(ug->u.a[uId]);
        index += query->n;
    }

    uint64_t* buffer = (uint64_t*)malloc(sizeof(uint64_t)*index);
    uint64_t* aim = NULL;
    index = 0;
    for (i = 0; i < collection->n; i++)
    {
        uId = collection->a[i]>>33;
        ori = collection->a[i]>>32&1;
        query = &(ug->u.a[uId]);
        aim = buffer + index;
        if(ori == 1)
        {
            for (j = 0; j < query->n; j++)
            {
                aim[query->n - j - 1] = (query->a[j])^(uint64_t)(0x100000000);
            }
        }
        else
        {
            for (j = 0; j < query->n; j++)
            {
                aim[j] = query->a[j];
            }
        }
        index += query->n;
        free(query->a);query->m=0;query->a=NULL;
    }

    if(index == 0) return;

    ///fill_unitig(buffer, index, read_g, edge, collection->circ, &totalLen);
    fill_unitig(buffer, index, read_g, edge, /**collection->circ**/
                    (collection->n == 1 && ug->u.a[collection->a[0]>>33].circ), &totalLen);

    ///important. must be here
    if(collection->n == 1 && ug->u.a[collection->a[0]>>33].circ) collection->circ = 1;
    
    free(collection->a);
    collection->a = buffer;
    collection->n = collection->m = index;
    collection->len = totalLen;
    if(!collection->circ)
    {
        collection->start = collection->a[0]>>32;
        collection->end = (collection->a[collection->n-1]>>32)^1;
    }
    else
    {
        collection->start = collection->end = UINT32_MAX;
    }
    
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, 0x8(%rsp)
cmpl $0x0, 0xc(%rdi)
je 0xcd8f2
movq %rdi, %rbx
movl 0x10(%rdi), %r14d
testq %r14, %r14
je 0xcd8f2
movq %rcx, %r15
movq %rdx, %r12
movq 0x18(%rbx), %rax
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %rcx
xorl %edx, %edx
xorl %esi, %esi
movq (%rax,%rdx,8), %rdi
shrq $0x21, %rdi
leaq (%rdi,%rdi,4), %rdi
addl 0x10(%rcx,%rdi,8), %esi
incq %rdx
cmpq %rdx, %r14
jne 0xcd741
movl %esi, %edi
shlq $0x3, %rdi
callq 0x2280
testq %r14, %r14
je 0xcd8f2
movq %r12, 0x10(%rsp)
movq %r15, 0x18(%rsp)
xorl %r12d, %r12d
movabsq $0x100000000, %r13      # imm = 0x100000000
xorl %ebp, %ebp
movq %rax, %r15
movl %ebp, %r10d
movq 0x18(%rbx), %rcx
movq (%rcx,%r12,8), %rdx
movq %rdx, %rcx
shrq $0x21, %rcx
movq 0x8(%rsp), %rsi
movq 0x10(%rsi), %rsi
leaq (%rcx,%rcx,4), %rcx
leaq (%rsi,%rcx,8), %r14
movl %ebp, %ecx
leaq (%rax,%rcx,8), %rcx
movl 0x10(%r14), %ebp
testq %r13, %rdx
jne 0xcd7d8
testq %rbp, %rbp
je 0xcd800
movq 0x18(%r14), %rdx
xorl %esi, %esi
movq (%rdx,%rsi,8), %rdi
movq %rdi, (%rcx,%rsi,8)
incq %rsi
cmpq %rsi, %rbp
jne 0xcd7c6
jmp 0xcd802
testq %rbp, %rbp
je 0xcd800
movq 0x18(%r14), %rdx
leal -0x1(%rbp), %esi
xorl %edi, %edi
movq (%rdx,%rdi,8), %r8
xorq %r13, %r8
movl %esi, %r9d
movq %r8, (%rcx,%r9,8)
incq %rdi
decl %esi
cmpq %rdi, %rbp
jne 0xcd7e6
jmp 0xcd802
xorl %ebp, %ebp
addl %r10d, %ebp
movq 0x18(%r14), %rdi
callq 0x2220
movl $0x0, 0xc(%r14)
movq $0x0, 0x18(%r14)
incq %r12
movl 0x10(%rbx), %ecx
cmpq %rcx, %r12
movq %r15, %rax
jb 0xcd789
testl %ebp, %ebp
movq 0x18(%rsp), %r10
movq 0x10(%rsp), %rdx
je 0xcd8f2
xorl %r8d, %r8d
cmpl $0x1, %ecx
jne 0xcd86a
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %rsi
movq 0x18(%rbx), %rcx
movq (%rcx), %rcx
shrq $0x21, %rcx
leaq (%rcx,%rcx,4), %rcx
movl (%rsi,%rcx,8), %r8d
shrl $0x1f, %r8d
leaq 0x20(%rsp), %r9
movq %rax, %rdi
movl %ebp, %esi
movq %r10, %rcx
callq 0x113fe2
cmpl $0x1, 0x10(%rbx)
jne 0xcd8a6
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rbx), %rdi
movq (%rdi), %rcx
shrq $0x21, %rcx
leaq (%rcx,%rcx,4), %rcx
cmpl $0x0, (%rax,%rcx,8)
jns 0xcd8aa
orb $-0x80, 0x3(%rbx)
jmp 0xcd8aa
movq 0x18(%rbx), %rdi
callq 0x2220
movq %r15, 0x18(%rbx)
movl %ebp, 0xc(%rbx)
movl %ebp, 0x10(%rbx)
movl (%rbx), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl 0x20(%rsp), %ecx
movl %eax, %edx
andl $0x80000000, %edx       # imm = 0x80000000
orl %ecx, %edx
movl %edx, (%rbx)
testl %eax, %eax
js 0xcd8ea
movl 0x4(%r15), %eax
movl %eax, 0x4(%rbx)
decl %ebp
movl 0x4(%r15,%rbp,8), %eax
xorl $0x1, %eax
movl %eax, 0x8(%rbx)
jmp 0xcd8f2
movq $-0x1, 0x4(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq