// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %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 0xd086
movq %rbx, %rdx
xorl %ebx, %ebx
movq 0x20(%rdx), %rax
movl (%rax,%rbx,8), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
shrl $0x1f, %ecx
movq %r14, %rdi
movl %ebx, %esi
callq 0xa0115
movq (%rsp), %rdx
movq 0x20(%rdx), %rax
movb 0x4(%rax,%rbx,8), %al
movq 0x20(%r14), %rcx
movb %al, 0x4(%rcx,%rbx,8)
incq %rbx
movl 0x14(%rdx), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %rbx
jb 0xd046
movq %r14, 0x8(%rsp)
movq %r14, %rdi
callq 0xa02fa
movq (%rsp), %r9
movl 0x14(%r9), %eax
addl %eax, %eax
movl %eax, 0x40(%rsp)
testl %ebp, %ebp
je 0xd18c
movl %ebp, %eax
movq %rax, 0x10(%rsp)
movslq %ebp, %r12
imulq $0x18, %r12, %r13
pushq $0x12
popq %rbx
xorl %r15d, %r15d
xorl %ebp, %ebp
movl 0x4(%r9), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq %rbx, 0x18(%rsp)
movq %r15, %r14
cmpq %rcx, %r15
jae 0xd175
movl %ebp, %eax
xorl %edx, %edx
movl $0xc350, %esi           # imm = 0xC350
divl %esi
testl %edx, %edx
je 0xd152
movq 0x8(%r9), %rax
movl -0x6(%rax,%rbx), %r8d
testl %r8d, %r8d
js 0xd139
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 0xe907b
movq 0x10(%rsp), %r9
addq $0x10, %rsp
addq %r12, %r14
movl 0x4(%r9), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addq %r13, %rbx
incl %ebp
cmpq %rcx, %r14
jb 0xd0da
jmp 0xd175
movq 0x27ce87(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0x21f51b(%rip), %rsi    # 0x22c67e
movl %ebp, %edx
xorl %eax, %eax
callq 0x22b0
movq (%rsp), %r9
jmp 0xd0e9
incq %r15
movq 0x18(%rsp), %rbx
addq $0x18, %rbx
cmpq 0x10(%rsp), %r15
jne 0xd0bf
movl 0x40(%rsp), %eax
testl %eax, %eax
jne 0xd1f1
movq 0x30(%r9), %rbx
testq %rbx, %rbx
movq 0x8(%rsp), %r15
je 0xd1c3
movl 0x14(%r9), %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 0x27ce16(%rip), %rax    # 0x289fe0
movq (%rax), %rcx
leaq 0x21f55c(%rip), %rdi    # 0x22c730
pushq $0x9
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq %r15, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %eax
movq %rax, 0x50(%rsp)
movl $0xc350, %r14d          # imm = 0xC350
xorl %r13d, %r13d
xorl %ebp, %ebp
movq 0x20(%r9), %rax
movl %r13d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xd2dd
movq 0x28(%r9), %rax
movq (%rax,%r13,8), %rax
movq %rax, %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %rcx
je 0xd2dd
movq 0x8(%r9), %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 0xd2af
movl -0x6(%r12,%r15), %r8d
testl %r8d, %r8d
js 0xd2a2
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 0xe907b
movq 0x10(%rsp), %r9
addq $0x10, %rsp
addq $0x18, %r15
incl %ebp
cmpq %r15, %rbx
jne 0xd24a
jmp 0xd2dd
movq 0x27cd2a(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
movl 0x4(%r9), %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ecx
leaq 0x21f3b2(%rip), %rsi    # 0x22c67d
movl %ebp, %edx
xorl %eax, %eax
callq 0x22b0
movq (%rsp), %r9
jmp 0xd255
incq %r13
cmpq 0x50(%rsp), %r13
jne 0xd203
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x58(%rsp)
xorl %r14d, %r14d
movq 0x20(%r9), %rax
movl %r14d, %ecx
shrl %ecx
movq 0x58(%rsp), %rdx
movl (%rdx,%rcx,8), %edx
xorl (%rax,%rcx,8), %edx
js 0xd6b6
movq 0x8(%r9), %rbx
movq 0x28(%r9), %rax
movq %r14, 0x38(%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 0xd36a
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 0xd353
movq 0x8(%rsp), %rdx
movq 0x28(%rdx), %rsi
movq 0x38(%rsp), %rdx
movq %rsi, 0x60(%rsp)
movq (%rsi,%rdx,8), %rdx
movq %rdx, %rsi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
andq %rdi, %rsi
je 0xd3c5
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 0xd3ae
cmpl %ecx, %eax
jne 0xd6db
testq %r15, %r15
je 0xd588
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 0xd484
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 0xe8d4c
testl %eax, %eax
je 0xd567
movl 0x2c(%rsp), %ebp
movb 0x32(%rsp), %al
testl %ebp, %ebp
movq (%rsp), %r9
js 0xd498
cmpb %al, 0x18(%rsp)
jne 0xd498
cmpl %ebp, %r12d
jne 0xd498
movzwl 0x30(%rsp), %ecx
xorw 0x10(%rsp), %cx
js 0xd498
cmpw $0x3fff, %cx            # imm = 0x3FFF
ja 0xd498
cmpq 0x20(%rsp), %r15
jne 0xd498
cmpl 0x28(%rsp), %r13d
jne 0xd498
addq $0x18, %r14
cmpq %r14, 0x40(%rsp)
jne 0xd3ed
jmp 0xd588
movl %ebp, %ecx
shrl $0x1f, %ecx
movl %ecx, 0x48(%rsp)
movzbl %al, %eax
movl %eax, 0x4c(%rsp)
movq 0x27cb31(%rip), %rax    # 0x289fe0
movq (%rax), %rcx
leaq 0x21d352(%rip), %rdi    # 0x22a80b
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq 0x27cb15(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
movq 0x10(%rsp), %r10
movl %r10d, %r8d
shrl $0xf, %r8d
shrl $0xe, %r10d
andl $0x1, %r10d
subq $0x8, %rsp
leaq 0x21f1a8(%rip), %rsi    # 0x22c695
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 0x27cad2(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
movzwl 0x30(%rsp), %r10d
movl %r10d, %r8d
shrl $0xf, %r8d
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
shrl $0xe, %r10d
andl $0x1, %r10d
movl 0x20(%rsp), %r11d
movl 0x28(%rsp), %r15d
subq $0x8, %rsp
leaq 0x21f1a1(%rip), %rsi    # 0x22c6e2
movl 0x50(%rsp), %edx
movl 0x54(%rsp), %ecx
movl %ebp, %r9d
xorl %eax, %eax
pushq %r15
pushq %r11
pushq %r10
callq 0x22b0
movq 0x20(%rsp), %r9
addq $0x20, %rsp
jmp 0xd484
movq 0x27ca72(%rip), %rax    # 0x289fe0
movq (%rax), %rcx
leaq 0x21d28b(%rip), %rdi    # 0x22a803
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xd448
movq 0x38(%rsp), %rax
movq 0x60(%rsp), %rcx
movq (%rcx,%rax,8), %rax
movq %rax, %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %rcx
je 0xd69e
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 0xd64e
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
movq %r9, %rdi
movl %ebp, %edx
leaq 0x20(%rsp), %rcx
callq 0xe8d4c
testl %eax, %eax
je 0xd67d
movl 0x2c(%rsp), %eax
movl %eax, %ecx
xorl %ebx, %ecx
js 0xd65f
movb 0x18(%rsp), %cl
cmpb 0x32(%rsp), %cl
jne 0xd65f
cmpl %eax, %ebx
jne 0xd65f
xorw 0x30(%rsp), %r13w
js 0xd65f
cmpw $0x3fff, %r13w          # imm = 0x3FFF
ja 0xd65f
cmpq 0x20(%rsp), %r12
jne 0xd65f
cmpl 0x28(%rsp), %ebp
jne 0xd65f
movq (%rsp), %r9
addq $0x18, %r15
cmpq %r15, 0x10(%rsp)
jne 0xd5cc
jmp 0xd69e
movq 0x27c97a(%rip), %rax    # 0x289fe0
movq (%rax), %rcx
leaq 0x21d1b5(%rip), %rdi    # 0x22a825
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xd64a
movq 0x27c95c(%rip), %rax    # 0x289fe0
movq (%rax), %rcx
leaq 0x21d185(%rip), %rdi    # 0x22a813
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xd615
movq 0x38(%rsp), %r14
incq %r14
cmpq 0x50(%rsp), %r14
jne 0xd2fc
jmp 0xd194
movq 0x27c923(%rip), %rax    # 0x289fe0
movq (%rax), %rcx
leaq 0x21cf75(%rip), %rdi    # 0x22a63c
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq (%rsp), %r9
jmp 0xd316
movq 0x27c8fe(%rip), %rax    # 0x289fe0
movq (%rax), %rcx
leaq 0x21cf58(%rip), %rdi    # 0x22a644
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq (%rsp), %r9
jmp 0xd3cd