// File: /workspace/github_cpp_makefile_star2_O2/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:
cmpl $0x0, 0xc(%rdi)
je 0x92443
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbp
movq %rdi, %r8
movq %rdx, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
movl 0x10(%rdi), %r14d
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %rax, %r14
je 0x922a4
movq 0x18(%r8), %rdx
movq (%rdx,%rax,8), %rdx
shrq $0x21, %rdx
movq 0x10(%rbp), %rsi
imulq $0x28, %rdx, %rdx
addl 0x10(%rsi,%rdx), %ecx
incq %rax
jmp 0x92282
movabsq $0x100000000, %r12      # imm = 0x100000000
movl %ecx, %edi
shlq $0x3, %rdi
movq %r8, 0x8(%rsp)
callq 0x2280
movq 0x8(%rsp), %rcx
xorl %r13d, %r13d
xorl %esi, %esi
movl %r14d, %edx
cmpq %rdx, %r13
jae 0x92378
movq 0x18(%rcx), %rcx
movq (%rcx,%r13,8), %rcx
movq %rcx, %rdi
shrq $0x21, %rdi
movq %rbp, %rbx
movq 0x10(%rbp), %rdx
imulq $0x28, %rdi, %r8
leaq (%rdx,%r8), %r14
movl %esi, %edi
movq %rax, %r15
leaq (%rax,%rdi,8), %rax
movl 0x10(%rdx,%r8), %ebp
testq %r12, %rcx
jne 0x9231d
xorl %ecx, %ecx
cmpq %rcx, %rbp
je 0x9234a
movq 0x18(%r14), %rdx
movq (%rdx,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
incq %rcx
jmp 0x92307
leaq (,%rbp,8), %rcx
leal -0x1(%rbp), %edx
xorl %r9d, %r9d
cmpq %r9, %rcx
je 0x9234a
movq 0x18(%r14), %rdi
movq (%rdi,%r9), %rdi
xorq %r12, %rdi
movl %edx, %r8d
movq %rdi, (%rax,%r8,8)
addq $0x8, %r9
decl %edx
jmp 0x9232b
addl %esi, %ebp
movq 0x18(%r14), %rdi
callq 0x2220
andl $0x0, 0xc(%r14)
andq $0x0, 0x18(%r14)
incq %r13
movq 0x8(%rsp), %rcx
movl 0x10(%rcx), %r14d
movl %ebp, %esi
movq %rbx, %rbp
movq %r15, %rax
jmp 0x922c8
testl %esi, %esi
je 0x92435
xorl %r8d, %r8d
cmpl $0x1, %r14d
jne 0x923a4
movq 0x10(%rbp), %rdx
movq 0x18(%rcx), %rcx
movq (%rcx), %rcx
shrq $0x21, %rcx
imulq $0x28, %rcx, %rcx
movl (%rdx,%rcx), %r8d
shrl $0x1f, %r8d
leaq 0x20(%rsp), %r9
movq %rax, %rbx
movq %rax, %rdi
movq %rsi, %r14
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rcx
callq 0xcfa82
movq 0x8(%rsp), %rdx
cmpl $0x1, 0x10(%rdx)
movq 0x18(%rdx), %rdi
jne 0x923e9
movq 0x10(%rbp), %rax
movq (%rdi), %rcx
shrq $0x21, %rcx
imulq $0x28, %rcx, %rcx
cmpl $0x0, (%rax,%rcx)
jns 0x923e9
orb $-0x80, 0x3(%rdx)
callq 0x2220
movq 0x8(%rsp), %rsi
movq %rbx, 0x18(%rsi)
movl %r14d, 0xc(%rsi)
movl %r14d, 0x10(%rsi)
movl (%rsi), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl 0x20(%rsp), %ecx
movl %eax, %edx
andl $0x80000000, %edx       # imm = 0x80000000
orl %ecx, %edx
movl %edx, (%rsi)
testl %eax, %eax
js 0x92430
movl 0x4(%rbx), %eax
movl %eax, 0x4(%rsi)
decl %r14d
movl 0x4(%rbx,%r14,8), %eax
xorl $0x1, %eax
movl %eax, 0x8(%rsi)
jmp 0x92435
orq $-0x1, 0x4(%rsi)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq