// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: copy_graph(asg_t*, int)
asg_t *copy_graph(asg_t* src, int round)
{
    asg_t *rg;
	///just calloc
	rg = asg_init();
    uint64_t i, k;
    for (i = 0; i < src->n_seq; ++i) 
    {
        ///if a read has been deleted, should we still add them?
		asg_seq_set(rg, i, src->seq[i].len, src->seq[i].del);
        rg->seq[i].c = src->seq[i].c;
	}
    asg_cleanup(rg);

    
    uint32_t v, n_vtx = src->n_seq * 2, totalL = 0;;


    for (k = 0; k < (uint32_t)round; k++)
    {
        for (i = k; i < src->n_arc; i = i + round)
        {
            if(totalL%50000==0) fprintf(stderr, "totalL: %u, n_arc: %u\n", totalL, src->n_arc);
            totalL++;
            if(src->arc[i].del) continue;
            asg_append_edges_to_srt(rg, src->arc[i].ul>>32, 
            (uint32_t)(src->arc[i].ul) + src->arc[i].ol,
            src->arc[i].v, src->arc[i].ol, src->arc[i].strong, 
            src->arc[i].el, src->arc[i].no_l_indel);
        }
    }
    
    
    totalL = 0;
    for (v = 0; v < n_vtx; ++v)
    {
        if (src->seq[v>>1].del) continue;
        uint32_t nv = asg_arc_n(src, v);
        asg_arc_t *av = asg_arc_a(src, v);
        for (i = 0; i < nv; i++)
        {
            if(totalL%50000==0) fprintf(stderr, "-totalL: %u, n_arc: %u\n", totalL, src->n_arc);
            totalL++;
            if(av[i].del) continue;
            asg_append_edges_to_srt(rg, av[i].ul>>32, (uint32_t)(av[i].ul) + av[i].ol,
            av[i].v, av[i].ol, av[i].strong, av[i].el, av[i].no_l_indel);
        }
    }
    

    

    /**
    for (v = 0; v < n_vtx; ++v)
    {
        if(src->idx[v] != rg->idx[v])
        {
            fprintf(stderr, "*****v: %u, src_i: %u, srcLen: %u, rg_i: %u, rgLen: %u\n", 
            v, src->idx[v]>>32, (uint32_t)src->idx[v], 
            rg->idx[v]>>32, (uint32_t)rg->idx[v]); 
        }
    }
    **/


    for (v = 0; v < n_vtx; ++v)
    {
        
        if(src->seq[v>>1].del != rg->seq[v>>1].del)
        {
            fprintf(stderr, "ERROR1\n");
        }

        uint32_t nv = asg_arc_n(src, v);
        asg_arc_t *av = asg_arc_a(src, v);
        ///if(nv != rnv)
        if(get_real_length(src, v, NULL) != get_real_length(rg, v, NULL))
        {
            fprintf(stderr, "ERROR2\n");
        }

        for (i = 0; i < nv; i++)
        {
            if(av[i].del) continue;
            asg_arc_t forward = av[i], backward;
            memset(&backward, 0, sizeof(backward));
            if(get_arc(rg, (forward.ul>>32), forward.v, &backward)!=1)
            {
                fprintf(stderr, "ERROR3\n");
            }

            if(forward.del != backward.del || forward.el != backward.el || 
               forward.no_l_indel != backward.no_l_indel || forward.ol != backward.ol ||
               forward.strong != backward.strong || forward.ul != backward.ul || forward.v != backward.v)
            {
                fprintf(stderr, "ERROR4\n");
                fprintf(stderr, "forward, del: %u, el: %u, no_l_indel: %u, ol: %u, strong: %u, ul: %u, v: %u\n",
                (uint32_t)forward.del, (uint32_t)forward.el, (uint32_t)forward.no_l_indel, 
                (uint32_t)forward.ol, (uint32_t)forward.strong,
                (uint32_t)forward.ul, (uint32_t)forward.v);
                fprintf(stderr, "backward, del: %u, el: %u, no_l_indel: %u, ol: %u, strong: %u, ul: %u, v: %u\n",
                (uint32_t)backward.del, (uint32_t)backward.el, (uint32_t)backward.no_l_indel, 
                (uint32_t)backward.ol, (uint32_t)backward.strong,
                (uint32_t)backward.ul, (uint32_t)backward.v);
            }
        }

        
        nv = asg_arc_n(rg, v);
        av = asg_arc_a(rg, v);
        for (i = 0; i < nv; i++)
        {
            if(av[i].del) continue;
            asg_arc_t forward = av[i], backward;
            memset(&backward, 0, sizeof(backward));
            if(get_arc(src, (forward.ul>>32), forward.v, &backward)!=1)
            {
                fprintf(stderr, "ERROR5\n");
            }

            if(forward.del != backward.del || forward.el != backward.el || 
               forward.no_l_indel != backward.no_l_indel || forward.ol != backward.ol ||
               forward.strong != backward.strong || forward.ul != backward.ul || forward.v != backward.v)
            {
                fprintf(stderr, "ERROR6\n");
            }
        }
        
        
        ///get_arc(g, forward.v^1, (forward.ul>>32)^1, &backward) 
        ///fprintf(stderr, "+v: %u\n", v);
        
    }

    
    if(src->seq_vis)
    {
        rg->seq_vis = (uint8_t*)malloc(src->n_seq*2*sizeof(uint8_t));
        memcpy(rg->seq_vis, src->seq_vis, src->n_seq*2*sizeof(uint8_t));
    }
    

    fprintf(stderr, "end_copy\n");
    return rg;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %esi, %ebp
movq %rdi, %rbx
pushq $0x1
popq %rdi
pushq $0x48
popq %rsi
callq 0x2120
movq %rax, %r14
testl $0x7fffffff, 0x14(%rbx) # imm = 0x7FFFFFFF
movq %rbx, (%rsp)
je 0xcfe8
movq 0x20(%rbx), %rax
xorl %ebx, %ebx
movl (%rax,%rbx,8), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
shrl $0x1f, %ecx
movq %r14, %rdi
movl %ebx, %esi
callq 0xa0887
movq (%rsp), %rsi
movq 0x20(%rsi), %rax
movb 0x4(%rax,%rbx,8), %cl
movq 0x20(%r14), %rdx
movb %cl, 0x4(%rdx,%rbx,8)
incq %rbx
movl 0x14(%rsi), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %rbx
jb 0xcfab
movq %r14, 0x8(%rsp)
movq %r14, %rdi
callq 0xa0a7d
movq (%rsp), %rdi
movl 0x14(%rdi), %eax
addl %eax, %eax
movl %eax, 0x40(%rsp)
testl %ebp, %ebp
je 0xd0ec
movl %ebp, %eax
movq %rax, 0x10(%rsp)
movslq %ebp, %r12
movl 0x4(%rdi), %eax
imulq $0x18, %r12, %r13
pushq $0x12
popq %rbx
xorl %r15d, %r15d
xorl %ebp, %ebp
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq %rbx, 0x18(%rsp)
movq %r15, %r14
cmpq %rcx, %r15
jae 0xd0d5
movl %ebp, %eax
xorl %edx, %edx
movl $0xc350, %esi           # imm = 0xC350
divl %esi
testl %edx, %edx
je 0xd0b2
movq 0x8(%rdi), %rax
movl -0x6(%rax,%rbx), %r8d
testl %r8d, %r8d
js 0xd094
movq -0x12(%rax,%rbx), %rdx
movq %rdx, %rsi
shrq $0x20, %rsi
addl %r8d, %edx
movl -0xa(%rax,%rbx), %ecx
movzwl -0x2(%rax,%rbx), %r10d
movl %r10d, %r9d
shrl $0xe, %r9d
movzbl (%rax,%rbx), %eax
shrl $0xf, %r10d
andl $0x1, %r9d
movq 0x8(%rsp), %rdi
pushq %r10
pushq %rax
callq 0xeaa02
popq %rcx
popq %rdx
addq %r12, %r14
movq (%rsp), %rdi
movl 0x4(%rdi), %eax
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addq %r13, %rbx
incl %ebp
cmpq %rcx, %r14
jb 0xd03c
jmp 0xd0d5
movq 0x287f27(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x22b7ab(%rip), %rsi    # 0x23886e
movl %ebp, %edx
xorl %eax, %eax
callq 0x22b0
movq (%rsp), %rdi
jmp 0xd04b
incq %r15
movq 0x18(%rsp), %rbx
addq $0x18, %rbx
cmpq 0x10(%rsp), %r15
jne 0xd023
movl 0x40(%rsp), %eax
testl %eax, %eax
je 0xd1f2
movl %eax, %eax
movq %rax, 0x58(%rsp)
movl $0xc350, %r14d          # imm = 0xC350
xorl %r13d, %r13d
xorl %ebp, %ebp
movq 0x20(%rdi), %rax
movl %r13d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xd1d9
movq 0x28(%rdi), %rax
movq (%rax,%r13,8), %rax
movq %rax, %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %rcx
je 0xd1d9
movq 0x8(%rdi), %rdx
shrq $0x20, %rax
imulq $0x18, %rcx, %rbx
imulq $0x18, %rax, %rax
leaq (%rdx,%rax), %r12
addq $0x12, %r12
xorl %r15d, %r15d
movl %ebp, %eax
xorl %edx, %edx
divl %r14d
testl %edx, %edx
je 0xd1af
movl -0x6(%r12,%r15), %r8d
testl %r8d, %r8d
js 0xd1a2
movq -0x12(%r12,%r15), %rdx
movq %rdx, %rsi
shrq $0x20, %rsi
addl %r8d, %edx
movl -0xa(%r12,%r15), %ecx
movzwl -0x2(%r12,%r15), %eax
movl %eax, %r9d
shrl $0xe, %r9d
movzbl (%r12,%r15), %r10d
shrl $0xf, %eax
andl $0x1, %r9d
movq 0x8(%rsp), %rdi
pushq %rax
pushq %r10
callq 0xeaa02
popq %rcx
popq %rdx
addq $0x18, %r15
incl %ebp
cmpq %r15, %rbx
jne 0xd151
jmp 0xd1d9
movq 0x287e2a(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
movq (%rsp), %rax
movl 0x4(%rax), %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ecx
leaq 0x22b69f(%rip), %rsi    # 0x23886d
movl %ebp, %edx
xorl %eax, %eax
callq 0x22b0
jmp 0xd15c
incq %r13
cmpq 0x58(%rsp), %r13
movq (%rsp), %rdi
jne 0xd10a
cmpl $0x0, 0x40(%rsp)
jne 0xd252
movq 0x30(%rdi), %rbx
testq %rbx, %rbx
movq 0x8(%rsp), %r15
je 0xd221
movl 0x14(%rdi), %r14d
addl %r14d, %r14d
movq %r14, %rdi
callq 0x2280
movq %rax, 0x30(%r15)
movq %rax, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2160
movq 0x287db8(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x22b6ee(%rip), %rdi    # 0x238920
pushq $0x9
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq %r15, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x68(%rsp)
xorl %r14d, %r14d
movq 0x20(%rdi), %rax
movl %r14d, %ecx
shrl %ecx
movq 0x68(%rsp), %rdx
movl (%rdx,%rcx,8), %edx
xorl (%rax,%rcx,8), %edx
js 0xd63f
movq 0x8(%rdi), %rbx
movq 0x28(%rdi), %rax
movq %r14, 0x48(%rsp)
movq (%rax,%r14,8), %r15
movq %r15, %r14
shrq $0x20, %r14
xorl %ecx, %ecx
movl $0x0, %eax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %r15
je 0xd2d1
imulq $0x18, %r14, %rax
leaq (%rbx,%rax), %rdx
addq $0xc, %rdx
imulq $0x18, %r15, %rsi
xorl %edi, %edi
xorl %eax, %eax
movl (%rdx,%rdi), %r8d
notl %r8d
shrl $0x1f, %r8d
addl %r8d, %eax
addq $0x18, %rdi
cmpq %rdi, %rsi
jne 0xd2ba
movq 0x8(%rsp), %rdx
movq 0x28(%rdx), %rsi
movq 0x48(%rsp), %rdx
movq %rsi, 0x70(%rsp)
movq (%rsi,%rdx,8), %rdx
movq %rdx, %rsi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
andq %rdi, %rsi
je 0xd32c
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x20, %rdx
imulq $0x18, %rdx, %rdx
addq %rcx, %rdx
addq $0xc, %rdx
imulq $0x18, %rsi, %rsi
xorl %edi, %edi
xorl %ecx, %ecx
movl (%rdx,%rdi), %r8d
notl %r8d
shrl $0x1f, %r8d
addl %r8d, %ecx
addq $0x18, %rdi
cmpq %rdi, %rsi
jne 0xd315
cmpl %ecx, %eax
jne 0xd664
testq %r15, %r15
movq (%rsp), %rdi
je 0xd514
imulq $0x18, %r15, %rax
movq %rax, 0x40(%rsp)
imulq $0x18, %r14, %rax
addq %rax, %rbx
addq $0x12, %rbx
xorl %r14d, %r14d
movl -0x6(%rbx,%r14), %r12d
testl %r12d, %r12d
js 0xd3fa
movq -0x12(%rbx,%r14), %r15
movl -0xa(%rbx,%r14), %r13d
movzwl -0x2(%rbx,%r14), %eax
movq %rax, 0x10(%rsp)
movzbl (%rbx,%r14), %eax
movl %eax, 0x18(%rsp)
andq $0x0, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq %r15, %rsi
shrq $0x20, %rsi
movq 0x8(%rsp), %rdi
movl %r13d, %edx
leaq 0x20(%rsp), %rcx
callq 0xea6eb
testl %eax, %eax
je 0xd40e
movl 0x2c(%rsp), %ebp
movb 0x32(%rsp), %al
movzwl 0x30(%rsp), %edx
testl %ebp, %ebp
movq (%rsp), %rdi
js 0xd42c
cmpb %al, 0x18(%rsp)
jne 0xd42c
movq 0x20(%rsp), %rsi
movl 0x28(%rsp), %r8d
cmpl %ebp, %r12d
movq %rsi, 0x60(%rsp)
jne 0xd43b
movl %edx, %ecx
xorl 0x10(%rsp), %ecx
testw %cx, %cx
js 0xd43b
cmpw $0x3fff, %cx            # imm = 0x3FFF
ja 0xd43b
cmpq %rsi, %r15
jne 0xd43b
cmpl %r8d, %r13d
jne 0xd43b
addq $0x18, %r14
cmpq %r14, 0x40(%rsp)
jne 0xd358
jmp 0xd514
movq 0x287bcb(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x2295d4(%rip), %rdi    # 0x2369f3
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xd3af
movq 0x20(%rsp), %rcx
movq %rcx, 0x60(%rsp)
movl 0x28(%rsp), %r8d
movq %r8, 0x80(%rsp)
movl %ebp, %ecx
shrl $0x1f, %ecx
movl %ecx, 0x50(%rsp)
movzbl %al, %eax
movl %eax, 0x54(%rsp)
movq 0x287b86(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x229597(%rip), %rdi    # 0x2369fb
pushq $0x7
popq %rsi
movq %rdx, 0x78(%rsp)
pushq $0x1
popq %rdx
callq 0x2410
movq 0x287b65(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
movq 0x10(%rsp), %r10
movl %r10d, %r8d
shrl $0xf, %r8d
shrl $0xe, %r10d
andl $0x1, %r10d
subq $0x8, %rsp
leaq 0x22b3e8(%rip), %rsi    # 0x238885
xorl %edx, %edx
movl 0x20(%rsp), %ecx
movl %r12d, %r9d
xorl %eax, %eax
pushq %r13
pushq %r15
pushq %r10
callq 0x22b0
addq $0x20, %rsp
movq 0x287b22(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
movq 0x78(%rsp), %rax
movl %eax, %r8d
shrl $0xf, %r8d
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
shrl $0xe, %eax
andl $0x1, %eax
movq %rax, %r10
subq $0x8, %rsp
leaq 0x22b3eb(%rip), %rsi    # 0x2388d2
movl 0x58(%rsp), %edx
movl 0x5c(%rsp), %ecx
movl %ebp, %r9d
xorl %eax, %eax
pushq 0x88(%rsp)
pushq 0x70(%rsp)
pushq %r10
callq 0x22b0
movq 0x20(%rsp), %rdi
addq $0x20, %rsp
jmp 0xd3fa
movq 0x48(%rsp), %rax
movq 0x70(%rsp), %rcx
movq (%rcx,%rax,8), %rax
movq %rax, %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %rcx
je 0xd627
movq 0x8(%rsp), %rdx
movq 0x8(%rdx), %rdx
shrq $0x20, %rax
imulq $0x18, %rcx, %rcx
movq %rcx, 0x10(%rsp)
imulq $0x18, %rax, %rax
leaq (%rdx,%rax), %r14
addq $0x12, %r14
xorl %r15d, %r15d
movl -0x6(%r14,%r15), %ebx
testl %ebx, %ebx
js 0xd5d7
movq -0x12(%r14,%r15), %r12
movl -0xa(%r14,%r15), %ebp
movzwl -0x2(%r14,%r15), %r13d
movb (%r14,%r15), %al
movb %al, 0x18(%rsp)
andq $0x0, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq %r12, %rsi
shrq $0x20, %rsi
movl %ebp, %edx
leaq 0x20(%rsp), %rcx
callq 0xea6eb
testl %eax, %eax
je 0xd606
movl 0x2c(%rsp), %eax
movl %eax, %ecx
xorl %ebx, %ecx
js 0xd5e8
movb 0x18(%rsp), %cl
cmpb 0x32(%rsp), %cl
jne 0xd5e8
cmpl %eax, %ebx
jne 0xd5e8
xorw 0x30(%rsp), %r13w
js 0xd5e8
cmpw $0x3fff, %r13w          # imm = 0x3FFF
ja 0xd5e8
cmpq 0x20(%rsp), %r12
jne 0xd5e8
cmpl 0x28(%rsp), %ebp
jne 0xd5e8
movq (%rsp), %rdi
addq $0x18, %r15
cmpq %r15, 0x10(%rsp)
jne 0xd558
jmp 0xd627
movq 0x2879f1(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x22941c(%rip), %rdi    # 0x236a15
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xd5d3
movq 0x2879d3(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x2293ec(%rip), %rdi    # 0x236a03
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xd59e
movq 0x48(%rsp), %r14
incq %r14
cmpq 0x58(%rsp), %r14
jne 0xd263
jmp 0xd1f2
movq 0x28799a(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x2291dc(%rip), %rdi    # 0x23682c
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq (%rsp), %rdi
jmp 0xd27d
movq 0x287975(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x2291bf(%rip), %rdi    # 0x236834
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xd334