// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]oatk/path_finder.c
// Function: extract_minicircles_with_anchor
static int extract_minicircles_with_anchor(scg_ra_v *ra, scg_t *scg, uint64_t anchor_sid, int n_threads, path_v *paths)
{
    uint64_t i, j, k, nr, *mcs;
    
    nr = ra->n;
    MYMALLOC(mcs, nr);
    mc_shared_t mc_shared = {ra, anchor_sid, mcs};
    kt_for(n_threads, minicircle_analysis_thread, &mc_shared, nr);

    for (i = 0; i < nr; ++i) {
        if (mcs[i] == UINT64_MAX) continue;
        scg_ra_t *r = &ra->a[i];
#ifdef DEBUG_MINICIRCLE_REPEAT_UNIT
        scg_ra_print(r, stderr);
        fprintf(stderr, "[DEBUG_MINICIRCLE_REPEAT_UNIT::%s] repeat unit: beg %lu; end %u; %c\n", __func__, 
                mcs[i]>>33, (uint32_t) (mcs[i]>>1), "+-"[mcs[i]&1]);
#endif
        // collect paths
        kvec_t(uint32_t) vt;
        kv_init(vt);
        uint32_t n;
        for (j = (mcs[i]>>33), n = (uint32_t) (mcs[i]>>1); j <= n; ++j)
            kv_push(uint32_t, vt, (uint32_t) (r->a[j].uid));
        if (mcs[i]&1) {
            // do reverse complement
            rev_array(vt.a+1, vt.n-1);
            for (j = 0; j < vt.n; ++j)
                vt.a[j] ^= 1;
        }
    
        path_t path = {0, vt.n, 1, 0, vt.a, 0, 0., 0.};
        kv_push(path_t, *paths, path);
    }
    free(mcs);

    if (paths->n == 0) return 0;

    // sort paths and remove duplicates
    qsort(paths->a, paths->n, sizeof(path_t), path_cmpfunc);
    j = 0;
    k = 1;
    for (i = 1; i < paths->n; ++i) {
        int c = path_cmpfunc(&paths->a[i], &paths->a[j]);
        if (c == 0) {
            free(paths->a[i].v);
            --k;
        } else {
            if (k != i)
                paths->a[k] = paths->a[i];
            j = k;
        }
        ++k;
    }
    paths->n = k;

    // now update path info
    uint32_t nv, len, len1, cov, *vt;
    double wlen;
    asmg_t *g;
    asmg_arc_t *a;
    
    g = scg->utg_asmg;
    for (i = 0; i < paths->n; ++i) {
        path_t *path = &paths->a[i];
        nv = path->nv;
        vt = path->v;
        
        a = asmg_arc1(g, vt[nv-1], vt[0]);
        assert(!!a); // should always be a circle
        len = g->vtx[vt[0]>>1].len;
        cov = g->vtx[vt[0]>>1].cov;
        wlen = (double) cov * len;
        len -= a->ls, wlen -= cov * a->ls; // circular path
        
        for (j = 1; j < nv; ++j) {
            len1 = g->vtx[vt[j]>>1].len;
            cov = g->vtx[vt[j]>>1].cov;
            len += len1;
            wlen += (double) cov * len1;
            a = asmg_arc1(g, vt[j-1], vt[j]);
            assert(!!a);
            len -= a->ls;
            wlen -= (double) cov * a->ls;
        }

        path->len = len;
        path->wlen = wlen;
    }

    return paths->n;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
shlq $0x3, %rdi
callq 0x33b0
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x24(%rbp), %edi
movq -0x50(%rbp), %rcx
leaq 0x7a0(%rip), %rsi       # 0xafe0
leaq -0x70(%rbp), %rdx
callq 0x49f60
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0xab28
movq -0x58(%rbp), %rax
movq -0x38(%rbp), %rcx
cmpq $-0x1, (%rax,%rcx,8)
jne 0xa873
jmp 0xab17
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x90(%rbp)
movq $0x0, -0x80(%rbp)
movq -0x58(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movq %rax, -0x40(%rbp)
movq -0x58(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq %rax
movl %eax, -0x94(%rbp)
movq -0x40(%rbp), %rax
movl -0x94(%rbp), %ecx
cmpq %rcx, %rax
ja 0xa98e
jmp 0xa8e6
movq -0x90(%rbp), %rax
cmpq -0x88(%rbp), %rax
jne 0xa947
cmpq $0x0, -0x88(%rbp)
je 0xa913
movq -0x88(%rbp), %rax
shlq %rax
movq %rax, -0x110(%rbp)
jmp 0xa921
movl $0x2, %eax
movq %rax, -0x110(%rbp)
jmp 0xa921
movq -0x110(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rsi
shlq $0x2, %rsi
callq 0x33f0
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, %edx
movq -0x80(%rbp), %rax
movq -0x90(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x90(%rbp)
movl %edx, (%rax,%rcx,4)
jmp 0xa97d
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xa8d1
movq -0x58(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0xa9f4
movq -0x80(%rbp), %rdi
addq $0x4, %rdi
movq -0x90(%rbp), %rax
subq $0x1, %rax
movl %eax, %esi
callq 0xb230
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x90(%rbp), %rax
jae 0xa9f2
movq -0x80(%rbp), %rax
movq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %edx
xorl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xa9c6
jmp 0xa9f4
movq $0x0, -0xc8(%rbp)
movq -0x90(%rbp), %rax
movl %eax, %ecx
movl -0xc0(%rbp), %eax
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
andl $0xc0000000, %eax       # imm = 0xC0000000
orl %ecx, %eax
movl %eax, -0xc0(%rbp)
movl -0xc0(%rbp), %eax
andl $0xbfffffff, %eax       # imm = 0xBFFFFFFF
orl $0x40000000, %eax       # imm = 0x40000000
movl %eax, -0xc0(%rbp)
movl -0xc0(%rbp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
orl $0x0, %eax
movl %eax, -0xc0(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl $0x0, -0xb0(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xa8(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xa0(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0xaae4
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xaaa6
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x118(%rbp)
jmp 0xaab4
movl $0x2, %eax
movq %rax, -0x118(%rbp)
jmp 0xaab4
movq -0x118(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
imulq $0x30, 0x8(%rax), %rsi
callq 0x33f0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rcx
movq (%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, (%rcx)
imulq $0x30, %rax, %rax
addq %rax, %rdi
leaq -0xc8(%rbp), %rsi
movl $0x30, %edx
callq 0x3350
jmp 0xab17
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xa851
movq -0x58(%rbp), %rdi
callq 0x3060
movq -0x30(%rbp), %rax
cmpq $0x0, (%rax)
jne 0xab47
movl $0x0, -0x4(%rbp)
jmp 0xafd2
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movq (%rax), %rsi
movl $0x30, %edx
leaq 0x73e(%rip), %rcx       # 0xb2a0
callq 0x30f0
movq $0x0, -0x40(%rbp)
movq $0x1, -0x48(%rbp)
movq $0x1, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq (%rcx), %rax
jae 0xac44
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
imulq $0x30, -0x38(%rbp), %rax
addq %rax, %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rsi
imulq $0x30, -0x40(%rbp), %rax
addq %rax, %rsi
callq 0xb2a0
movl %eax, -0xcc(%rbp)
cmpl $0x0, -0xcc(%rbp)
jne 0xabeb
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x38(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdi
callq 0x3060
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0xac27
movq -0x48(%rbp), %rax
cmpq -0x38(%rbp), %rax
je 0xac1f
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
imulq $0x30, -0x48(%rbp), %rax
addq %rax, %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rsi
imulq $0x30, -0x38(%rbp), %rax
addq %rax, %rsi
movl $0x30, %edx
callq 0x3350
movq -0x48(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xab7f
movq -0x48(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xf8(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq (%rcx), %rax
jae 0xafc8
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, -0xd0(%rbp)
movq -0x108(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xe8(%rbp)
movq -0xf8(%rbp), %rdi
movq -0xe8(%rbp), %rax
movl -0xd0(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, %esi
movq -0xe8(%rbp), %rax
movl (%rax), %eax
movl %eax, %edx
callq 0xb3d0
movq %rax, -0x100(%rbp)
cmpq $0x0, -0x100(%rbp)
je 0xacf6
jmp 0xad15
leaq 0x41ae6(%rip), %rdi     # 0x4c7e3
leaq 0x418fa(%rip), %rsi     # 0x4c5fe
movl $0x2c4, %edx            # imm = 0x2C4
leaq 0x41ad7(%rip), %rcx     # 0x4c7e7
callq 0x3220
movq -0xf8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0xe8(%rbp), %rcx
movl (%rcx), %ecx
shrl %ecx
leaq (%rcx,%rcx,4), %rcx
movl 0x18(%rax,%rcx,8), %eax
movl %eax, -0xd4(%rbp)
movq -0xf8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0xe8(%rbp), %rcx
movl (%rcx), %ecx
shrl %ecx
leaq (%rcx,%rcx,4), %rcx
movl 0x20(%rax,%rcx,8), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, -0xdc(%rbp)
movl -0xdc(%rbp), %eax
cvtsi2sd %rax, %xmm0
movl -0xd4(%rbp), %eax
cvtsi2sd %rax, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0xf0(%rbp)
movq -0x100(%rbp), %rax
movl 0x18(%rax), %ecx
movl -0xd4(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xd4(%rbp)
movl -0xdc(%rbp), %eax
movq -0x100(%rbp), %rcx
movq 0x18(%rcx), %rcx
imulq %rcx, %rax
movq %rax, %xmm1
movaps 0x41673(%rip), %xmm0    # 0x4c430
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x41677(%rip), %xmm0    # 0x4c440
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd -0xf0(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0xf0(%rbp)
movq $0x1, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl -0xd0(%rbp), %ecx
cmpq %rcx, %rax
jae 0xaf93
movq -0xf8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0xe8(%rbp), %rcx
movq -0x40(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
leaq (%rcx,%rcx,4), %rcx
movl 0x18(%rax,%rcx,8), %eax
movl %eax, -0xd8(%rbp)
movq -0xf8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0xe8(%rbp), %rcx
movq -0x40(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
leaq (%rcx,%rcx,4), %rcx
movl 0x20(%rax,%rcx,8), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, -0xdc(%rbp)
movl -0xd8(%rbp), %ecx
movl -0xd4(%rbp), %eax
addl %ecx, %eax
movl %eax, -0xd4(%rbp)
movl -0xdc(%rbp), %eax
cvtsi2sd %rax, %xmm0
movl -0xd8(%rbp), %eax
cvtsi2sd %rax, %xmm2
movsd -0xf0(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xf0(%rbp)
movq -0xf8(%rbp), %rdi
movq -0xe8(%rbp), %rax
movq -0x40(%rbp), %rcx
subq $0x1, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, %esi
movq -0xe8(%rbp), %rax
movq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, %edx
callq 0xb3d0
movq %rax, -0x100(%rbp)
cmpq $0x0, -0x100(%rbp)
je 0xaee3
jmp 0xaf02
leaq 0x418f9(%rip), %rdi     # 0x4c7e3
leaq 0x4170d(%rip), %rsi     # 0x4c5fe
movl $0x2d0, %edx            # imm = 0x2D0
leaq 0x418ea(%rip), %rcx     # 0x4c7e7
callq 0x3220
movq -0x100(%rbp), %rax
movl 0x18(%rax), %ecx
movl -0xd4(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xd4(%rbp)
movl -0xdc(%rbp), %eax
cvtsi2sd %rax, %xmm0
movq -0x100(%rbp), %rax
movq 0x18(%rax), %xmm2
movaps 0x414f8(%rip), %xmm1    # 0x4c430
punpckldq %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
movapd 0x414fc(%rip), %xmm1    # 0x4c440
subpd %xmm1, %xmm2
movaps %xmm2, %xmm1
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
addsd %xmm1, %xmm2
movsd -0xf0(%rbp), %xmm1
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xf0(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xadf4
movl -0xd4(%rbp), %ecx
movq -0x108(%rbp), %rax
movl %ecx, 0x18(%rax)
movsd -0xf0(%rbp), %xmm0
movq -0x108(%rbp), %rax
movsd %xmm0, 0x20(%rax)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xac66
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nop