// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]oatk/syncmer.c
// Function: syncmer_link_coverage_analysis
int syncmer_link_coverage_analysis(sr_db_t *sr_db, syncmer_db_t *scm_db, uint32_t min_k_cov, uint32_t min_n_seq, 
        uint32_t min_pt, double min_f, double **_beta, double **_bse, double **_r2, int verbose)
{
    uint64_t i, j;
    syncmer_t *scm;
    
    min_pt = MAX(min_pt, 30);
    min_f  = MAX(min_f,  .0);

    scm = scm_db->a;

    // collect read length - syncmer count
    kh_ctab_t *rl_ctab;
    int64_t *rl_cnts, *rd_cnts;
    uint32_t max_n;
    rl_ctab = kh_ctab_init();
    max_n = 0;
    for (i = 0; i < sr_db->n; ++i) {
        max_n = MAX(max_n, sr_db->a[i].n);
        kh_ctab_put1(rl_ctab, sr_db->a[i].n);
    }
    if (max_n == 0) return 0;

    rl_cnts = kh_ctab_cnt(rl_ctab, max_n);
    kh_ctab_destroy(rl_ctab);
    
    // rl_cnts cumsum from end to beg
    // rl_cnts size is max_n+1
    for (i = 0; i < max_n; ++i)
        rl_cnts[max_n-i-1] += rl_cnts[max_n-i];

#ifdef DEBUG_LINK_COVERAGE
    for (i = 0; i <= max_n; ++i)
        fprintf(stderr, "[DEBUG_LINK_COVERAGE::%s] rl_cnts: %lu %ld\n", __func__, i, rl_cnts[i]);
#endif

    kh_scm_t *a_cov; // arc cov
    kh_kcn_t *k_cn; // scm copy number
    sr_t *s;
    uint32_t a, c, v_v, n1, *pt_n;
    uint64_t v0, v1, *scm_id;
    uint128_t v_p;
    double *beta, *bse, *r2, c0, c1;
    kvec_t(pt1_t) pt1;
    khint_t k;

    a_cov = kh_scm_init();
    k_cn = kh_kcn_init();
    kv_init(pt1);
    MYMALLOC(scm_id, max_n);
    MYCALLOC(rd_cnts, max_n+1);
    MYCALLOC(beta, max_n);
    MYCALLOC(bse, max_n);
    MYCALLOC(r2, max_n);
    MYCALLOC(pt_n, max_n);
    n1 = 0;
    for (i = 2; i < max_n; ++i) {
        if (rl_cnts[i] < min_n_seq) break;
        // do coverage analysis
        // the gap will be i-2
        kh_scm_m_clear(a_cov);
        for (j = 0; j < sr_db->n; ++j) {
            s = &sr_db->a[j];
            if (s->n < i) continue;
            // collect scm_id along reads
            for (a = 0; a < s->n; ++a)
                scm_id[a] = s->k_mer[a] >> 1;
            // collect coverage
            for (a = i-1; a < s->n; ++a) {
                if (scm[scm_id[a+1-i]].cov < min_k_cov || 
                        scm[scm_id[a]].cov < min_k_cov)
                    continue;
                v0 = scm_id[a+1-i] << 1 | (s->m_pos[a+1-i] & 1);
                v1 = scm_id[a] << 1 | (s->m_pos[a] & 1);
                v0 <= v1? kh_scm_add(a_cov, (uint128_t) v0 << 64 | v1, 1) :
                    kh_scm_add(a_cov, ((uint128_t) v1^1) << 64 | (v0^1), 1);
                // rd_cnts collects the pair number of a given gap in the data
                ++rd_cnts[i];
            }
        }

        if (i == 2) {
            // kmer copy number estimation
            for (k = (khint_t) 0; k < kh_end(a_cov); ++k) {
                if (!kh_exist(a_cov, k)) continue;
                v_p = kh_key(a_cov, k);
                kh_kcn_put1(k_cn, (uint64_t) (v_p >> 65));
                kh_kcn_put1(k_cn, ((uint64_t) v_p) >> 1);
            }

#ifdef DEBUG_LINK_COVERAGE
            for (k = (khint_t) 0; k < kh_end(k_cn); ++k) {
                if (!kh_exist(k_cn, k)) continue;
                fprintf(stderr, "[DEBUG_LINK_COVERAGE::%s] k_cn: %lu %d\n", __func__, i-2, kh_val(k_cn, k));
            }
#endif
        }

#ifdef DEBUG_LINK_COVERAGE
        if ((i-2) % 3 == 0) {
            // print arc cov stats
            for (k = (khint_t) 0; k < kh_end(a_cov); ++k) {
                if (!kh_exist(a_cov, k)) continue;
                v_p = kh_key(a_cov, k);
                v_v = kh_val(a_cov, k);
                v0 = (uint64_t) (v_p >> 65);
                v1 = ((uint64_t) v_p) >> 1;
                c0 = MAX(2, kh_kcn_get1(k_cn, v0)) / 2.0;
                c1 = MAX(2, kh_kcn_get1(k_cn, v1)) / 2.0;
                c = (uint32_t) (MIN(scm[v0].cov/c0, scm[v1].cov/c1));
                v_v = MIN(v_v, c);
                fprintf(stderr, "[DEBUG_LINK_COVERAGE::%s] lc_cnts: %lu %u %u\n", __func__, i-2, c, v_v);
            }
        }
#endif

        // collect covs
        pt1.n = 0;
        for (k = (khint_t) 0; k < kh_end(a_cov); ++k) {
            if (!kh_exist(a_cov, k)) continue;
            v_p = kh_key(a_cov, k);
            v_v = kh_val(a_cov, k);
            v0 = (uint64_t) (v_p >> 65);
            v1 = ((uint64_t) v_p) >> 1;
            c0 = MAX(2, kh_kcn_get1(k_cn, v0)) / 2.0;
            c1 = MAX(2, kh_kcn_get1(k_cn, v1)) / 2.0;
            c = (uint32_t) (MIN(scm[v0].cov/c0, scm[v1].cov/c1));
            v_v = MIN(v_v, c);
            pt1_t pt = {c, v_v, (double) v_v / c};
            kv_push(pt1_t, pt1, pt);
        }
        
        uint32_t beg, end;
        /***
        beg = floor(pt1.n * .01);
        end =  ceil(pt1.n * .99);
        // sort pt by c
        qsort(pt1.a, pt1.n, sizeof(pt1_t), pt1_c_cmpfunc);
        // mask the lower 1% and upper 1% of data
        for (j = 0; j < beg; ++j) pt1.a[j].f = -1.0;
        for (j = end; j < pt1.n; ++j) pt1.a[j].f = -1.0;
        // sort pt by l
        qsort(pt1.a, pt1.n, sizeof(pt1_t), pt1_l_cmpfunc);
        // mask the lower 1% and upper 1% of data
        for (j = 0; j < beg; ++j) pt1.a[j].f = -1.0;
        for (j = end; j < pt1.n; ++j) pt1.a[j].f = -1.0;
        **/
        beg = floor(pt1.n * .05);
        end =  ceil(pt1.n * .95);
        // sort pt by l/c
        qsort(pt1.a, pt1.n, sizeof(pt1_t), pt1_f_cmpfunc);
        // estimate slope using the middle 90% data
        while (beg < end && pt1.a[beg].f < min_f)
            ++beg;
        
        if (end - beg < min_pt)
            break;

        if (verbose > 1) {
            for (j = beg; j < end; ++j)
                fprintf(stderr, "[M::%s] pt1: %lu %lu %u %u %.6f\n", __func__, i-2, j, pt1.a[j].c, pt1.a[j].l, pt1.a[j].f);
        }

        // do estimation
        double xy, x2, ybar;
        xy = x2 = ybar = .0;
        for (j = beg; j < end; ++j) {
            xy += (double) pt1.a[j].c * pt1.a[j].l;
            x2 += (double) pt1.a[j].c * pt1.a[j].c;
            ybar += pt1.a[j].l;
        }
        beta[i] = xy / x2;
        ybar /= end - beg;
        // calculate r2
        double res, tot, r;
        res = tot = .0;
        for (j = beg; j < end; ++j) {
            r = pt1.a[j].l - beta[i] * pt1.a[j].c;
            res += r * r;
            r = pt1.a[j].l - ybar;
            tot += r * r;
        }
        bse[i] = sqrt(res / x2 / (end - beg - 1));
        r2[i] = 1 - (tot == .0? .0 : res / tot);
        pt_n[i] = end - beg;
        n1 = i;
    }

#ifdef DEBUG_LINK_COVERAGE
    for (i = 0; i <= max_n; ++i)
        fprintf(stderr, "[DEBUG_LINK_COVERAGE::%s] rd_cnts: %lu %ld\n", __func__, i, rd_cnts[i]);
    for (i = 2; i < max_n; ++i)
        fprintf(stderr, "[DEBUG_LINK_COVERAGE::%s] rd_regs: %lu %u %.6f %.6f %.6f\n", __func__, 
                i-2, pt_n[i], beta[i], bse[i], r2[i]);
#endif

    if (verbose > 0) {
        for (i = 2; i < n1; ++i)
            fprintf(stderr, "[M::%s] G: %lu N: %u D: %ld coeff: %.6f bse: %.6f R2: %.6f\n", __func__, 
                    i-2, pt_n[i], rd_cnts[i], beta[i], bse[i], r2[i]);
    }

    if (n1 > 0) {
        // copy results
        if (_beta) {
            MYMALLOC(*_beta, n1 - 1);
            memcpy(*_beta, &beta[2], n1 - 1);
        }
        if (_bse) {
            MYMALLOC(*_bse, n1 - 1);
            memcpy(*_bse, &bse[2], n1 - 1);
        }
        if (_r2) {
            MYMALLOC(*_r2, n1 - 1);
            memcpy(*_r2, &r2[2], n1 - 1);
        }
    }

    kh_scm_destroy(a_cov);
    kh_kcn_destroy(k_cn);
    kv_destroy(pt1);
    free(scm_id);
    free(rl_cnts);
    free(rd_cnts);
    free(beta);
    free(bse);
    free(r2);
    free(pt_n);

    return n1 > 0? (n1 - 1) : 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
movl 0x20(%rbp), %eax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movsd %xmm0, -0x30(%rbp)
movq %r9, -0x38(%rbp)
cmpl $0x1e, -0x24(%rbp)
jbe 0x154c2
movl -0x24(%rbp), %eax
movl %eax, -0x18c(%rbp)
jmp 0x154cf
movl $0x1e, %eax
movl %eax, -0x18c(%rbp)
jmp 0x154cf
movl -0x18c(%rbp), %eax
movl %eax, -0x24(%rbp)
movsd -0x30(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x154f5
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x198(%rbp)
jmp 0x15502
xorps %xmm0, %xmm0
movsd %xmm0, -0x198(%rbp)
jmp 0x15502
movsd -0x198(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
callq 0x12e70
movq %rax, -0x58(%rbp)
movl $0x0, -0x6c(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x155af
movl -0x6c(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
imulq $0x58, -0x40(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x38(%rcx), %eax
jbe 0x15563
movl -0x6c(%rbp), %eax
movl %eax, -0x19c(%rbp)
jmp 0x1557c
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x58, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0x38(%rax), %eax
movl %eax, -0x19c(%rbp)
movl -0x19c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movq -0x58(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x58, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0x38(%rax), %esi
callq 0x12e80
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x15533
cmpl $0x0, -0x6c(%rbp)
jne 0x155c1
movl $0x0, -0x4(%rbp)
jmp 0x164fb
movq -0x58(%rbp), %rdi
movl -0x6c(%rbp), %esi
callq 0x13100
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rdi
callq 0x13ad0
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl -0x6c(%rbp), %ecx
cmpq %rcx, %rax
jae 0x15622
movq -0x60(%rbp), %rax
movl -0x6c(%rbp), %ecx
subq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x60(%rbp), %rax
movl -0x6c(%rbp), %ecx
subq -0x40(%rbp), %rcx
subq $0x1, %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x155e2
callq 0x16510
movq %rax, -0x78(%rbp)
callq 0x16520
movq %rax, -0x80(%rbp)
movq $0x0, -0x108(%rbp)
movq $0x0, -0x110(%rbp)
movq $0x0, -0x100(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x2320
movq %rax, -0xb8(%rbp)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
movl $0x8, %esi
callq 0x2250
movq %rax, -0x68(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, %edi
movl $0x8, %esi
callq 0x2250
movq %rax, -0xd8(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, %edi
movl $0x8, %esi
callq 0x2250
movq %rax, -0xe0(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, %edi
movl $0x8, %esi
callq 0x2250
movq %rax, -0xe8(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, %edi
movl $0x4, %esi
callq 0x2250
movq %rax, -0xa0(%rbp)
movl $0x0, -0x98(%rbp)
movq $0x2, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl -0x6c(%rbp), %ecx
cmpq %rcx, %rax
jae 0x162c8
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x20(%rbp), %ecx
cmpq %rcx, %rax
jge 0x15715
jmp 0x162c8
movq -0x78(%rbp), %rdi
callq 0x16530
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x15982
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x58, -0x48(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movl 0x38(%rax), %eax
cmpq -0x40(%rbp), %rax
jae 0x15763
jmp 0x15971
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movq -0x88(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jae 0x157b9
movq -0x88(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x8c(%rbp), %ecx
movq (%rax,%rcx,8), %rdx
shrq %rdx
movq -0xb8(%rbp), %rax
movl -0x8c(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x1576d
movq -0x40(%rbp), %rax
subq $0x1, %rax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movq -0x88(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jae 0x1596f
movq -0x50(%rbp), %rax
movq -0xb8(%rbp), %rcx
movl -0x8c(%rbp), %edx
addl $0x1, %edx
movl %edx, %edx
subq -0x40(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl -0x1c(%rbp), %eax
jb 0x15838
movq -0x50(%rbp), %rax
movq -0xb8(%rbp), %rcx
movl -0x8c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl -0x1c(%rbp), %eax
jae 0x1583d
jmp 0x1595b
movq -0xb8(%rbp), %rax
movl -0x8c(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
subq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shlq %rax
movq -0x88(%rbp), %rcx
movq 0x40(%rcx), %rcx
movl -0x8c(%rbp), %edx
addl $0x1, %edx
movl %edx, %edx
subq -0x40(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
andl $0x1, %ecx
movl %ecx, %ecx
orq %rcx, %rax
movq %rax, -0xa8(%rbp)
movq -0xb8(%rbp), %rax
movl -0x8c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shlq %rax
movq -0x88(%rbp), %rcx
movq 0x40(%rcx), %rcx
movl -0x8c(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
andl $0x1, %ecx
movl %ecx, %ecx
orq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rax
cmpq -0xb0(%rbp), %rax
ja 0x15907
movq -0x78(%rbp), %rdi
movq -0xa8(%rbp), %rcx
movq -0xb0(%rbp), %rax
movq %rcx, -0x128(%rbp)
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rsi
movq -0x128(%rbp), %rdx
movl $0x1, %ecx
callq 0x165b0
jmp 0x15947
movq -0x78(%rbp), %rdi
movq -0xb0(%rbp), %rcx
xorq $0x1, %rcx
movq -0xa8(%rbp), %rax
xorq $0x1, %rax
movq %rcx, -0x138(%rbp)
movq %rax, -0x140(%rbp)
movq -0x140(%rbp), %rsi
movq -0x138(%rbp), %rdx
movl $0x1, %ecx
callq 0x165b0
movq -0x68(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x157c7
jmp 0x15971
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x15726
cmpq $0x2, -0x40(%rbp)
jne 0x15a71
movl $0x0, -0x114(%rbp)
movl -0x114(%rbp), %eax
movl %eax, -0x1a0(%rbp)
movq -0x78(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x159c3
movq -0x78(%rbp), %rax
movl (%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x1a4(%rbp)
jmp 0x159cd
xorl %eax, %eax
movl %eax, -0x1a4(%rbp)
jmp 0x159cd
movl -0x1a0(%rbp), %eax
movl -0x1a4(%rbp), %ecx
cmpl %ecx, %eax
jae 0x15a6f
movq -0x78(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x114(%rbp), %ecx
shrl $0x5, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl -0x114(%rbp), %ecx
andl $0x1f, %ecx
shrl %cl, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x15a0c
jmp 0x15a5b
movq -0x78(%rbp), %rax
movq 0x10(%rax), %rcx
movl -0x114(%rbp), %eax
leaq (%rax,%rax,2), %rdx
movq (%rcx,%rdx,8), %rax
movq 0x8(%rcx,%rdx,8), %rcx
movq %rcx, -0xc8(%rbp)
movq %rax, -0xd0(%rbp)
movq -0x80(%rbp), %rdi
movq -0xc8(%rbp), %rsi
shrq %rsi
callq 0x16650
movq -0x80(%rbp), %rdi
movq -0xd0(%rbp), %rsi
shrq %rsi
callq 0x16650
movl -0x114(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0x15997
jmp 0x15a71
movq $0x0, -0x110(%rbp)
movl $0x0, -0x114(%rbp)
movl -0x114(%rbp), %eax
movl %eax, -0x1a8(%rbp)
movq -0x78(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x15ab2
movq -0x78(%rbp), %rax
movl (%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x1ac(%rbp)
jmp 0x15abc
xorl %eax, %eax
movl %eax, -0x1ac(%rbp)
jmp 0x15abc
movl -0x1a8(%rbp), %eax
movl -0x1ac(%rbp), %ecx
cmpl %ecx, %eax
jae 0x15e03
movq -0x78(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x114(%rbp), %ecx
shrl $0x5, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl -0x114(%rbp), %ecx
andl $0x1f, %ecx
shrl %cl, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x15afe
jmp 0x15def
movq -0x78(%rbp), %rax
movq 0x10(%rax), %rcx
movl -0x114(%rbp), %eax
leaq (%rax,%rax,2), %rdx
movq (%rcx,%rdx,8), %rax
movq 0x8(%rcx,%rdx,8), %rcx
movq %rcx, -0xc8(%rbp)
movq %rax, -0xd0(%rbp)
movq -0x78(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x114(%rbp), %ecx
leaq (%rcx,%rcx,2), %rcx
movl 0x10(%rax,%rcx,8), %eax
movl %eax, -0x94(%rbp)
movq -0xc8(%rbp), %rax
shrq %rax
movq %rax, -0xa8(%rbp)
movq -0xd0(%rbp), %rax
shrq %rax
movq %rax, -0xb0(%rbp)
movq -0x80(%rbp), %rdi
movq -0xa8(%rbp), %rsi
callq 0x166c0
movl %eax, %ecx
movl $0x2, %eax
cmpl %ecx, %eax
jle 0x15b8d
movl $0x2, %eax
movl %eax, -0x1b0(%rbp)
jmp 0x15ba3
movq -0x80(%rbp), %rdi
movq -0xa8(%rbp), %rsi
callq 0x166c0
movl %eax, -0x1b0(%rbp)
movl -0x1b0(%rbp), %eax
cvtsi2sd %eax, %xmm0
movsd 0x1839b(%rip), %xmm1    # 0x2df50
divsd %xmm1, %xmm0
movsd %xmm0, -0xf0(%rbp)
movq -0x80(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0x166c0
movl %eax, %ecx
movl $0x2, %eax
cmpl %ecx, %eax
jle 0x15be9
movl $0x2, %eax
movl %eax, -0x1b4(%rbp)
jmp 0x15bff
movq -0x80(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0x166c0
movl %eax, -0x1b4(%rbp)
movl -0x1b4(%rbp), %eax
cvtsi2sd %eax, %xmm0
movsd 0x1833f(%rip), %xmm1    # 0x2df50
divsd %xmm1, %xmm0
movsd %xmm0, -0xf8(%rbp)
movq -0x50(%rbp), %rax
movq -0xa8(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cvtsi2sd %eax, %xmm1
divsd -0xf0(%rbp), %xmm1
movq -0x50(%rbp), %rax
movq -0xb0(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cvtsi2sd %eax, %xmm0
divsd -0xf8(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x15c9f
movq -0x50(%rbp), %rax
movq -0xa8(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cvtsi2sd %eax, %xmm0
divsd -0xf0(%rbp), %xmm0
movsd %xmm0, -0x1c0(%rbp)
jmp 0x15ccd
movq -0x50(%rbp), %rax
movq -0xb0(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cvtsi2sd %eax, %xmm0
divsd -0xf8(%rbp), %xmm0
movsd %xmm0, -0x1c0(%rbp)
movsd -0x1c0(%rbp), %xmm0
cvttsd2si %xmm0, %rax
movl %eax, -0x90(%rbp)
movl -0x94(%rbp), %eax
cmpl -0x90(%rbp), %eax
jae 0x15cfc
movl -0x94(%rbp), %eax
movl %eax, -0x1c4(%rbp)
jmp 0x15d08
movl -0x90(%rbp), %eax
movl %eax, -0x1c4(%rbp)
movl -0x1c4(%rbp), %eax
movl %eax, -0x94(%rbp)
movl -0x90(%rbp), %eax
movl %eax, -0x150(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0x14c(%rbp)
movl -0x94(%rbp), %eax
cvtsi2sd %rax, %xmm0
movl -0x90(%rbp), %eax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x148(%rbp)
movq -0x110(%rbp), %rax
cmpq -0x108(%rbp), %rax
jne 0x15db5
cmpq $0x0, -0x108(%rbp)
je 0x15d7b
movq -0x108(%rbp), %rax
shlq %rax
movq %rax, -0x1d0(%rbp)
jmp 0x15d89
movl $0x2, %eax
movq %rax, -0x1d0(%rbp)
jmp 0x15d89
movq -0x1d0(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x100(%rbp), %rdi
movq -0x108(%rbp), %rsi
shlq $0x4, %rsi
callq 0x2360
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rax
movq -0x110(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x110(%rbp)
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x150(%rbp), %rcx
movq %rcx, (%rax)
movq -0x148(%rbp), %rcx
movq %rcx, 0x8(%rax)
jmp 0x15def
movl -0x114(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0x15a86
movq -0x110(%rbp), %xmm0
movaps 0x179ae(%rip), %xmm1    # 0x2d7c0
movaps %xmm1, -0x1f0(%rbp)
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x179ab(%rip), %xmm1    # 0x2d7d0
movaps %xmm1, -0x1e0(%rbp)
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x180f5(%rip), %xmm1    # 0x2df38
mulsd %xmm1, %xmm0
callq 0x2410
movaps -0x1f0(%rbp), %xmm2
movaps -0x1e0(%rbp), %xmm1
cvttsd2si %xmm0, %rax
movl %eax, -0x154(%rbp)
movq -0x110(%rbp), %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x180b8(%rip), %xmm1    # 0x2df40
mulsd %xmm1, %xmm0
callq 0x24e0
cvttsd2si %xmm0, %rax
movl %eax, -0x158(%rbp)
movq -0x100(%rbp), %rdi
movq -0x110(%rbp), %rsi
movl $0x10, %edx
leaq 0x88a(%rip), %rcx       # 0x16740
callq 0x20d0
movl -0x154(%rbp), %ecx
xorl %eax, %eax
cmpl -0x158(%rbp), %ecx
movb %al, -0x1f1(%rbp)
jae 0x15efc
movq -0x100(%rbp), %rax
movl -0x154(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm1
movsd -0x30(%rbp), %xmm0
ucomisd %xmm1, %xmm0
seta %al
movb %al, -0x1f1(%rbp)
movb -0x1f1(%rbp), %al
testb $0x1, %al
jne 0x15f08
jmp 0x15f19
movl -0x154(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x154(%rbp)
jmp 0x15ebb
movl -0x158(%rbp), %eax
subl -0x154(%rbp), %eax
cmpl -0x24(%rbp), %eax
jae 0x15f2f
jmp 0x162c8
cmpl $0x1, 0x20(%rbp)
jle 0x15fd8
movl -0x154(%rbp), %eax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl -0x158(%rbp), %ecx
cmpq %rcx, %rax
jae 0x15fd6
movq 0x1e09b(%rip), %rax     # 0x33ff8
movq (%rax), %rdi
movq -0x40(%rbp), %rcx
subq $0x2, %rcx
movq -0x48(%rbp), %r8
movq -0x100(%rbp), %rax
movq -0x48(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl (%rax), %r9d
movq -0x100(%rbp), %rax
movq -0x48(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl 0x4(%rax), %eax
movq -0x100(%rbp), %rdx
movq -0x48(%rbp), %rsi
shlq $0x4, %rsi
addq %rsi, %rdx
movsd 0x8(%rdx), %xmm0
leaq 0x182de(%rip), %rsi     # 0x2e292
leaq 0x182f8(%rip), %rdx     # 0x2e2b3
movl %eax, (%rsp)
movb $0x1, %al
callq 0x2290
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x15f43
jmp 0x15fd8
xorps %xmm0, %xmm0
movsd %xmm0, -0x170(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x168(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x160(%rbp)
movl -0x154(%rbp), %eax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl -0x158(%rbp), %ecx
cmpq %rcx, %rax
jae 0x160b6
movq -0x100(%rbp), %rax
movq -0x48(%rbp), %rdx
shlq $0x4, %rdx
movl (%rax,%rdx), %ecx
movl 0x4(%rax,%rdx), %eax
cvtsi2sd %rcx, %xmm0
cvtsi2sd %rax, %xmm2
movsd -0x160(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x160(%rbp)
movq -0x100(%rbp), %rax
movq -0x48(%rbp), %rcx
shlq $0x4, %rcx
movl (%rax,%rcx), %eax
cvtsi2sd %rax, %xmm0
movsd -0x168(%rbp), %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x168(%rbp)
movq -0x100(%rbp), %rax
movq -0x48(%rbp), %rcx
shlq $0x4, %rcx
movl 0x4(%rax,%rcx), %eax
cvtsi2sd %rax, %xmm0
addsd -0x170(%rbp), %xmm0
movsd %xmm0, -0x170(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x16003
movsd -0x160(%rbp), %xmm0
movsd -0x168(%rbp), %xmm1
divsd %xmm1, %xmm0
movq -0xd8(%rbp), %rax
movq -0x40(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x158(%rbp), %eax
movl -0x154(%rbp), %ecx
subl %ecx, %eax
cvtsi2sd %rax, %xmm1
movsd -0x170(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x170(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x180(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x178(%rbp)
movl -0x154(%rbp), %eax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl -0x158(%rbp), %ecx
cmpq %rcx, %rax
jae 0x161f5
movq -0x100(%rbp), %rcx
movq -0x48(%rbp), %rdx
shlq $0x4, %rdx
movl (%rcx,%rdx), %eax
movl 0x4(%rcx,%rdx), %ecx
cvtsi2sd %rcx, %xmm0
movq -0xd8(%rbp), %rcx
movq -0x40(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm1
cvtsi2sd %rax, %xmm2
mulsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x188(%rbp)
movsd -0x188(%rbp), %xmm0
movsd -0x178(%rbp), %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x178(%rbp)
movq -0x100(%rbp), %rax
movq -0x48(%rbp), %rcx
shlq $0x4, %rcx
movl 0x4(%rax,%rcx), %eax
cvtsi2sd %rax, %xmm0
subsd -0x170(%rbp), %xmm0
movsd %xmm0, -0x188(%rbp)
movsd -0x188(%rbp), %xmm0
movsd -0x188(%rbp), %xmm2
movsd -0x180(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x180(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x16121
movsd -0x178(%rbp), %xmm0
movsd -0x168(%rbp), %xmm1
divsd %xmm1, %xmm0
movl -0x158(%rbp), %ecx
movl -0x154(%rbp), %eax
notl %eax
addl %ecx, %eax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
callq 0x2480
movq -0xe0(%rbp), %rax
movq -0x40(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd -0x180(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x16257
jp 0x16257
xorps %xmm0, %xmm0
movsd %xmm0, -0x200(%rbp)
jmp 0x1626f
movsd -0x178(%rbp), %xmm0
divsd -0x180(%rbp), %xmm0
movsd %xmm0, -0x200(%rbp)
movsd -0x200(%rbp), %xmm1
movsd 0x17509(%rip), %xmm0    # 0x2d788
subsd %xmm1, %xmm0
movq -0xe8(%rbp), %rax
movq -0x40(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x158(%rbp), %edx
subl -0x154(%rbp), %edx
movq -0xa0(%rbp), %rax
movq -0x40(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x40(%rbp), %rax
movl %eax, -0x98(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x156ec
cmpl $0x0, 0x20(%rbp)
jle 0x16372
movq $0x2, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl -0x98(%rbp), %ecx
cmpq %rcx, %rax
jae 0x16370
movq 0x1dd04(%rip), %rax     # 0x33ff8
movq (%rax), %rdi
movq -0x40(%rbp), %rcx
subq $0x2, %rcx
movq -0xa0(%rbp), %rax
movq -0x40(%rbp), %rdx
movl (%rax,%rdx,4), %r8d
movq -0x68(%rbp), %rax
movq -0x40(%rbp), %rdx
movq (%rax,%rdx,8), %r9
movq -0xd8(%rbp), %rax
movq -0x40(%rbp), %rdx
movsd (%rax,%rdx,8), %xmm0
movq -0xe0(%rbp), %rax
movq -0x40(%rbp), %rdx
movsd (%rax,%rdx,8), %xmm1
movq -0xe8(%rbp), %rax
movq -0x40(%rbp), %rdx
movsd (%rax,%rdx,8), %xmm2
leaq 0x17f81(%rip), %rsi     # 0x2e2d2
leaq 0x17f5b(%rip), %rdx     # 0x2e2b3
movb $0x3, %al
callq 0x2290
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x162da
jmp 0x16372
cmpl $0x0, -0x98(%rbp)
jbe 0x16462
cmpq $0x0, -0x38(%rbp)
je 0x163ca
movl -0x98(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x2320
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movq -0xd8(%rbp), %rsi
addq $0x10, %rsi
movl -0x98(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
callq 0x22c0
cmpq $0x0, 0x10(%rbp)
je 0x16415
movl -0x98(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x2320
movq %rax, %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movq 0x10(%rbp), %rax
movq (%rax), %rdi
movq -0xe0(%rbp), %rsi
addq $0x10, %rsi
movl -0x98(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
callq 0x22c0
cmpq $0x0, 0x18(%rbp)
je 0x16460
movl -0x98(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x2320
movq %rax, %rcx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
movq 0x18(%rbp), %rax
movq (%rax), %rdi
movq -0xe8(%rbp), %rsi
addq $0x10, %rsi
movl -0x98(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
callq 0x22c0
jmp 0x16462
movq -0x78(%rbp), %rdi
callq 0x167e0
movq -0x80(%rbp), %rdi
callq 0x16800
movq -0x100(%rbp), %rdi
callq 0x2060
movq -0xb8(%rbp), %rdi
callq 0x2060
movq -0x60(%rbp), %rdi
callq 0x2060
movq -0x68(%rbp), %rdi
callq 0x2060
movq -0xd8(%rbp), %rdi
callq 0x2060
movq -0xe0(%rbp), %rdi
callq 0x2060
movq -0xe8(%rbp), %rdi
callq 0x2060
movq -0xa0(%rbp), %rdi
callq 0x2060
cmpl $0x0, -0x98(%rbp)
jbe 0x164e8
movl -0x98(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x204(%rbp)
jmp 0x164f2
xorl %eax, %eax
movl %eax, -0x204(%rbp)
jmp 0x164f2
movl -0x204(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
nopw (%rax,%rax)