// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]oatk/path.c
// Function: make_seg_dups
static void make_seg_dups(asg_t *asg, kh_u32_t *seg_dups, uint32_t s, uint32_t copy)
{
    // copy number include sequence itself
    // i.e., make 'copy' copies and remove the original
    // FIXME arcs involving self cycles are not copied since it will potentially cause problems
    // for example
    // in a graph containing path (X+)<->(a+,b+,b+,c+)<->(Y+)
    // the self cycle b+,b+ will increase the ambiguities of the path selection
    // valid path including
    // (X+)->(a+,b+,b+,c+)->(Y+)->(a-,b-,b-,c-)
    // (X+)->(a+,b+,b+,b+,c+)->(Y+)->(a-,b-,c-)
    // TODO solve the copy number of self cycles in postprocessing
    // now the self arcs is processed in this way
    // (X+)->(a+)[4]->(Y+) => (X+)->(a0+) ->(a1+) ->(a2+) ->(a3+) ->(Y+)
    //                            ->(a1+) ->(a2+) ->(a0+) ->(a1+) ->(a0+)
    //                            ->(a2+) ->(a3+) ->(a3+) ->(a2+) ->(a1+)
    //                            ->(a3+) ->(Y+)  ->(Y+)  ->(Y+)  ->(a2+)
    // (a+)->(a-) arcs are not copied
    uint32_t sid;
    uint64_t i, j, v, nv, pv, self_arc;
    kvec_t(uint64_t) arcs_diff;
    asmg_t *g;
    asmg_arc_t *av;
    asmg_vtx_t *vt;
    char *name;
    asg_seg_t *seg, *seg_c;
    khint32_t k;
    int absent;

    g = asg->asmg;
    // mark arcs from vtx
    kv_init(arcs_diff);
    self_arc = UINT64_MAX;

    for (i = 0; i < 2; ++i) {
        v = s<<1 | i;
        pv = g->idx_p[v];
        nv = asmg_arc_n(g, v);
        av = asmg_arc_a(g, v);
        for (j = 0; j < nv; ++j) {
            if (av[j].del) continue;
            if ((av[j].v >> 1) != (av[j].w >> 1))
                kv_push(uint64_t, arcs_diff, pv+j);
            else if (av[j].v == av[j].w && i == 0)
                // (a+)->(a+)
                // avoid adding v+->v+ and v-->v- twice
                self_arc = pv + j;
        }
    }

    for (i = 0; i < copy; ++i) {
        // make a copy of the segment
        seg = &asg->seg[s];
        MYMALLOC(name, strlen(seg->name) + floor(log10(abs(i + 1))) + 7);
        sprintf(name, "%s_copy%lu", seg->name, i);
        sid = asg_add_seg(asg, name, 0);
        free(name);
        // add to seg dups map
        k = kh_u32_put(seg_dups, sid, &absent);
        kh_val(seg_dups, k) = s;
        // only copy essential fields
        seg = &asg->seg[s]; // need to redo this as the seg might be reallocated
        seg_c = &asg->seg[sid];
        seg_c->len = seg->len;
        seg_c->cov = seg->cov;

        // add vtx
        asmg_vtx_addp(g, &vt);
        MYBZERO(vt, 1);
        vt->len = seg->len;
        // using vtx coverage instead of seg coverage
        //vt->cov = seg->cov / copy;
        vt->cov = g->vtx[s].cov / copy;

        // make copies of links
        // arc cov already changed
        for (j = 0; j < arcs_diff.n; ++j) {
            av = &g->arc[arcs_diff.a[j]];
            asmg_arc_add2(g, sid << 1 | (av->v&1), av->w, av->ln, av->ls, UINT64_MAX, av->cov / copy, av->comp);
        }
        
        if (self_arc != UINT64_MAX) {
            // tandem repeat
            // self arcs are added between copies
            av = &g->arc[self_arc];
            for (j = 0; j < i; ++j) {
                asmg_arc_add2(g, (sid - i + j) << 1, sid << 1, av->ln, av->ls, UINT64_MAX, av->cov / copy, 0);
                asmg_arc_add2(g, sid << 1, (sid - i + j) << 1, av->ln, av->ls, UINT64_MAX, av->cov / copy, 0);
            }
        }
    }

    kv_destroy(arcs_diff);

    // need to redo sort and index but not graph clean
    asmg_finalize(g, 0);

    // delete the original vtx
    asmg_vtx_del(g, s, 1);

    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x58(%rbp)
movq $-0x1, -0x50(%rbp)
movq $0x0, -0x28(%rbp)
cmpq $0x2, -0x28(%rbp)
jae 0x621c
movl -0x14(%rbp), %eax
shll %eax
movl %eax, %eax
orq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x70(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movq -0x70(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movq -0x70(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x70(%rbp), %rcx
movq 0x30(%rcx), %rcx
movq -0x38(%rbp), %rdx
imulq $0x30, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x6209
movq -0x78(%rbp), %rax
imulq $0x30, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x6124
jmp 0x61f8
movq -0x78(%rbp), %rax
imulq $0x30, -0x30(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq %rax
movq -0x78(%rbp), %rcx
imulq $0x30, -0x30(%rbp), %rdx
addq %rdx, %rcx
movq 0x8(%rcx), %rcx
shrq %rcx
cmpq %rcx, %rax
je 0x61c0
jmp 0x6150
movq -0x68(%rbp), %rax
cmpq -0x60(%rbp), %rax
jne 0x619f
cmpq $0x0, -0x60(%rbp)
je 0x6171
movq -0x60(%rbp), %rax
shlq %rax
movq %rax, -0xa8(%rbp)
jmp 0x617f
movl $0x2, %eax
movq %rax, -0xa8(%rbp)
jmp 0x617f
movq -0xa8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rsi
shlq $0x3, %rsi
callq 0x2330
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rdx
addq -0x30(%rbp), %rdx
movq -0x58(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x68(%rbp)
movq %rdx, (%rax,%rcx,8)
jmp 0x61f6
movq -0x78(%rbp), %rax
imulq $0x30, -0x30(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x78(%rbp), %rcx
imulq $0x30, -0x30(%rbp), %rdx
addq %rdx, %rcx
cmpq 0x8(%rcx), %rax
jne 0x61f4
cmpq $0x0, -0x28(%rbp)
jne 0x61f4
movq -0x48(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x61f6
jmp 0x61f8
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x60f7
jmp 0x620b
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x608d
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl -0x18(%rbp), %ecx
cmpq %rcx, %rax
jae 0x6602
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x14(%rbp), %ecx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq (%rax), %rdi
callq 0x2130
movq %rax, %xmm0
movaps 0x1d307(%rip), %xmm1    # 0x23570
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x1d30b(%rip), %xmm1    # 0x23580
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0xb0(%rbp)
movl -0x28(%rbp), %eax
incl %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cvtsi2sd %eax, %xmm0
callq 0x2270
callq 0x23e0
movaps %xmm0, %xmm1
movsd -0xb0(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd 0x1d23b(%rip), %xmm1    # 0x234f8
addsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rdi
movq %rdi, %rcx
sarq $0x3f, %rcx
movsd 0x1d1c8(%rip), %xmm1    # 0x234a0
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
andq %rcx, %rax
orq %rax, %rdi
callq 0x22f0
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
movq -0x90(%rbp), %rax
movq (%rax), %rdx
movq -0x28(%rbp), %rcx
leaq 0x1de51(%rip), %rsi     # 0x24160
movb $0x0, %al
callq 0x2420
movq -0x8(%rbp), %rdi
movq -0x88(%rbp), %rsi
xorl %edx, %edx
callq 0xb300
movl %eax, -0x1c(%rbp)
movq -0x88(%rbp), %rdi
callq 0x2060
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq -0xa0(%rbp), %rdx
callq 0x13ae0
movl %eax, -0x9c(%rbp)
movl -0x14(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x9c(%rbp), %ecx
movl %edx, 0x4(%rax,%rcx,8)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x14(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x98(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x90(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x98(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x70(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x13b10
movq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x21c0
movq -0x90(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %ecx
movq -0x80(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x70(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x14(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
xorl %edx, %edx
divl -0x18(%rbp)
movl %eax, %edx
movq -0x80(%rbp), %rax
movl 0x20(%rax), %ecx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl %edx, %ecx
movl %ecx, 0x20(%rax)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x68(%rbp), %rax
jae 0x64df
movq -0x70(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x58(%rbp), %rcx
movq -0x30(%rbp), %rdx
imulq $0x30, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
movl -0x1c(%rbp), %eax
shll %eax
movl %eax, %eax
movl %eax, %esi
movq -0x78(%rbp), %rax
movq (%rax), %rax
andq $0x1, %rax
orq %rax, %rsi
movq -0x78(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xb8(%rbp)
movq -0x78(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x78(%rbp), %rax
movq 0x18(%rax), %r8
movq -0x78(%rbp), %rax
movl 0x20(%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
xorl %edx, %edx
divl -0x18(%rbp)
movq -0xb8(%rbp), %rdx
movl %eax, %r10d
movq -0x78(%rbp), %rax
movl 0x20(%rax), %eax
shrl $0x1f, %eax
movq $-0x1, %r9
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x13c50
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x6431
cmpq $-0x1, -0x50(%rbp)
je 0x65ef
movq -0x70(%rbp), %rax
movq 0x28(%rax), %rax
imulq $0x30, -0x50(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x65ed
movq -0x70(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
subq -0x28(%rbp), %rsi
addq -0x30(%rbp), %rsi
shlq %rsi
movl -0x1c(%rbp), %eax
shll %eax
movl %eax, %eax
movq %rax, -0xc8(%rbp)
movq -0x78(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x78(%rbp), %rax
movq 0x18(%rax), %r8
movq -0x78(%rbp), %rax
movl 0x20(%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
xorl %edx, %edx
divl -0x18(%rbp)
movq -0xc8(%rbp), %rdx
movq $-0x1, %r9
xorl %r10d, %r10d
movl %eax, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x13c50
movq -0x70(%rbp), %rdi
movl -0x1c(%rbp), %eax
shll %eax
movl %eax, %eax
movl %eax, %esi
movl -0x1c(%rbp), %eax
subq -0x28(%rbp), %rax
addq -0x30(%rbp), %rax
shlq %rax
movq %rax, -0xc0(%rbp)
movq -0x78(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x78(%rbp), %rax
movq 0x18(%rax), %r8
movq -0x78(%rbp), %rax
movl 0x20(%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
xorl %edx, %edx
divl -0x18(%rbp)
movq -0xc0(%rbp), %rdx
movq $-0x1, %r9
xorl %r10d, %r10d
movl %eax, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x13c50
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x6506
jmp 0x65ef
jmp 0x65f1
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x6224
movq -0x58(%rbp), %rdi
callq 0x2060
movq -0x70(%rbp), %rdi
xorl %esi, %esi
callq 0x18500
movq -0x70(%rbp), %rdi
movl -0x14(%rbp), %eax
movl %eax, %esi
movl $0x1, %edx
callq 0x6640
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)