// File: /workspace/github_c_makefile_star2_O1/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 $0xe8, %rsp
movsd %xmm0, 0x90(%rsp)
movq %r9, %r15
movl %r8d, %ebp
movq %rcx, 0x78(%rsp)
movq %rdx, %rbx
movq %rsi, 0xe0(%rsp)
movq %rdi, 0x68(%rsp)
movq 0x38(%rdx), %rdi
xorl %esi, %esi
callq 0xad23
movq %rax, 0x10(%rsp)
movq (%rax), %r12
movq 0x20(%rbx), %rax
movq %rax, 0x28(%rsp)
movl 0x1c(%rbx), %r13d
cmpl $0x2, 0x130(%rsp)
jge 0x104f5
movl %r12d, %edi
movl $0x1, %esi
movq %rdi, 0x58(%rsp)
callq 0x3240
testq %r13, %r13
je 0xf829
xorl %edx, %edx
cmpl %ebp, (%r15,%rdx,4)
je 0xf821
movq 0x28(%rsp), %rcx
movl (%rcx,%rdx,4), %ecx
movb $0x1, (%rax,%rcx)
incq %rdx
cmpq %rdx, %r13
jne 0xf80f
movl %ebp, 0x3c(%rsp)
movq %r15, 0xa8(%rsp)
movabsq $0x3ffffffffffffff, %rbx # imm = 0x3FFFFFFFFFFFFFF
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
shlq $0x3, %r12
movq %r12, %rdi
movq %rax, 0x20(%rsp)
callq 0x32f0
movq %rax, %r15
movq %r12, %rdi
callq 0x32f0
movq %rax, %r14
movl $0x1, %esi
movl $0x28, %edx
xorl %edi, %edi
callq 0x171c8
movq %rax, %rbp
movq (%rax), %rax
andq %rbx, %rax
btsq $0x3b, %rax
movq %rax, (%rbp)
movq $0x3, 0x10(%rbp)
movl $0x20, %esi
xorl %edi, %edi
callq 0x17335
movq %r15, %r10
movq %rax, 0x18(%rbp)
movq %rbp, 0x30(%rsp)
movq $0x0, 0x20(%rbp)
movslq 0x120(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x68(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x98(%rsp)
movq %r13, 0x70(%rsp)
movq %r12, 0x88(%rsp)
movq %r15, 0x50(%rsp)
movq %r10, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x31b0
movq 0x50(%rsp), %r10
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %r8
testl %r13d, %r13d
je 0xfb6b
xorl %edx, %edx
movq 0x28(%rsp), %rax
movl (%rax,%rdx,4), %eax
cmpb $0x0, (%rdi,%rax)
jne 0xfabd
movq 0x10(%r8), %rcx
leaq (%rax,%rax,4), %rax
movl 0x18(%rcx,%rax,8), %eax
movl 0x120(%rsp), %ecx
cmpl %ecx, %eax
cmovgel %ecx, %eax
movslq %eax, %rbp
xorl %ecx, %ecx
movq %rdx, 0x40(%rsp)
movq 0x28(%rsp), %rax
movl (%rax,%rdx,4), %eax
movq %rcx, 0x48(%rsp)
leal (%rcx,%rax,2), %ebx
movq %r14, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x31b0
movq %rbx, %rsi
shlq $0x20, %rsi
movq 0x30(%rsp), %r15
movq %r15, %rdi
callq 0x11750
movq 0x50(%rsp), %r10
movq 0x10(%rsp), %r8
movq 0x8(%r15), %rax
testq %rax, %rax
je 0xfa9e
movq %r15, %r11
leal 0x1(,%rbx,2), %ecx
movl %ecx, 0x60(%rsp)
movq (%r11), %rcx
movq 0x18(%r11), %rdx
movq %rcx, %rsi
movabsq $0x3ffffffffffffff, %r9 # imm = 0x3FFFFFFFFFFFFFF
andq %r9, %rsi
leaq 0x1(%rcx), %rdi
andq %r9, %rdi
movabsq $-0x400000000000000, %r9 # imm = 0xFC00000000000000
andq %r9, %rcx
andq 0x10(%r11), %rdi
orq %rcx, %rdi
movq %rdi, (%r11)
decq %rax
movq %rax, 0x8(%r11)
movq (%rdx,%rsi,8), %rax
movq %rax, %rdx
shrq $0x20, %rdx
movl %edx, 0x1c(%rsp)
movl $0x1, (%r14,%rdx,4)
movl 0x60(%rsp), %ecx
movl %ecx, (%r10,%rdx,4)
movq 0x38(%r8), %rcx
movl (%rcx,%rdx,8), %ecx
testq %rcx, %rcx
je 0xfa91
movq 0x28(%r8), %rsi
movq 0x30(%r8), %rdi
movq (%rdi,%rdx,8), %rdx
movl %eax, %r15d
leaq (%rdx,%rdx,2), %rax
shlq $0x4, %rax
leaq (%rsi,%rax), %rbx
addq $0x20, %rbx
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %r12
xorl %r13d, %r13d
testb $0x40, 0x3(%rbx,%r13)
jne 0xfa88
movq -0x18(%rbx,%r13), %rdx
movl %edx, %eax
cmpl $0x0, (%r14,%rax,4)
jne 0xfa88
movq -0x8(%rbx,%r13), %rcx
leaq (%rcx,%rbp), %rsi
cmpq %rsi, %r15
ja 0xfa88
movq 0x10(%r8), %rsi
shrl %edx
leaq (%rdx,%rdx,4), %rdx
movq 0x18(%rsi,%rdx,8), %rdx
cmpq %rbp, %rdx
ja 0xfa88
shlq $0x20, %rax
movq %r15, %rsi
subq %rcx, %rsi
addq %rdx, %rsi
orq %rax, %rsi
movq %r11, %rdi
callq 0x11750
movq 0x30(%rsp), %r11
movq 0x50(%rsp), %r10
movq 0x10(%rsp), %r8
addq $0x30, %r13
cmpq %r13, %r12
jne 0xfa29
movq 0x8(%r11), %rax
testq %rax, %rax
jne 0xf994
movq 0x48(%rsp), %rcx
leal 0x1(%rcx), %eax
testl %ecx, %ecx
movl %eax, %ecx
movq 0x88(%rsp), %r12
movq 0x40(%rsp), %rdx
je 0xf93e
incq %rdx
movq 0x70(%rsp), %r13
cmpq %r13, %rdx
movq 0x20(%rsp), %rdi
jne 0xf90a
testq %r13, %r13
je 0xfb6b
xorl %r12d, %r12d
xorl %ebp, %ebp
movl 0x130(%rsp), %ebx
movq 0x80(%rsp), %r15
movq 0x28(%rsp), %rax
movl (%rax,%r12,4), %esi
movl %esi, 0x1c(%rsp)
cmpb $0x0, (%rdi,%rsi)
je 0xfb33
movq 0x10(%r8), %rax
leaq (%rsi,%rsi,4), %rcx
cmpq %r15, 0x18(%rax,%rcx,8)
ja 0xfb33
leal (%rsi,%rsi), %eax
movl (%r10,%rax,4), %edx
testl %edx, %edx
je 0xfb33
movl %eax, %eax
movl 0x4(%r10,%rax,4), %ecx
testl %ecx, %ecx
je 0xfb33
incl %ebp
movb $0x0, (%rdi,%rsi)
cmpl $0x3, %ebx
jge 0xfb3d
incq %r12
cmpq %r12, %r13
jne 0xfaf0
jmp 0xfb5b
movq 0x98(%rsp), %rdi
callq 0x3aa5
movq 0x50(%rsp), %r10
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %r8
jmp 0xfb33
testl %ebp, %ebp
movq 0x88(%rsp), %r12
jne 0xf8e3
movq %r10, %rdi
callq 0x3060
movq %r14, %rdi
callq 0x3060
movq 0x30(%rsp), %rbx
movq 0x18(%rbx), %rsi
movq 0x20(%rbx), %rdi
callq 0x1726a
movq 0x20(%rbx), %rdi
movq %rbx, %rsi
callq 0x1726a
movq 0x20(%rsp), %rcx
testq %r13, %r13
movl 0x3c(%rsp), %ebp
movl 0x130(%rsp), %r15d
je 0xfbda
xorl %ebx, %ebx
movq 0x28(%rsp), %rax
movl (%rax,%rbx,4), %esi
movl %esi, 0x1c(%rsp)
cmpb $0x0, (%rcx,%rsi)
je 0xfbd2
movq 0x10(%rsp), %rdi
callq 0x6dc8
movq 0x20(%rsp), %rcx
incq %rbx
cmpq %rbx, %r13
jne 0xfbb1
cmpl $0x3, %r15d
movq 0x10(%rsp), %rdi
jl 0xfc12
movq 0x68(%rsp), %r14
movq 0x20(%r14), %rbx
movq %rdi, 0x20(%r14)
movq 0xf3ff(%rip), %rax      # 0x1eff8
movq (%rax), %rsi
movq %r14, %rdi
movl $0x1, %edx
callq 0xb1c3
movq 0x10(%rsp), %rdi
movq %rbx, 0x20(%r14)
movq 0x80(%rsp), %r12
movl %r15d, (%rsp)
movq %r12, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x12e3b
movq %rax, %rbx
movq 0x10(%rsp), %rdi
movsd 0x986d(%rip), %xmm0     # 0x194b0
movsd 0x9915(%rip), %xmm1     # 0x19560
xorl %esi, %esi
movl %r15d, %edx
callq 0x12bdf
movq %rax, %r14
addq %rbx, %r14
movq 0x10(%rsp), %rdi
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq %r12, %rdx
movl $0x1, %ecx
xorl %r8d, %r8d
movl %r15d, %r9d
callq 0x12674
movq 0x10(%rsp), %rdi
addq %r14, %rax
jne 0xfc1a
testq %r13, %r13
movq 0x20(%rsp), %r8
je 0xfcb6
movq 0x10(%rdi), %rax
xorl %ecx, %ecx
movq 0x28(%rsp), %rdx
movl (%rdx,%rcx,4), %edx
movl %edx, 0x1c(%rsp)
leaq (%rdx,%rdx,4), %rsi
testb $0x40, 0x23(%rax,%rsi,8)
je 0xfcae
movb $0x1, (%r8,%rdx)
incq %rcx
cmpq %rcx, %r13
jne 0xfc92
cmpl $0x3, %r15d
jl 0xfce9
movq 0x68(%rsp), %r14
movq 0x20(%r14), %rbx
movq %rdi, 0x20(%r14)
movq 0xf328(%rip), %rax      # 0x1eff8
movq (%rax), %rsi
movq %r14, %rdi
movl $0x1, %edx
callq 0xb1c3
movq 0x10(%rsp), %rdi
movq %rbx, 0x20(%r14)
testq %r13, %r13
je 0xfd78
movq 0x10(%rdi), %rax
xorpd %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
xorl %ecx, %ecx
movsd 0x9886(%rip), %xmm0     # 0x19590
movapd 0x988e(%rip), %xmm1     # 0x195a0
movq 0x58(%rsp), %rdi
movq 0x28(%rsp), %rdx
movl (%rdx,%rcx,4), %edx
movl %edx, 0x1c(%rsp)
leaq (%rdx,%rdx,4), %rdx
testb $0x40, 0x23(%rax,%rdx,8)
jne 0xfd5a
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 0x40(%rsp), %xmm2
addsd %xmm3, %xmm2
movsd %xmm2, 0x40(%rsp)
incq %rcx
cmpq %rcx, %r13
jne 0xfd17
movsd 0x40(%rsp), %xmm0
mulsd 0x97f8(%rip), %xmm0     # 0x19568
movsd %xmm0, 0x40(%rsp)
jmp 0xfd87
xorpd %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x58(%rsp), %rdi
movl $0x1, %esi
callq 0x3240
movq %rax, %r10
testq %r13, %r13
movq 0x10(%rsp), %rdx
movq 0x20(%rsp), %rdi
je 0x104c8
movl %ebp, %eax
movsd 0x97bf(%rip), %xmm0     # 0x19570
mulsd 0x90(%rsp), %xmm0
movsd %xmm0, 0x88(%rsp)
movq 0x78(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
addq $0x18, %rax
movq %rax, 0xd8(%rsp)
xorl %ebx, %ebx
movq %r10, 0x48(%rsp)
movq 0x28(%rsp), %rax
movl (%rax,%rbx,4), %eax
movl %eax, 0x1c(%rsp)
cmpb $0x0, (%r10,%rax)
jne 0x10457
movq 0x10(%rdx), %rcx
leaq (%rax,%rax,4), %rax
testb $0x40, 0x23(%rcx,%rax,8)
jne 0x10457
movq %rbx, 0x78(%rsp)
xorl %r14d, %r14d
movq %rdx, %rdi
xorl %esi, %esi
callq 0xad23
movq %rax, %rbx
movl $0x1, (%rsp)
movq %rax, %rdi
leaq 0x1c(%rsp), %rsi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x1495a
movq %rbx, %rdi
movq 0x48(%rsp), %rdx
movq 0xd8(%rsp), %rbp
xorl %r8d, %r8d
xorl %eax, %eax
xorl %r12d, %r12d
xorl %r9d, %r9d
xorl %esi, %esi
movq %rbx, 0x60(%rsp)
movq 0x28(%rsp), %rcx
movl (%rcx,%r14,4), %ebx
movq 0x10(%rdi), %rcx
leaq (%rbx,%rbx,4), %r15
testb $0x40, 0x23(%rcx,%r15,8)
jne 0xfee3
cmpq %rax, %r8
jne 0xfecc
leaq (%rax,%rax), %r13
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %r13
movl %esi, 0x30(%rsp)
leaq (,%r13,4), %rsi
movq %r12, %rdi
movl %r9d, 0x50(%rsp)
movq %r8, %r12
callq 0x3330
movl 0x30(%rsp), %esi
movq 0x60(%rsp), %rdi
movq %r12, %r8
movl 0x50(%rsp), %r9d
movq 0x48(%rsp), %rdx
movq %rax, %r12
movq %r13, %rax
movq 0x70(%rsp), %r13
movl %ebx, (%r12,%r8,4)
movq 0x10(%rdi), %rcx
addl 0x18(%rcx,%r15,8), %r9d
incq %r8
addl (%rbp), %esi
movb $0x1, (%rdx,%rbx)
incq %r14
addq $0x30, %rbp
cmpq %r14, %r13
jne 0xfe61
movl %r9d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd 0x40(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x1014f
testl %esi, %esi
je 0x1014f
movq %r12, 0xd0(%rsp)
movl %r9d, 0x50(%rsp)
movq %r8, 0xa0(%rsp)
movq %rdi, %rdx
addq $0x10, %rdx
xorl %r12d, %r12d
movq 0xa8(%rsp), %rbx
movl 0x3c(%rsp), %ebp
movq 0x80(%rsp), %r15
movq %rdx, 0x58(%rsp)
movq 0x28(%rsp), %rax
movl (%rax,%r12,4), %r9d
movq (%rdx), %rax
leaq (%r9,%r9,4), %rsi
movl 0x20(%rax,%rsi,8), %ecx
btl $0x1e, %ecx
jb 0x1012d
cmpl %ebp, (%rbx,%r12,4)
je 0x1012d
leaq (%rax,%rsi,8), %rdi
cmpq %r15, 0x18(%rdi)
jae 0x1012d
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd 0x88(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x1012d
movq 0x10(%rsp), %r8
movq 0x28(%r8), %rcx
movq 0x30(%r8), %rdx
movq %r9, 0x30(%rsp)
addl %r9d, %r9d
movq 0x38(%r8), %r10
addq $0x20, %rcx
xorl %r11d, %r11d
xorl %r8d, %r8d
xorl %ebx, %ebx
leaq (%r11,%r9), %r15
movl (%r10,%r15,8), %r14d
testq %r14, %r14
je 0x1001f
movq (%rdx,%r15,8), %r15
leaq (%r15,%r15,2), %r15
shlq $0x4, %r15
addq %rcx, %r15
shlq $0x4, %r14
leaq (%r14,%r14,2), %rbp
xorl %r14d, %r14d
movq 0x20(%rsp), %rdi
movq -0x18(%r15,%r14), %r13
shrq %r13
cmpb $0x1, (%rdi,%r13)
sbbl $-0x1, %ebx
movb 0x3(%r15,%r14), %r13b
andb $0x40, %r13b
cmpb $0x1, %r13b
adcl $0x0, %r8d
addq $0x30, %r14
cmpq %r14, %rbp
jne 0xfff5
leaq 0x1(%r11), %r14
testq %r11, %r11
movq %r14, %r11
je 0xffc9
testl %ebx, %ebx
movq 0xa8(%rsp), %rbx
movl 0x3c(%rsp), %ebp
movl 0x130(%rsp), %r14d
movq 0x70(%rsp), %r13
movq 0x80(%rsp), %r15
movq 0x58(%rsp), %rdx
movq 0x30(%rsp), %r9
je 0x1012d
movl 0x20(%rax,%rsi,8), %edi
movl %edi, %ecx
movl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
andl %edx, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %r8d, %xmm0
mulsd 0x90(%rsp), %xmm0
mulsd 0x944c(%rip), %xmm0     # 0x194d0
cvttsd2si %xmm0, %r8
andl %edx, %r8d
andl $0xc0000000, %edi       # imm = 0xC0000000
orl %r8d, %edi
movl %edi, 0x20(%rax,%rsi,8)
leal (%r9,%r9), %eax
xorl %edx, %edx
leaq (%rdx,%rax), %rdi
movq 0x10(%rsp), %r8
movq 0x38(%r8), %r8
movl (%r8,%rdi,8), %r8d
testq %r8, %r8
je 0x10111
movq 0x10(%rsp), %r10
movq 0x28(%r10), %r9
movq 0x30(%r10), %r10
movq (%r10,%rdi,8), %rdi
leaq (%rdi,%rdi,2), %rdi
shlq $0x4, %rdi
addq %r9, %rdi
addq $0x20, %rdi
shlq $0x4, %r8
leaq (%r8,%r8,2), %r8
xorl %r9d, %r9d
movl (%rdi,%r9), %r10d
btl $0x1e, %r10d
jb 0x10108
movl %r10d, %r11d
andl $0x3fffffff, %r11d      # imm = 0x3FFFFFFF
cmpl %ecx, %r11d
jbe 0x10108
andl $0x80000000, %r10d      # imm = 0x80000000
orl %ecx, %r10d
movl %r10d, (%rdi,%r9)
addq $0x30, %r9
cmpq %r9, %r8
jne 0x100e0
leaq 0x1(%rdx), %rdi
testq %rdx, %rdx
movq %rdi, %rdx
je 0x1009f
cmpl $0x3, %r14d
movq 0x58(%rsp), %rdx
movq 0x30(%rsp), %rsi
jge 0x1013b
incq %r12
cmpq %r13, %r12
jne 0xff4e
jmp 0x10175
movq 0x98(%rsp), %rdi
callq 0x3b25
movq 0x58(%rsp), %rdx
jmp 0x1012d
callq 0x118c4
movq %r12, %rdi
callq 0x3060
movq 0x10(%rsp), %rdx
movq 0x20(%rsp), %rdi
movq 0x48(%rsp), %r10
movq 0x78(%rsp), %rbx
jmp 0x10457
movq 0xa0(%rsp), %rax
leaq (,%rax,4), %rsi
movq 0xd0(%rsp), %rdi
callq 0x3330
movq 0x60(%rsp), %rdx
movq %rax, 0x30(%rsp)
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %ebp, %ebp
xorl %r14d, %r14d
movq 0x28(%rsp), %rax
movl (%rax,%r12,4), %r15d
movq 0x10(%rdx), %rax
leaq (%r15,%r15,4), %rcx
testb $0x40, 0x23(%rax,%rcx,8)
jne 0x1024c
movq 0xe0(%rsp), %rax
movq 0x10(%rax), %rbx
shlq $0x6, %r15
movl 0x28(%rbx,%r15), %eax
addq %r13, %rax
cmpq %rbp, %rax
jbe 0x1022a
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, %rbp
shrq $0x10, %rbp
orq %rax, %rbp
leaq 0x8(,%rbp,8), %rsi
incq %rbp
movq %r14, %rdi
callq 0x3330
movq %rax, %r14
addq %r15, %rbx
leaq (%r14,%r13,8), %rdi
movq 0x30(%rbx), %rsi
movl 0x28(%rbx), %edx
shlq $0x3, %rdx
callq 0x32c0
movl 0x28(%rbx), %eax
addq %rax, %r13
movq 0x60(%rsp), %rdx
incq %r12
cmpq %r12, 0x70(%rsp)
jne 0x101a7
movl $0x8, %edx
movq %r14, %rdi
movq %r13, %rsi
leaq -0x3181(%rip), %rcx     # 0xd0eb
callq 0x30c0
testq %r13, %r13
je 0x102b2
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %eax, %eax
xorl %r12d, %r12d
movl 0x130(%rsp), %r15d
movq (%r14,%rax,8), %rdx
movq %rdx, %rsi
shrq $0x20, %rsi
cmpl %ecx, %esi
je 0x102a6
movl %r12d, %ecx
incl %r12d
movq %rdx, (%r14,%rcx,8)
movl 0x4(%r14,%rax,8), %ecx
incq %rax
movl %eax, %edx
cmpq %rdx, %r13
ja 0x10288
jmp 0x102bd
xorl %r12d, %r12d
movl 0x130(%rsp), %r15d
movl %r12d, %ebx
leaq (,%rbx,8), %rsi
movq %r14, %rdi
callq 0x3330
movq %rax, %r14
xorpd %xmm0, %xmm0
movapd %xmm0, 0xb0(%rsp)
movapd %xmm0, 0xc0(%rsp)
testl %r12d, %r12d
je 0x1031f
xorl %eax, %eax
movq (%r14,%rax,8), %rcx
movl %ecx, %edx
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
shrq $0x20, %rcx
andl $0x3, %ecx
addsd 0xb0(%rsp,%rcx,8), %xmm0
movsd %xmm0, 0xb0(%rsp,%rcx,8)
incq %rax
cmpq %rax, %rbx
jne 0x102f0
xorl %eax, %eax
movsd 0x91ff(%rip), %xmm0     # 0x19528
movapd %xmm0, %xmm1
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x70(%rsp), %r13
movq 0x20(%rsp), %rdi
movq 0x128(%rsp), %rsi
movq 0x48(%rsp), %r10
movl %ebx, %ecx
movsd 0xb0(%rsp,%rax,8), %xmm3
ucomisd %xmm0, %xmm3
jbe 0x10363
movl %eax, %ebx
movl %ecx, %ebp
movapd %xmm3, %xmm2
jmp 0x1037f
movl %ecx, %ebx
ucomisd %xmm1, %xmm3
jbe 0x10377
movl %eax, %ebp
movapd %xmm0, %xmm2
movapd %xmm3, %xmm0
jmp 0x1037f
movapd %xmm0, %xmm2
movapd %xmm1, %xmm0
incq %rax
movapd %xmm0, %xmm1
movapd %xmm2, %xmm0
cmpq $0x4, %rax
jne 0x10348
movq 0x8(%rsi), %rax
cmpq %rax, (%rsi)
jne 0x103d8
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq 0x128(%rsp), %rax
movq %rsi, 0x8(%rax)
movq 0x10(%rax), %rdi
shlq $0x6, %rsi
callq 0x3330
movq 0x48(%rsp), %r10
movq 0x128(%rsp), %rsi
movq 0x20(%rsp), %rdi
movq %rax, 0x10(%rsi)
movq (%rsi), %rax
movq 0x10(%rsi), %rcx
leaq 0x1(%rax), %rdx
shlq $0x6, %rax
movq %rdx, (%rsi)
movl 0x3c(%rsp), %esi
movl %esi, (%rcx,%rax)
movl %ebx, %edx
movsd 0xb0(%rsp,%rdx,8), %xmm0
movsd %xmm0, 0x8(%rcx,%rax)
movl %ebp, %edx
movsd 0xb0(%rsp,%rdx,8), %xmm0
movsd %xmm0, 0x10(%rcx,%rax)
movl 0x50(%rsp), %r9d
movl %r9d, 0x18(%rcx,%rax)
movq 0xa0(%rsp), %r8
movl %r8d, 0x1c(%rcx,%rax)
movq 0x30(%rsp), %rdx
movq %rdx, 0x20(%rcx,%rax)
movl %r12d, 0x28(%rcx,%rax)
movq %r14, 0x30(%rcx,%rax)
movq 0x60(%rsp), %rdx
movq %rdx, 0x38(%rcx,%rax)
testl %r15d, %r15d
movq 0x10(%rsp), %rdx
movq 0x78(%rsp), %rbx
jg 0x10465
incq %rbx
cmpq %r13, %rbx
jne 0xfddf
jmp 0x104c8
movq 0xeb8c(%rip), %rax      # 0x1eff8
movq (%rax), %rdi
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x1c(%rsp), %ecx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rcx
movsd 0xb8(%rsp), %xmm0
movsd 0xc0(%rsp), %xmm1
movsd 0xc8(%rsp), %xmm2
movl %esi, (%rsp)
leaq 0xa250(%rip), %rsi      # 0x1a6f9
leaq 0xa1e4(%rip), %rdx      # 0x1a694
movb $0x3, %al
callq 0x3290
movq 0x48(%rsp), %r10
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rdx
jmp 0x10457
movq %rdx, %rbx
movq %r10, %r14
callq 0x3060
movq %r14, %rdi
callq 0x3060
movq %rbx, %rdi
callq 0x118c4
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xeafc(%rip), %rbx      # 0x1eff8
movq (%rbx), %rdi
movl %ebp, %eax
leaq 0xe638(%rip), %rcx      # 0x1eb40
movq (%rcx,%rax,8), %rcx
leaq 0xa12f(%rip), %rsi      # 0x1a642
leaq 0xa17a(%rip), %rdx      # 0x1a694
movsd 0x90(%rsp), %xmm0
movb $0x1, %al
callq 0x3290
cmpl $0x2, 0x130(%rsp)
je 0xf7f6
movq %rbx, %rcx
movq %r12, %rbx
movq 0x68(%rsp), %r12
movq 0x20(%r12), %r14
movq 0x10(%rsp), %rax
movq %rax, 0x20(%r12)
movq (%rcx), %rsi
movq %r12, %rdi
movl $0x1, %edx
callq 0xb1c3
movq %r14, 0x20(%r12)
movq %rbx, %r12
jmp 0xf7f6