// File: /workspace/github_c_makefile_star2_O3/c-zhou[P]oatk/path.c
// Function: slim_graph
static void slim_graph(asg_t *asg, og_component_v *sequence_og, og_component_t *component_g, clust_dp_t *comp_dps, OG_TYPE_t og_target, 
        OG_TYPE_t *og_seeds, double c_mean, int max_r_len, og_component_v *components, int verbose)
{
    uint32_t i, j, k, l, v, w, r, nv, na, len, gen, cov, gid, n_vtx, imax, smax, *comp_v;
    uint8_t *dels, *visited;
    double score[4];
    asmg_t *asmg;
    asmg_arc_t *av;
    og_component_t *component_s, *component;

    asmg = asg_make_asmg_copy(component_g->asmg, 0);
    n_vtx = asmg->n_vtx;
    comp_v = component_g->v;
    nv = component_g->nv;

    // do graph slimming
    if (verbose > 1) {
        fprintf(stderr, "[M::%s] subgraph slimming for organelle [%s] with average sequence coverage %.3f\n", 
                __func__, OG_TYPES[og_target], c_mean);
        if (verbose > 2) {
            asmg_t *g = asg->asmg;
            asg->asmg = asmg;
            asg_print(asg, stderr, 1);
            asg->asmg = g;
        }
    }

    // find sequences to remove
    MYCALLOC(dels, n_vtx);
    for (i = 0; i < nv; ++i)
        if (og_seeds[i] != og_target)
            dels[comp_v[i]] = 1;

    // bring back the sequence if in a critical path
    // TODO improve the recalling strategy
    // currently bring repeat sequences back if attached to any non-deleted
    /***
    while (1) {
        int recall = 0;
        for (i = 0; i < nv; ++i) {
            v = comp_v[i];
            if (!dels[v] || asmg->vtx[v].len > max_r_len)
                continue; // not a repeat
            // check incoming and outgoing arcs to see if any non-deleted
            int done = 0;
            for (j = 0; j < 2 && !done; ++j) {
                av = asmg_arc_a(asmg, v<<1 | j);
                na = asmg_arc_n(asmg, v<<1 | j);
                for (k = 0; k < na; ++k) {
                    if (!av[k].del && !dels[av[k].w>>1]) {
                        dels[v] = 0;
                        ++recall;
                        done = 1;
                        break;
                    }
                }
            }
        }
        if (!recall) break;
    }
    **/
    
    // here is an improved strategy
    // bring a repeat sequence back if both ends connect to a sequence
    // through a path of all repeats
    // and the distance is no greater than max_r_len
    // repeat this process until no sequence is added
    int recall, max_r, *dist, *flag;
    kdq_u64_t *q;

    MYMALLOC(dist, n_vtx << 1);
    MYMALLOC(flag, n_vtx << 1);
    q = kdq_init(uint64_t, 0);
    while (1) {
        MYBZERO(dist, n_vtx << 1);
        for (i = 0; i < nv; ++i) {
            if (dels[comp_v[i]])
                // skip dels
                continue;
            // the maximum distance to radiate
            max_r = asmg->vtx[comp_v[i]].len;
            if (max_r > max_r_len)
                max_r = max_r_len;
            for (k = 0; k < 2; ++k) {
                uint64_t source = comp_v[i] << 1 | k;
                // find all reachable repeats from 'source'
                MYBZERO(flag, n_vtx << 1);
                kdq_push(uint64_t, q, source << 32 | 0);
                while (kdq_size(q) > 0) {
                    uint64_t x = *kdq_shift(uint64_t, q);
                    v = x >> 32;
                    r = (uint32_t) x;
                    flag[v] = 1;
                    dist[v] = source << 1 | 1;
                    av = asmg_arc_a(asmg, v);
                    na = asmg_arc_n(asmg, v);
                    for (j = 0; j < na; ++j) {
                        if (av[j].del)
                            continue;
                        w = av[j].w;
                        if (!flag[w] &&
                                r <= av[j].ls + max_r &&
                                asmg->vtx[w>>1].len <= max_r)
                            // add non-visited repeats
                            kdq_push(uint64_t, q, (uint64_t) w << 32 | (r + asmg->vtx[w>>1].len - av[j].ls));
                    }
                }
            }
        }

        recall = 0;
        for (i = 0; i < nv; ++i) {
            v = comp_v[i];
            if (dels[v] &&
                    asmg->vtx[v].len <= max_r_len &&
                    dist[v<<1] &&
                    dist[v<<1 | 1]) {
                dels[v] = 0;
                ++recall;
                if (verbose > 2)
                    fprintf(stderr, "[M::%s] recall repeat %s: %s%c <-> %s%c\n", __func__,
                            asg->seg[v].name,
                            asg->seg[dist[v<<1]>>2].name, "+-"[(dist[v<<1]>>1)&1],
                            asg->seg[dist[v<<1|1]>>2].name, "+-"[(dist[v<<1|1]>>1)&1]);
            }
        }
        if (!recall) break;
    }
    free(dist);
    free(flag);
    kdq_destroy(uint64_t, q);

    for (i = 0; i < nv; ++i) {
        v = comp_v[i];
        if (dels[v])
            asmg_vtx_del(asmg, v, 1);
    }

    if (verbose > 2) {
        asmg_t *g = asg->asmg;
        asg->asmg = asmg;
        asg_print(asg, stderr, 1);
        asg->asmg = g;
    }

    uint64_t cleaned = 1;
    while (cleaned) {
        // simple clean
        cleaned = 0;
        cleaned += asmg_pop_bubble(asmg, max_r_len, 0, 0, 1, 0, verbose);
        cleaned += asmg_remove_weak_crosslink(asmg, 0.3, 10, 0, verbose);
        cleaned += asmg_drop_tip(asmg, INT32_MAX, max_r_len, 1, 0, verbose);
    }
    // add cleaned vtx to dels for integrity
    for (i = 0; i < nv; ++i) {
        v = comp_v[i];
        if (asmg->vtx[v].del)
            dels[v] = 1;
    }

    if (verbose > 2) {
        asmg_t *g = asg->asmg;
        asg->asmg = asmg;
        asg_print(asg, stderr, 1);
        asg->asmg = g;
    }

    // minimum subgraph size to keep
    // set as 10% of the total sequence
    double m_size = 0;
    for (i = 0; i < nv; ++i) {
        v = comp_v[i];
        if (!asmg->vtx[v].del)
            m_size += asmg->vtx[v].len;
    }
    m_size *= 0.1;

    // now process each subgraph
    MYCALLOC(visited, n_vtx);
    for (i = 0; i < nv; ++i) {
        v = comp_v[i];
        if (visited[v] || asmg->vtx[v].del)
            continue;
        
        asmg_t *g = asg_make_asmg_copy(asmg, 0);
        asmg_subgraph(g, &v, 1, 0, 0, 0, 1);

        kvec_t(uint32_t) comp_s;
        kv_init(comp_s);
        len = gen = 0;
        for (j = 0; j < nv; ++j) {
            w = comp_v[j];
            if (g->vtx[w].del)
                continue;
            kv_push(uint32_t, comp_s, w);
            len += g->vtx[w].len;
            gen += comp_dps[j].gene_num[og_target];
            visited[w] = 1;
        }
        if (len < m_size || gen == 0) {
            // not a good subgraph
            asmg_destroy(g);
            kv_destroy(comp_s);
            continue;
        }
        
        // add subgraph component
        // adjust repeat sequence coverage if necessary
        // also fix the arc coverage
        for (j = 0; j < nv; ++j) {
            w = comp_v[j];
            if (g->vtx[w].del ||
                    og_seeds[j] == og_target ||
                    g->vtx[w].len >= max_r_len ||
                    g->vtx[w].cov < c_mean * 3.5)
                continue;
            int n_del, n_arc;
            n_del = n_arc = 0;
            for (k = 0; k < 2; ++k) {
                av = asmg_arc_a(asmg, w << 1 | k);
                na = asmg_arc_n(asmg, w << 1 | k);
                for (l = 0; l < na; ++l) {
                    if (dels[av[l].w>>1])
                        ++n_del;
                    if (!av[l].del)
                        ++n_arc;
                }
            }
            if (!n_del) continue;
            cov = g->vtx[w].cov;
            g->vtx[w].cov = c_mean * n_arc / 2.0;
            // fix arc coverage
            for (k = 0; k < 2; ++k) {
                av = asmg_arc_a(asmg, w << 1 | k);
                na = asmg_arc_n(asmg, w << 1 | k);
                for (l = 0; l < na; ++l) {
                    if (av[l].del) continue;
                    if (av[l].cov > cov)
                        av[l].cov = cov;
                }
            }
            if (verbose > 2)
                fprintf(stderr, "[M::%s] sequence %s coverage adjusted: %u -> %u\n", 
                        __func__, asg->seg[w].name, cov, g->vtx[w].cov);
        }

        // make seg list
        MYREALLOC(comp_s.a, comp_s.n);

        // make gene list
        kvec_t(uint64_t) comp_g;
        kv_init(comp_g);
        // collect genes from sequences in the subgraph
        for (j = 0; j < nv; ++j) {
            w = comp_v[j];
            if (g->vtx[w].del)
                continue;
            component_s = &sequence_og->a[w];
            kv_pushn(uint64_t, comp_g, component_s->g, component_s->ng);
        }
        // sort by gid and then score - descending order
        qsort(comp_g.a, comp_g.n, sizeof(uint64_t), u64_cmpfunc_r);
        // keep only the best hit for each gene
        k = 0;
        gid = UINT32_MAX;
        for (j = 0; j < comp_g.n; ++j) {
            if (comp_g.a[j] >> 32 != gid) {
                comp_g.a[k++] = comp_g.a[j];
                gid = comp_g.a[j] >> 32;
            }
        }
        comp_g.n = k;
        MYREALLOC(comp_g.a, k);

        // calculate subgraph annotation scores
        uint64_t *a_s = comp_g.a;
        MYBZERO(score, 4);
        for (j = 0, k = comp_g.n; j < k; ++j)
            score[(a_s[j] >> 32) & 0x3] += (uint32_t) a_s[j];
        imax = max2(score, 4, &smax);

        // update component vector
        kv_pushp(og_component_t, *components, &component);
        component->type = (uint32_t) og_target;
        component->score = score[imax];
        component->sscore = score[smax];
        component->len = len;
        component->nv = comp_s.n;
        component->v = comp_s.a;
        component->ng = comp_g.n;
        component->g = comp_g.a;
        component->asmg = g;

        if (verbose > 0)
            fprintf(stderr, "[M::%s] subgraph seeding from %s: segs, %lu; size, %d; mito score, %.3f; pltd score, %.3f; mini score, %.3f; classification, %d\n",
                    __func__, asg->seg[v].name, comp_s.n, len, score[OG_MITO], score[OG_PLTD], score[OG_MINI], og_target);

    }

    free(dels);
    free(visited);
    asmg_destroy(asmg);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movsd %xmm0, 0xa0(%rsp)
movq %r9, 0xb0(%rsp)
movl %r8d, 0x1c(%rsp)
movq %rcx, 0xf8(%rsp)
movq %rdx, %r15
movq %rsi, 0x100(%rsp)
movq %rdi, 0x78(%rsp)
movq 0x38(%rdx), %rdi
xorl %esi, %esi
callq 0xb1fb
movq %rax, 0x10(%rsp)
movq (%rax), %r13
movq 0x20(%r15), %rax
movq %rax, 0x38(%rsp)
movl 0x1c(%r15), %r15d
cmpl $0x2, 0x150(%rsp)
jge 0x10e1b
movl %r13d, %edi
movl $0x1, %esi
movq %rdi, 0xc8(%rsp)
callq 0x3240
movq %rax, %r14
testq %r15, %r15
movq 0xb0(%rsp), %rdx
movl 0x1c(%rsp), %esi
movq %r13, %rbx
je 0xfdd6
xorl %eax, %eax
cmpl %esi, (%rdx,%rax,4)
je 0xfdce
movq 0x38(%rsp), %rcx
movl (%rcx,%rax,4), %ecx
movb $0x1, (%r14,%rcx)
incq %rax
cmpq %rax, %r15
jne 0xfdbc
movabsq $0x3ffffffffffffff, %r13 # imm = 0x3FFFFFFFFFFFFFF
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
shlq $0x3, %rbx
movq %rbx, %rdi
callq 0x32f0
movq %rax, 0x20(%rsp)
movq %rbx, %rdi
callq 0x32f0
movq %rax, %rbp
movl $0x1, %esi
movl $0x28, %edx
xorl %edi, %edi
callq 0x18ab0
movq %rax, %r12
movq (%rax), %rax
andq %r13, %rax
movq %rbp, %r13
btsq $0x3b, %rax
movq %rax, (%r12)
movq $0x3, 0x10(%r12)
movl $0x20, %esi
xorl %edi, %edi
callq 0x18c11
movq 0x20(%rsp), %rdi
movq %rax, 0x18(%r12)
movq %r12, 0x30(%rsp)
movq $0x0, 0x20(%r12)
movslq 0x140(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x78(%rsp), %rax
addq $0x10, %rax
movq %rax, 0xa8(%rsp)
movq %r15, 0x48(%rsp)
movq %r14, 0x90(%rsp)
movq %rbp, 0x68(%rsp)
movq %rbx, 0x98(%rsp)
xorl %esi, %esi
movq %rbx, %rdx
callq 0x31b0
testq %r15, %r15
movq 0x10(%rsp), %r8
je 0x104cc
xorl %edx, %edx
movq 0x30(%rsp), %r9
movq 0x38(%rsp), %rax
movl (%rax,%rdx,4), %eax
cmpb $0x0, (%r14,%rax)
je 0xfed8
incq %rdx
movq 0x48(%rsp), %r15
cmpq %r15, %rdx
movq 0x90(%rsp), %r14
jne 0xfeaf
jmp 0x103d2
movq 0x10(%r8), %rcx
leaq (%rax,%rax,4), %rax
movl 0x18(%rcx,%rax,8), %eax
movl 0x140(%rsp), %ecx
cmpl %ecx, %eax
cmovgel %ecx, %eax
cltq
movq %rax, 0x50(%rsp)
movq 0x8(%r9), %r15
xorl %ebx, %ebx
movb $0x1, %al
movq %rdx, 0x80(%rsp)
movq %rax, 0xb8(%rsp)
movq 0x38(%rsp), %rax
movl (%rax,%rdx,4), %r14d
movq %r13, %rdi
xorl %esi, %esi
movq 0x98(%rsp), %rdx
callq 0x31b0
movq 0x30(%rsp), %r9
movq (%r9), %rsi
movq %rsi, %rax
shrq $0x3a, %rax
movl $0x1, %edx
movl %eax, %ecx
shlq %cl, %rdx
cmpq %rdx, %r15
jne 0x10040
leal 0x1(%rax), %r13d
movl $0x1, %r12d
movl %r13d, %ecx
shlq %cl, %r12
cmpq %r15, %r12
jae 0xffb1
movq $-0x1, %r13
movq 0x10(%rsp), %r8
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq 0x20(%rsp), %r11
incq %r13
movq %r15, %rdx
movl %r13d, %ecx
shrq %cl, %rdx
cmpq $0x3f, %r13
ja 0xff93
testq %rdx, %rdx
jne 0xff7c
cmpq %r13, %rax
je 0x100b0
movl $0x1, %r12d
movl %r13d, %ecx
shlq %cl, %r12
cmpq %rax, %r13
jbe 0x103ca
movq 0x18(%r9), %rsi
movq 0x20(%r9), %rdi
movl $0x8, %edx
movl %r13d, %ecx
shlq %cl, %rdx
callq 0x18d19
movq 0x30(%rsp), %r9
movq %rax, 0x18(%r9)
movq (%r9), %rsi
movq 0x8(%r9), %rdx
movq 0x10(%rsp), %r8
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq 0x20(%rsp), %r11
movq %rsi, %rax
andq %r10, %rax
addq %rax, %rdx
cmpq %r15, %rdx
jbe 0x10056
movq 0x18(%r9), %rcx
movq %r15, %rdx
subq %rax, %rdx
movq %r12, %rsi
subq %rdx, %rsi
leaq (%rcx,%rsi,8), %rdi
leaq (%rcx,%rax,8), %rsi
shlq $0x3, %rdx
callq 0x3340
movq 0x20(%rsp), %r11
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq 0x30(%rsp), %r9
movq 0x10(%rsp), %r8
subq %r15, %r12
addq (%r9), %r12
movq %r12, %rsi
jmp 0x10088
movq 0x10(%rsp), %r8
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq 0x20(%rsp), %r11
jmp 0x100b5
subq %r12, %rdx
jbe 0x10088
movq 0x18(%r9), %rdi
leaq (%rdi,%r12,8), %rsi
shlq $0x3, %rdx
callq 0x3340
movq 0x20(%rsp), %r11
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq 0x30(%rsp), %r9
movq 0x10(%rsp), %r8
movq (%r9), %rsi
movq %r13, %rax
shlq $0x3a, %rax
andq %r10, %rsi
orq %rax, %rsi
movq $-0x1, %rax
movl %r13d, %ecx
shlq %cl, %rax
movq %rsi, (%r9)
notq %rax
movq %rax, 0x10(%r9)
movq 0x8(%r9), %r15
movq 0x68(%rsp), %r13
leal (%rbx,%r14,2), %edx
movq %rdx, %rcx
movq 0x18(%r9), %rax
leaq 0x1(%r15), %rdi
movq %rdi, 0x8(%r9)
andq %r10, %rsi
addq %r15, %rsi
andq 0x10(%r9), %rsi
shlq $0x20, %rcx
movq %rcx, (%rax,%rsi,8)
movq 0x8(%r9), %rcx
testq %rcx, %rcx
movq 0x50(%rsp), %r15
je 0x103a2
leal 0x1(,%rdx,2), %edx
movl %edx, 0x58(%rsp)
movq (%r9), %rdx
movq %rdx, %rsi
andq %r10, %rsi
leaq 0x1(%rdx), %rdi
andq %r10, %rdi
movabsq $-0x400000000000000, %rbx # imm = 0xFC00000000000000
andq %rbx, %rdx
andq 0x10(%r9), %rdi
orq %rdx, %rdi
movq %rdi, (%r9)
decq %rcx
movq %rcx, 0x8(%r9)
movq (%rax,%rsi,8), %rdx
movq %rdx, %rsi
shrq $0x20, %rsi
movl %esi, 0x2c(%rsp)
movl $0x1, (%r13,%rsi,4)
movl 0x58(%rsp), %edi
movl %edi, (%r11,%rsi,4)
movq 0x38(%r8), %rdi
movl (%rdi,%rsi,8), %r14d
testq %r14, %r14
je 0x10399
movq 0x30(%r8), %rcx
movq (%rcx,%rsi,8), %rcx
leaq (%rcx,%rcx,2), %rbx
shlq $0x4, %rbx
addq 0x28(%r8), %rbx
movl %edx, %edi
xorl %r12d, %r12d
movq %rdi, 0x40(%rsp)
leaq (%r12,%r12,2), %rdx
shlq $0x4, %rdx
testb $0x40, 0x23(%rbx,%rdx)
jne 0x1037f
addq %rbx, %rdx
movq 0x8(%rdx), %rcx
movl %ecx, %ebp
cmpl $0x0, (%r13,%rbp,4)
jne 0x1037f
movq 0x18(%rdx), %rsi
leaq (%rsi,%r15), %rdx
cmpq %rdx, %rdi
ja 0x1037f
movq 0x10(%r8), %rdx
shrl %ecx
leaq (%rcx,%rcx,4), %rcx
movq 0x18(%rdx,%rcx,8), %rcx
cmpq %r15, %rcx
ja 0x1037f
movq %rcx, 0xc0(%rsp)
movq %rsi, 0x70(%rsp)
movq (%r9), %rsi
movq 0x8(%r9), %r15
movq %rsi, %rdx
shrq $0x3a, %rdx
movl $0x1, %edi
movl %edx, %ecx
shlq %cl, %rdi
cmpq %rdi, %r15
jne 0x10230
leal 0x1(%rdx), %r13d
movl $0x1, %edi
movl %r13d, %ecx
shlq %cl, %rdi
movq %rdi, 0x60(%rsp)
cmpq %r15, %rdi
jae 0x10253
movq $-0x1, %r13
incq %r13
movq %r15, %rdi
movl %r13d, %ecx
shrq %cl, %rdi
cmpq $0x3f, %r13
ja 0x10226
testq %rdi, %rdi
jne 0x1020f
cmpq %r13, %rdx
jne 0x1023a
movq 0x68(%rsp), %r13
movq 0x40(%rsp), %rdi
jmp 0x1034d
movl $0x1, %edi
movl %r13d, %ecx
shlq %cl, %rdi
movq %rdi, 0x60(%rsp)
cmpq %rdx, %r13
jbe 0x1038d
movq 0x20(%r9), %rdi
movl $0x8, %edx
movl %r13d, %ecx
shlq %cl, %rdx
movq %rax, %rsi
callq 0x18d19
movq 0x30(%rsp), %r9
movq %rax, 0x18(%r9)
movq (%r9), %rsi
movq 0x8(%r9), %rdx
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq 0x20(%rsp), %r11
movq 0x40(%rsp), %rdi
movq %rsi, %rcx
andq %r10, %rcx
addq %rcx, %rdx
cmpq %r15, %rdx
jbe 0x102e1
movq %r15, %rdx
subq %rcx, %rdx
movq 0x60(%rsp), %rsi
subq %rdx, %rsi
leaq (%rax,%rsi,8), %rdi
leaq (%rax,%rcx,8), %rsi
shlq $0x3, %rdx
callq 0x3340
movq 0x40(%rsp), %rdi
movq 0x20(%rsp), %r11
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq 0x30(%rsp), %r9
movq 0x60(%rsp), %rsi
subq %r15, %rsi
addq (%r9), %rsi
jmp 0x10317
movq 0x60(%rsp), %rcx
subq %rcx, %rdx
jbe 0x10317
leaq (%rax,%rcx,8), %rsi
shlq $0x3, %rdx
movq %rax, %rdi
callq 0x3340
movq 0x40(%rsp), %rdi
movq 0x20(%rsp), %r11
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq 0x30(%rsp), %r9
movq (%r9), %rsi
movq %r13, %rax
shlq $0x3a, %rax
andq %r10, %rsi
orq %rax, %rsi
movq %rsi, (%r9)
movq $-0x1, %rax
movl %r13d, %ecx
shlq %cl, %rax
notq %rax
movq %rax, 0x10(%r9)
movq 0x8(%r9), %r15
movq 0x18(%r9), %rax
movq 0x10(%rsp), %r8
movq 0x68(%rsp), %r13
shlq $0x20, %rbp
movq %rdi, %rcx
subq 0x70(%rsp), %rcx
addq 0xc0(%rsp), %rcx
orq %rbp, %rcx
leaq 0x1(%r15), %rdx
movq %rdx, 0x8(%r9)
andq %r10, %rsi
addq %r15, %rsi
andq 0x10(%r9), %rsi
movq %rcx, (%rax,%rsi,8)
movq 0x50(%rsp), %r15
incq %r12
cmpq %r14, %r12
jne 0x10174
jmp 0x10395
movq %r15, %rdx
jmp 0x10289
movq 0x8(%r9), %rcx
testq %rcx, %rcx
jne 0x100f7
movl $0x1, %ebx
xorl %r15d, %r15d
testb $0x1, 0xb8(%rsp)
movl $0x0, %eax
movq 0x80(%rsp), %rdx
jne 0xff07
jmp 0xfebe
movq %r15, %rdx
jmp 0xffed
testq %r15, %r15
je 0x104cc
xorl %ebx, %ebx
xorl %ebp, %ebp
movq 0x88(%rsp), %r9
movq 0x20(%rsp), %rdi
movq 0x38(%rsp), %rax
movl (%rax,%rbx,4), %esi
movl %esi, 0x2c(%rsp)
cmpb $0x0, (%r14,%rsi)
je 0x10433
movq 0x10(%r8), %rax
leaq (%rsi,%rsi,4), %rcx
cmpq %r9, 0x18(%rax,%rcx,8)
ja 0x10433
leal (%rsi,%rsi), %eax
movl (%rdi,%rax,4), %edx
testl %edx, %edx
je 0x10433
movl %eax, %eax
movl 0x4(%rdi,%rax,4), %ecx
testl %ecx, %ecx
je 0x10433
incl %ebp
movb $0x0, (%r14,%rsi)
cmpl $0x3, 0x150(%rsp)
jge 0x1043d
incq %rbx
cmpq %rbx, %r15
jne 0x103ec
jmp 0x1045e
movq 0xa8(%rsp), %rdi
callq 0x3a64
movq 0x20(%rsp), %rdi
movq 0x88(%rsp), %r9
movq 0x10(%rsp), %r8
jmp 0x10433
testl %ebp, %ebp
movq 0x98(%rsp), %rbx
jne 0xfe90
callq 0x3060
movq %r13, %rdi
callq 0x3060
movq 0x30(%rsp), %rbx
movq 0x18(%rbx), %rsi
movq 0x20(%rbx), %rdi
callq 0x18b4b
movq 0x20(%rbx), %rdi
movq %rbx, %rsi
callq 0x18b4b
testq %r15, %r15
movq 0x10(%rsp), %rdi
je 0x10501
xorl %ebx, %ebx
movq 0x38(%rsp), %rax
movl (%rax,%rbx,4), %esi
movl %esi, 0x2c(%rsp)
cmpb $0x0, (%r14,%rsi)
je 0x104c2
callq 0x6f45
movq 0x10(%rsp), %rdi
incq %rbx
cmpq %rbx, %r15
jne 0x104a5
jmp 0x10501
movq 0x20(%rsp), %rdi
callq 0x3060
movq %r13, %rdi
callq 0x3060
movq 0x30(%rsp), %rbx
movq 0x18(%rbx), %rsi
movq 0x20(%rbx), %rdi
callq 0x18b4b
movq 0x20(%rbx), %rdi
movq %rbx, %rsi
callq 0x18b4b
movq 0x10(%rsp), %rdi
movl 0x150(%rsp), %ebx
cmpl $0x2, %ebx
movq 0x88(%rsp), %r12
jle 0x10549
movq 0x78(%rsp), %r14
movq 0x20(%r14), %rbx
movq %rdi, 0x20(%r14)
movq 0xfacf(%rip), %rax      # 0x1fff8
movq (%rax), %rsi
movq %r14, %rdi
movl $0x1, %edx
callq 0xb68d
movq 0x10(%rsp), %rdi
movq %rbx, 0x20(%r14)
movl 0x150(%rsp), %ebx
movl %ebx, (%rsp)
movq %r12, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x13460
movq %rax, %r14
movsd 0x9f44(%rip), %xmm0     # 0x1a4b0
movsd 0x9fec(%rip), %xmm1     # 0x1a560
movq 0x10(%rsp), %rdi
xorl %esi, %esi
movl %ebx, %edx
callq 0x13206
movq %rax, %r15
addq %r14, %r15
movq 0x10(%rsp), %rdi
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq %r12, %rdx
movl $0x1, %ecx
xorl %r8d, %r8d
movl %ebx, %r9d
callq 0x12c67
movq 0x10(%rsp), %rdi
addq %r15, %rax
jne 0x10549
movq 0x48(%rsp), %r14
testq %r14, %r14
je 0x105ea
movq 0x10(%rdi), %rax
xorl %ecx, %ecx
movq 0x38(%rsp), %rdx
movl (%rdx,%rcx,4), %edx
movl %edx, 0x2c(%rsp)
leaq (%rdx,%rdx,4), %rsi
testb $0x40, 0x23(%rax,%rsi,8)
je 0x105e2
movq 0x90(%rsp), %rsi
movb $0x1, (%rsi,%rdx)
incq %rcx
cmpq %rcx, %r14
jne 0x105bf
cmpl $0x3, %ebx
jl 0x1061c
movq 0x78(%rsp), %r15
movq 0x20(%r15), %rbx
movq %rdi, 0x20(%r15)
movq 0xf9f5(%rip), %rax      # 0x1fff8
movq (%rax), %rsi
movq %r15, %rdi
movl $0x1, %edx
callq 0xb68d
movq 0x10(%rsp), %rdi
movq %rbx, 0x20(%r15)
testq %r14, %r14
je 0x10dd5
movq 0x10(%rdi), %rax
xorpd %xmm0, %xmm0
movsd %xmm0, 0x50(%rsp)
xorl %ecx, %ecx
movsd 0x9f53(%rip), %xmm0     # 0x1a590
movapd 0x9f5b(%rip), %xmm1     # 0x1a5a0
movq 0x38(%rsp), %rdx
movl (%rdx,%rcx,4), %edx
movl %edx, 0x2c(%rsp)
leaq (%rdx,%rdx,4), %rdx
testb $0x40, 0x23(%rax,%rdx,8)
jne 0x10688
leaq (%rax,%rdx,8), %rdx
movsd 0x18(%rdx), %xmm2
unpcklps %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1]
subpd %xmm1, %xmm2
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
addsd %xmm2, %xmm3
movsd 0x50(%rsp), %xmm2
addsd %xmm3, %xmm2
movsd %xmm2, 0x50(%rsp)
incq %rcx
cmpq %rcx, %r14
jne 0x10645
movl $0x1, %esi
movq 0xc8(%rsp), %rdi
callq 0x3240
movq %rax, %r10
testq %r14, %r14
je 0x10dd0
movsd 0x50(%rsp), %xmm0
mulsd 0x9eac(%rip), %xmm0     # 0x1a568
movsd %xmm0, 0x50(%rsp)
movl 0x1c(%rsp), %eax
movsd 0x9ea2(%rip), %xmm0     # 0x1a570
mulsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0xf8(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
addq $0x18, %rax
movq %rax, 0x98(%rsp)
xorl %ebx, %ebx
movq 0x10(%rsp), %rdi
movq %r10, 0x58(%rsp)
movq 0x38(%rsp), %rax
movl (%rax,%rbx,4), %eax
movl %eax, 0x2c(%rsp)
cmpb $0x0, (%r10,%rax)
jne 0x10d62
movq 0x10(%rdi), %rcx
leaq (%rax,%rax,4), %rax
testb $0x40, 0x23(%rcx,%rax,8)
jne 0x10d62
movq %rbx, 0x20(%rsp)
xorl %ebx, %ebx
xorl %esi, %esi
callq 0xb1fb
movq %rax, %r14
movl $0x1, (%rsp)
movq %rax, %rdi
leaq 0x2c(%rsp), %rsi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x14ff2
movq 0x58(%rsp), %rdx
movq 0x10(%r14), %rax
movq %r14, 0x68(%rsp)
addq $0x10, %r14
movq %r14, 0x60(%rsp)
movq 0x98(%rsp), %r13
xorl %r8d, %r8d
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %r9d, %r9d
xorl %esi, %esi
movq 0x38(%rsp), %rcx
movl (%rcx,%rbx,4), %r14d
leaq (%r14,%r14,4), %r12
testb $0x40, 0x23(%rax,%r12,8)
jne 0x10801
cmpq %r15, %r8
jne 0x107eb
leaq (%r8,%r8), %r15
testq %r8, %r8
movl $0x2, %eax
cmoveq %rax, %r15
movl %esi, 0x70(%rsp)
leaq (,%r15,4), %rsi
movq %rbp, %rdi
movq %r8, %rbp
movl %r9d, 0x40(%rsp)
callq 0x3330
movl 0x70(%rsp), %esi
movl 0x40(%rsp), %r9d
movq %rbp, %r8
movq 0x58(%rsp), %rdx
movq %rax, %rbp
movq 0x60(%rsp), %rax
movq (%rax), %rax
movl %r14d, (%rbp,%r8,4)
addl 0x18(%rax,%r12,8), %r9d
incq %r8
addl (%r13), %esi
movb $0x1, (%rdx,%r14)
incq %rbx
addq $0x30, %r13
cmpq %rbx, 0x48(%rsp)
jne 0x10789
movl %r9d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd 0x50(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x10a82
testl %esi, %esi
je 0x10a82
movq %rbp, 0x78(%rsp)
movl %r9d, 0x40(%rsp)
movq %r8, 0x80(%rsp)
xorl %ebx, %ebx
movq 0x10(%rsp), %r11
movq 0xb0(%rsp), %r14
movl 0x1c(%rsp), %r9d
movq 0x48(%rsp), %r15
movq 0x60(%rsp), %r12
movq 0x38(%rsp), %rax
movl (%rax,%rbx,4), %esi
movq (%r12), %rdx
leaq (%rsi,%rsi,4), %rdi
movl 0x20(%rdx,%rdi,8), %r8d
btl $0x1e, %r8d
jb 0x10a58
cmpl %r9d, (%r14,%rbx,4)
je 0x10a58
leaq (%rdx,%rdi,8), %rax
movq 0x88(%rsp), %rcx
cmpq %rcx, 0x18(%rax)
jae 0x10a58
movl %r8d, %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd 0x30(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x10a58
movq 0x28(%r11), %r9
movq 0x30(%r11), %rax
movq %rax, 0xc0(%rsp)
movq %rsi, 0xb8(%rsp)
leal (%rsi,%rsi), %eax
movq 0x38(%r11), %r11
addq $0x20, %r9
movq %r9, 0x70(%rsp)
xorl %r14d, %r14d
movb $0x1, %r15b
xorl %ebp, %ebp
xorl %r13d, %r13d
orq %rax, %r14
movl (%r11,%r14,8), %r10d
testq %r10, %r10
je 0x1095b
movq 0xc0(%rsp), %rsi
movq (%rsi,%r14,8), %r14
leaq (%r14,%r14,2), %r14
shlq $0x4, %r14
addq 0x70(%rsp), %r14
shlq $0x4, %r10
leaq (%r10,%r10,2), %r12
xorl %r10d, %r10d
movq 0x90(%rsp), %r9
movq -0x18(%r14,%r10), %rsi
shrq %rsi
cmpb $0x1, (%r9,%rsi)
sbbl $-0x1, %r13d
movb 0x3(%r14,%r10), %sil
andb $0x40, %sil
cmpb $0x1, %sil
adcl $0x0, %ebp
addq $0x30, %r10
cmpq %r10, %r12
jne 0x10931
movl $0x1, %r14d
testb $0x1, %r15b
movl $0x0, %r15d
jne 0x108f9
testl %r13d, %r13d
movq 0x10(%rsp), %r11
movq 0xb0(%rsp), %r14
movl 0x1c(%rsp), %r9d
movq 0x48(%rsp), %r15
movq 0x60(%rsp), %r12
movq 0xb8(%rsp), %rsi
je 0x10a58
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
mulsd 0xa0(%rsp), %xmm0
mulsd 0x9b46(%rip), %xmm0     # 0x1a4f8
cvttsd2si %xmm0, %r9
andl $0x3fffffff, %r9d       # imm = 0x3FFFFFFF
andl $0x80000000, %r8d       # imm = 0x80000000
orl %r9d, %r8d
movl %r8d, 0x20(%rdx,%rdi,8)
movb $0x1, %dl
xorl %r10d, %r10d
orq %rax, %r10
movq 0x38(%r11), %rdi
movl (%rdi,%r10,8), %r8d
testq %r8, %r8
je 0x10a39
movq 0x28(%r11), %rdi
movq 0x30(%r11), %r9
movq (%r9,%r10,8), %r9
leaq (%r9,%r9,2), %r9
shlq $0x4, %r9
addq %r9, %rdi
addq $0x20, %rdi
shlq $0x4, %r8
leaq (%r8,%r8,2), %r13
xorl %r8d, %r8d
movl (%rdi,%r8), %r9d
btl $0x1e, %r9d
jb 0x10a30
movl %r9d, %r10d
andl $0x3fffffff, %r10d      # imm = 0x3FFFFFFF
cmpl %ecx, %r10d
jbe 0x10a30
andl $0x80000000, %r9d       # imm = 0x80000000
orl %ecx, %r9d
movl %r9d, (%rdi,%r8)
addq $0x30, %r8
cmpq %r8, %r13
jne 0x10a08
movl $0x1, %r10d
testb $0x1, %dl
movl $0x0, %edx
jne 0x109d2
cmpl $0x3, 0x150(%rsp)
movl 0x1c(%rsp), %r9d
jge 0x10a66
incq %rbx
cmpq %r15, %rbx
jne 0x10866
jmp 0x10aad
movq 0xa8(%rsp), %rdi
movq %r12, %rdx
callq 0x3ae4
movl 0x1c(%rsp), %r9d
movq 0x10(%rsp), %r11
jmp 0x10a58
movq 0x68(%rsp), %rdi
callq 0x11ef0
movq %rbp, %rdi
callq 0x3060
movq 0x10(%rsp), %rdi
movq 0x48(%rsp), %r14
movq 0x58(%rsp), %r10
movq 0x20(%rsp), %rbx
jmp 0x10d62
movq 0x80(%rsp), %rax
leaq (,%rax,4), %rsi
movq 0x78(%rsp), %rdi
callq 0x3330
movq %rax, 0x70(%rsp)
xorl %ebx, %ebx
xorl %ebp, %ebp
xorl %r15d, %r15d
xorl %r14d, %r14d
movq 0x38(%rsp), %rax
movl (%rax,%rbx,4), %eax
movq (%r12), %rcx
leaq (%rax,%rax,4), %rdx
testb $0x40, 0x23(%rcx,%rdx,8)
jne 0x10b78
movq 0x100(%rsp), %rcx
movq 0x10(%rcx), %rcx
shlq $0x6, %rax
leaq (%rcx,%rax), %r13
movl 0x28(%rcx,%rax), %edx
leaq (%rdx,%rbp), %rax
cmpq %r15, %rax
jbe 0x10b60
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %r15
shrq $0x10, %r15
orq %rax, %r15
leaq 0x8(,%r15,8), %rsi
incq %r15
movq %r14, %rdi
callq 0x3330
movq %rax, %r14
movl 0x28(%r13), %edx
leaq (%r14,%rbp,8), %rdi
movq 0x30(%r13), %rsi
shlq $0x3, %rdx
callq 0x32c0
movl 0x28(%r13), %eax
addq %rax, %rbp
incq %rbx
cmpq %rbx, 0x48(%rsp)
jne 0x10ad6
movl $0x8, %edx
movq %r14, %rdi
movq %rbp, %rsi
leaq -0x36a3(%rip), %rcx     # 0xd4f5
callq 0x30c0
testq %rbp, %rbp
je 0x10bd3
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %eax, %eax
xorl %ebx, %ebx
movq (%r14,%rax,8), %rdx
movq %rdx, %rsi
shrq $0x20, %rsi
cmpl %ecx, %esi
je 0x10bc7
movl %ebx, %ecx
incl %ebx
movq %rdx, (%r14,%rcx,8)
movl 0x4(%r14,%rax,8), %ecx
incq %rax
movl %eax, %edx
cmpq %rdx, %rbp
ja 0x10bab
jmp 0x10bd5
xorl %ebx, %ebx
movl %ebx, %r15d
leaq (,%r15,8), %rsi
movq %r14, %rdi
callq 0x3330
movq %rax, %r14
xorpd %xmm0, %xmm0
movapd %xmm0, 0xd0(%rsp)
movapd %xmm0, 0xe0(%rsp)
testl %ebx, %ebx
je 0x10c36
xorl %eax, %eax
movq (%r14,%rax,8), %rcx
movl %ecx, %edx
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
shrq $0x20, %rcx
andl $0x3, %ecx
addsd 0xd0(%rsp,%rcx,8), %xmm0
movsd %xmm0, 0xd0(%rsp,%rcx,8)
incq %rax
cmpq %rax, %r15
jne 0x10c07
xorl %eax, %eax
movsd 0x98e8(%rip), %xmm0     # 0x1a528
movapd %xmm0, %xmm1
xorl %ebp, %ebp
xorl %r15d, %r15d
movq 0x148(%rsp), %rdx
movl %r15d, %ecx
movsd 0xd0(%rsp,%rax,8), %xmm3
ucomisd %xmm0, %xmm3
jbe 0x10c6e
movl %eax, %r15d
movl %ecx, %ebp
movapd %xmm3, %xmm2
jmp 0x10c8b
movl %ecx, %r15d
ucomisd %xmm1, %xmm3
jbe 0x10c83
movl %eax, %ebp
movapd %xmm0, %xmm2
movapd %xmm3, %xmm0
jmp 0x10c8b
movapd %xmm0, %xmm2
movapd %xmm1, %xmm0
incq %rax
movapd %xmm0, %xmm1
movapd %xmm2, %xmm0
cmpq $0x4, %rax
jne 0x10c51
movq (%rdx), %rcx
movq 0x10(%rdx), %rax
cmpq 0x8(%rdx), %rcx
jne 0x10cd7
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rdx)
shlq $0x6, %rsi
movq %rdx, %r12
movq %rax, %rdi
callq 0x3330
movq %rax, 0x10(%r12)
movq (%r12), %rcx
jmp 0x10cda
movq %rdx, %r12
movq 0x10(%rsp), %rdi
movl 0x1c(%rsp), %esi
movq 0x58(%rsp), %r10
movq 0x80(%rsp), %r8
movl 0x40(%rsp), %r9d
leaq 0x1(%rcx), %rdx
shlq $0x6, %rcx
movq %rdx, (%r12)
movl %esi, (%rax,%rcx)
movl %r15d, %edx
movsd 0xd0(%rsp,%rdx,8), %xmm0
movsd %xmm0, 0x8(%rax,%rcx)
movl %ebp, %edx
movsd 0xd0(%rsp,%rdx,8), %xmm0
movsd %xmm0, 0x10(%rax,%rcx)
movl %r9d, 0x18(%rax,%rcx)
movl %r8d, 0x1c(%rax,%rcx)
movq 0x70(%rsp), %rdx
movq %rdx, 0x20(%rax,%rcx)
movl %ebx, 0x28(%rax,%rcx)
movq %r14, 0x30(%rax,%rcx)
movq 0x68(%rsp), %rdx
movq %rdx, 0x38(%rax,%rcx)
cmpl $0x0, 0x150(%rsp)
movq 0x48(%rsp), %r14
movq 0x20(%rsp), %rbx
jg 0x10d70
incq %rbx
cmpq %r14, %rbx
jne 0x10701
jmp 0x10dd0
movq 0xf281(%rip), %rax      # 0x1fff8
movq (%rax), %rdi
movq 0xa8(%rsp), %rax
movq (%rax), %rax
movl 0x2c(%rsp), %ecx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rcx
movsd 0xd8(%rsp), %xmm0
movsd 0xe0(%rsp), %xmm1
movsd 0xe8(%rsp), %xmm2
movl %esi, (%rsp)
leaq 0xa947(%rip), %rsi      # 0x1b6fd
leaq 0xa8db(%rip), %rdx      # 0x1b698
movb $0x3, %al
callq 0x3290
movq 0x58(%rsp), %r10
movq 0x10(%rsp), %rdi
jmp 0x10d62
movq %r10, %rbx
jmp 0x10dea
movl $0x1, %esi
movq 0xc8(%rsp), %rdi
callq 0x3240
movq %rax, %rbx
movq 0x90(%rsp), %rdi
callq 0x3060
movq %rbx, %rdi
callq 0x3060
movq 0x10(%rsp), %rdi
callq 0x11ef0
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xf1d6(%rip), %rbx      # 0x1fff8
movq (%rbx), %rdi
movl 0x1c(%rsp), %eax
leaq 0xed10(%rip), %rcx      # 0x1fb40
movq (%rcx,%rax,8), %rcx
leaq 0xa80b(%rip), %rsi      # 0x1b646
leaq 0xa856(%rip), %rdx      # 0x1b698
movsd 0xa0(%rsp), %xmm0
movb $0x1, %al
callq 0x3290
cmpl $0x2, 0x150(%rsp)
je 0xfd8e
movq 0x78(%rsp), %r12
movq 0x20(%r12), %r14
movq 0x10(%rsp), %rax
movq %rax, 0x20(%r12)
movq (%rbx), %rsi
movq %r12, %rdi
movl $0x1, %edx
callq 0xb68d
movq %r14, 0x20(%r12)
jmp 0xfd8e