// File: /workspace/github_cpp_makefile_star2_O2/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 $0x78, %rsp
movl %esi, %ebx
movq %rdi, %r14
xorl %r15d, %r15d
callq 0x68f5d
movq %r14, %rdx
movq %rax, %r14
movq %rdx, 0x8(%rsp)
movl 0x14(%rdx), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %r15
jae 0xb2682
movq 0x20(%rdx), %rax
movl (%rax,%r15,8), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
shrl $0x1f, %ecx
movq %r14, %rdi
movl %r15d, %esi
callq 0x69316
movq 0x8(%rsp), %rdx
movq 0x20(%rdx), %rax
movb 0x4(%rax,%r15,8), %al
movq 0x20(%r14), %rcx
movb %al, 0x4(%rcx,%r15,8)
incq %r15
jmp 0xb263b
movq %r14, (%rsp)
movq %r14, %rdi
movq %rdx, %r14
callq 0x694eb
movl 0x14(%r14), %eax
movq %rax, 0x40(%rsp)
movl %ebx, %eax
movq %rax, 0x48(%rsp)
movslq %ebx, %rbx
imulq $0x18, %rbx, %r12
pushq $0x12
popq %r13
movl $0xc350, %r15d          # imm = 0xC350
xorl %ebp, %ebp
xorl %eax, %eax
movq %r13, 0x18(%rsp)
movq %rax, %r14
movq %rax, 0x10(%rsp)
cmpq 0x48(%rsp), %rax
je 0xb277d
movl %ebp, %eax
xorl %edx, %edx
divl %r15d
movq 0x8(%rsp), %rdx
movl 0x4(%rdx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %r14
jae 0xb2767
imull $0xc350, %eax, %eax     # imm = 0xC350
cmpl %ebp, %eax
je 0xb2746
movq 0x8(%rdx), %rax
movl -0x6(%rax,%r13), %r8d
testl %r8d, %r8d
js 0xb273c
movq -0x12(%rax,%r13), %rdx
movq %rdx, %rsi
shrq $0x20, %rsi
addl %r8d, %edx
movl -0xa(%rax,%r13), %ecx
movzwl -0x2(%rax,%r13), %r10d
movl %r10d, %r9d
shrl $0xe, %r9d
movzbl (%rax,%r13), %eax
shrl $0xf, %r10d
andl $0x1, %r9d
movq (%rsp), %rdi
pushq %r10
pushq %rax
callq 0xac072
popq %rcx
popq %rdx
addq %rbx, %r14
addq %r12, %r13
incl %ebp
jmp 0xb26ce
movq 0x1a0893(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0x138017(%rip), %rsi    # 0x1ea76e
movl %ebp, %edx
xorl %eax, %eax
callq 0x22b0
movq 0x8(%rsp), %rdx
jmp 0xb26f2
movq 0x10(%rsp), %rax
incq %rax
movq 0x18(%rsp), %r13
addq $0x18, %r13
jmp 0xb26b6
movq 0x40(%rsp), %rax
addl %eax, %eax
movq %rax, 0x40(%rsp)
movl $0xc350, %ebx           # imm = 0xC350
xorl %r12d, %r12d
xorl %ebp, %ebp
movq (%rsp), %r14
movq 0x8(%rsp), %rdi
cmpq 0x40(%rsp), %r12
je 0xb2881
movq 0x20(%rdi), %rax
movl %r12d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xb2879
movq 0x8(%rdi), %rax
movq 0x28(%rdi), %rcx
movq (%rcx,%r12,8), %rcx
movl %ecx, %edx
shrq $0x20, %rcx
imulq $0x18, %rdx, %r13
imulq $0x18, %rcx, %rcx
leaq (%rax,%rcx), %r14
addq $0x12, %r14
xorl %r15d, %r15d
movl %ebp, %eax
xorl %edx, %edx
divl %ebx
cmpq %r15, %r13
je 0xb2870
imull $0xc350, %eax, %eax     # imm = 0xC350
cmpl %ebp, %eax
je 0xb2845
movl -0x6(%r14,%r15), %r8d
testl %r8d, %r8d
js 0xb283d
movq -0x12(%r14,%r15), %rdx
movq %rdx, %rsi
shrq $0x20, %rsi
addl %r8d, %edx
movl -0xa(%r14,%r15), %ecx
movzwl -0x2(%r14,%r15), %eax
movl %eax, %r9d
shrl $0xe, %r9d
movzbl (%r14,%r15), %r10d
shrl $0xf, %eax
andl $0x1, %r9d
movq (%rsp), %rdi
pushq %rax
pushq %r10
callq 0xac072
popq %rcx
popq %rdx
addq $0x18, %r15
incl %ebp
jmp 0xb27df
movq 0x1a0794(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
movq 0x8(%rsp), %rax
movl 0x4(%rax), %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ecx
leaq 0x137f08(%rip), %rsi    # 0x1ea76d
movl %ebp, %edx
xorl %eax, %eax
callq 0x22b0
jmp 0xb27f8
movq (%rsp), %r14
movq 0x8(%rsp), %rdi
incq %r12
jmp 0xb279c
xorl %r13d, %r13d
cmpq 0x40(%rsp), %r13
je 0xb2c09
movq 0x20(%rdi), %rax
movl %r13d, %ecx
shrl %ecx
movq %rdi, %rbx
movq 0x20(%r14), %rdx
movl (%rdx,%rcx,8), %edx
xorl (%rax,%rcx,8), %edx
movq %r14, %r12
js 0xb2bc7
movq 0x8(%rbx), %r14
movq 0x28(%rbx), %rax
movq (%rax,%r13,8), %r15
movq %rbx, %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0xc2e7a
movl %eax, %ebx
movq %r12, %rdi
movq %r13, 0x58(%rsp)
movl %r13d, %esi
xorl %edx, %edx
callq 0xc2e7a
cmpl %eax, %ebx
jne 0xb2be8
movq %r15, %rax
shrq $0x20, %rax
movl %r15d, %ecx
imulq $0x18, %rcx, %rcx
movq %rcx, 0x48(%rsp)
imulq $0x18, %rax, %rax
addq %rax, %r14
addq $0x12, %r14
xorl %ebx, %ebx
cmpq %rbx, 0x48(%rsp)
je 0xb2aae
movl -0x6(%r14,%rbx), %r13d
testl %r13d, %r13d
js 0xb29aa
movq -0x12(%r14,%rbx), %r15
movl -0xa(%r14,%rbx), %ebp
movzwl -0x2(%r14,%rbx), %eax
movq %rax, 0x10(%rsp)
movzbl (%r14,%rbx), %eax
movl %eax, 0x18(%rsp)
andq $0x0, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq %r15, %rsi
shrq $0x20, %rsi
movq (%rsp), %rdi
movl %ebp, %edx
leaq 0x20(%rsp), %rcx
callq 0xabd97
testl %eax, %eax
je 0xb29b3
movl 0x2c(%rsp), %r12d
movb 0x32(%rsp), %al
movzwl 0x30(%rsp), %edx
testl %r12d, %r12d
js 0xb29d1
cmpb %al, 0x18(%rsp)
jne 0xb29d1
movq 0x20(%rsp), %rsi
movl 0x28(%rsp), %edi
cmpl %r12d, %r13d
movq %rsi, 0x60(%rsp)
jne 0xb29df
movl %edx, %ecx
xorl 0x10(%rsp), %ecx
testw %cx, %cx
js 0xb29df
cmpw $0x3fff, %cx            # imm = 0x3FFF
ja 0xb29df
cmpq %rsi, %r15
jne 0xb29df
cmpl %edi, %ebp
jne 0xb29df
addq $0x18, %rbx
jmp 0xb2903
movq 0x1a0626(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x135f2f(%rip), %rdi    # 0x1e88f3
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xb2963
movq 0x20(%rsp), %rcx
movq %rcx, 0x60(%rsp)
movl 0x28(%rsp), %edi
movq %rdi, 0x70(%rsp)
movl %r12d, %ecx
shrl $0x1f, %ecx
movl %ecx, 0x50(%rsp)
movzbl %al, %eax
movl %eax, 0x54(%rsp)
movq 0x1a05e4(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x135ef5(%rip), %rdi    # 0x1e88fb
pushq $0x7
popq %rsi
movq %rdx, 0x68(%rsp)
pushq $0x1
popq %rdx
callq 0x2410
movq 0x1a05c3(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
movq 0x10(%rsp), %r10
movl %r10d, %r8d
shrl $0xf, %r8d
shrl $0xe, %r10d
andl $0x1, %r10d
subq $0x8, %rsp
leaq 0x137d46(%rip), %rsi    # 0x1ea785
xorl %edx, %edx
movl 0x20(%rsp), %ecx
movl %r13d, %r9d
xorl %eax, %eax
pushq %rbp
pushq %r15
pushq %r10
callq 0x22b0
addq $0x20, %rsp
movq 0x1a0581(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
movq 0x68(%rsp), %rax
movl %eax, %r8d
shrl $0xf, %r8d
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
shrl $0xe, %eax
andl $0x1, %eax
movq %rax, %r10
subq $0x8, %rsp
leaq 0x137d49(%rip), %rsi    # 0x1ea7d2
movl 0x58(%rsp), %edx
movl 0x5c(%rsp), %ecx
movl %r12d, %r9d
xorl %eax, %eax
pushq 0x78(%rsp)
pushq 0x70(%rsp)
pushq %r10
callq 0x22b0
addq $0x20, %rsp
jmp 0xb29aa
movq (%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movq 0x58(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %edx
shrq $0x20, %rcx
imulq $0x18, %rdx, %rdx
movq %rdx, 0x10(%rsp)
imulq $0x18, %rcx, %rcx
leaq (%rax,%rcx), %r14
addq $0x12, %r14
xorl %r15d, %r15d
movq 0x8(%rsp), %rdi
cmpq %r15, 0x10(%rsp)
je 0xb2bb6
movl -0x6(%r14,%r15), %ebx
testl %ebx, %ebx
js 0xb2b71
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 0xabd97
testl %eax, %eax
je 0xb2b98
movl 0x2c(%rsp), %eax
movl %eax, %ecx
xorl %ebx, %ecx
js 0xb2b7a
movb 0x18(%rsp), %cl
cmpb 0x32(%rsp), %cl
jne 0xb2b7a
cmpl %eax, %ebx
jne 0xb2b7a
xorw 0x30(%rsp), %r13w
js 0xb2b7a
cmpw $0x3fff, %r13w          # imm = 0x3FFF
ja 0xb2b7a
cmpq 0x20(%rsp), %r12
jne 0xb2b7a
cmpl 0x28(%rsp), %ebp
jne 0xb2b7a
movq 0x8(%rsp), %rdi
addq $0x18, %r15
jmp 0xb2ae6
movq 0x1a045f(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x135d8a(%rip), %rdi    # 0x1e8915
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xb2b6c
movq 0x1a0441(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x135d5a(%rip), %rdi    # 0x1e8903
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xb2b37
movq 0x58(%rsp), %r13
incq %r13
movq (%rsp), %r14
jmp 0xb2884
movq 0x1a0412(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x135b54(%rip), %rdi    # 0x1e872c
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xb28ae
movq 0x1a03f1(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x135b3b(%rip), %rdi    # 0x1e8734
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xb28e3
movq 0x30(%rdi), %rbx
testq %rbx, %rbx
je 0xb2c3b
movl 0x14(%rdi), %r14d
addl %r14d, %r14d
movq %r14, %rdi
callq 0x2280
movq (%rsp), %rcx
movq %rax, 0x30(%rcx)
movq %rax, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq (%rsp), %r14
callq 0x2160
movq 0x1a039e(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x137bd4(%rip), %rdi    # 0x1ea820
pushq $0x9
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq %r14, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq