// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %r9, 0xb8(%rsp)
movsd %xmm0, 0x90(%rsp)
movl %ecx, %r14d
movl %edx, 0xc(%rsp)
movq %rdi, %rbx
cmpl $0x1f, %r8d
movl $0x1e, %eax
cmovael %r8d, %eax
movl %eax, 0xac(%rsp)
movq 0x10(%rsi), %rax
movq %rax, 0x38(%rsp)
movl $0x1, %esi
movl $0x20, %edx
xorl %edi, %edi
callq 0x1d660
movq $0x0, 0x18(%rax)
cmpq $0x0, (%rbx)
je 0x103da
movq %rax, %r15
xorpd %xmm0, %xmm0
movsd 0x90(%rsp), %xmm1
maxsd %xmm0, %xmm1
movsd %xmm1, 0x90(%rsp)
movq %rbx, %r13
movl $0x38, %ebx
xorl %ebp, %ebp
xorl %r12d, %r12d
movq 0x10(%r13), %rax
movl (%rax,%rbx), %esi
cmpl %esi, %ebp
cmovbel %esi, %ebp
movq %r15, %rdi
callq 0xe41f
incq %r12
addq $0x58, %rbx
cmpq (%r13), %r12
jb 0x1023f
testl %ebp, %ebp
je 0x103da
movq %r13, %rbx
movq %r15, %rdi
movq %rbp, 0x50(%rsp)
movl %ebp, %esi
callq 0xe83f
movq %rax, %r12
testq %r15, %r15
movq %rax, 0x48(%rsp)
je 0x102b3
movq 0x10(%r15), %rsi
movq 0x18(%r15), %r13
movq %r13, %rdi
callq 0x1d6fb
movq 0x8(%r15), %rsi
movq %r13, %rdi
callq 0x1d6fb
movq %r13, %rdi
movq 0x48(%rsp), %r12
movq %r15, %rsi
callq 0x1d6fb
movq %rbx, 0x98(%rsp)
movl 0x50(%rsp), %ecx
movq (%r12,%rcx,8), %rax
movq %rcx, 0x80(%rsp)
decq %rcx
addq (%r12,%rcx,8), %rax
movq %rax, (%r12,%rcx,8)
addq $-0x1, %rcx
jb 0x102ce
xorl %ebx, %ebx
movl $0x1, %esi
movl $0x20, %edx
xorl %edi, %edi
callq 0x1d660
movq %rax, %r13
movq %rbx, 0x18(%rax)
movl $0x1, %esi
movl $0x20, %edx
xorl %edi, %edi
callq 0x1d660
movq %rax, 0x78(%rsp)
movq $0x0, 0x10(%rsp)
movq %rbx, 0x18(%rax)
movq 0x80(%rsp), %rbp
leaq (,%rbp,8), %rdi
callq 0x2310
movq %rax, %r15
movq 0x50(%rsp), %rbx
leal 0x1(%rbx), %edi
movl $0x8, %esi
callq 0x2250
movq %rax, 0xa0(%rsp)
movl $0x8, %esi
movq %rbp, %rdi
callq 0x2250
movq %rax, 0x58(%rsp)
movl $0x8, %esi
movq %rbp, %rdi
callq 0x2250
movq %rax, 0x68(%rsp)
movl $0x8, %esi
movq %rbp, %rdi
callq 0x2250
movq %rax, 0x60(%rsp)
movl $0x4, %esi
movq %rbp, %rdi
callq 0x2250
movq %rax, 0x88(%rsp)
movl $0x0, %ebp
cmpl $0x3, %ebx
jb 0x10df3
movq %r13, 0x18(%rsp)
movl %r14d, %eax
movq %rax, 0xc0(%rsp)
cmpq %rax, 0x10(%r12)
movq 0x98(%rsp), %rbx
jge 0x103e1
movq $0x0, 0x40(%rsp)
movq $0x0, 0x10(%rsp)
jmp 0x10ca4
xorl %eax, %eax
jmp 0x10ea7
movq 0x50(%rsp), %rax
decl %eax
movq %rax, 0x50(%rsp)
addq $-0x2, 0x80(%rsp)
movl $0x1, %r13d
movq $0x0, 0x40(%rsp)
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movq $0x0, 0x10(%rsp)
movq $0x0, 0xb0(%rsp)
movl $0x2, %eax
movq 0x78(%rsp), %r12
movq 0x18(%rsp), %rbp
movl 0xc(%rsp), %r8d
movq %rax, 0x30(%rsp)
movq %r13, 0x70(%rsp)
movq 0x8(%rbp), %rdi
testq %rdi, %rdi
je 0x1047b
movl (%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
shrl $0x3, %edx
andl $-0x4, %edx
cmpl $0x5, %ecx
movl $0x4, %eax
cmovbl %eax, %edx
xorl %esi, %esi
callq 0x21e0
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movl 0xc(%rsp), %r8d
movl $0x0, 0x4(%rbp)
movq (%rbx), %rcx
testq %rcx, %rcx
movq 0x38(%rsp), %r9
je 0x105a5
movq 0x30(%rsp), %rax
decl %eax
movl %eax, 0x20(%rsp)
xorl %r14d, %r14d
movq 0x10(%rbx), %r13
imulq $0x58, %r14, %rdx
movl 0x38(%r13,%rdx), %eax
cmpq %rax, 0x30(%rsp)
ja 0x10599
addq %rdx, %r13
testl %eax, %eax
je 0x104d2
movq 0x50(%r13), %rdx
xorl %esi, %esi
movq (%rdx,%rsi,8), %rdi
shrq %rdi
movq %rdi, (%r15,%rsi,8)
incq %rsi
cmpq %rsi, %rax
jne 0x104bf
cmpl %eax, 0x20(%rsp)
jae 0x10599
xorl %ebx, %ebx
movq 0x70(%rsp), %rbp
movq (%r15,%rbx,2), %rcx
movq %rcx, %rdx
shlq $0x5, %rdx
movl 0x10(%r9,%rdx), %edx
andl %r10d, %edx
cmpl %r8d, %edx
jb 0x10577
movq (%r15,%rbp,8), %rsi
movq %rsi, %rdx
shlq $0x5, %rdx
movl 0x10(%r9,%rdx), %edx
andl %r10d, %edx
cmpl %r8d, %edx
jb 0x10577
movq 0x40(%r13), %rax
movl (%rax,%rbx), %edx
andl $0x1, %edx
leaq (%rdx,%rcx,2), %rdx
movl (%rax,%rbp,4), %eax
andl $0x1, %eax
leaq (%rax,%rsi,2), %rax
cmpq %rax, %rdx
jbe 0x10545
xorq $0x1, %rax
xorq $0x1, %rdx
movq 0x18(%rsp), %rdi
movq %rdx, %rsi
movq %rax, %rdx
jmp 0x1054d
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x10eb9
movq 0xa0(%rsp), %rax
movq 0x30(%rsp), %rcx
incq (%rax,%rcx,8)
movl 0x38(%r13), %eax
movl 0xc(%rsp), %r8d
movq 0x38(%rsp), %r9
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
incq %rbp
movl %eax, %ecx
addq $0x4, %rbx
cmpq %rcx, %rbp
jb 0x104e3
movq 0x98(%rsp), %rbx
movq (%rbx), %rcx
movq 0x18(%rsp), %rbp
incq %r14
cmpq %rcx, %r14
jb 0x1049a
cmpq $0x2, 0x30(%rsp)
jne 0x10619
xorl %ebx, %ebx
xorl %r13d, %r13d
movq 0x10(%rbp), %rax
testq %rax, %rax
je 0x105c8
movb (%rbp), %cl
movl $0x1, %edx
shlq %cl, %rdx
jmp 0x105ca
xorl %edx, %edx
cmpq %rdx, %r13
jae 0x10619
movq 0x8(%rbp), %rcx
movq %r13, %rdx
shrq $0x5, %rdx
movl (%rcx,%rdx,4), %ecx
btl %r13d, %ecx
jae 0x10610
movq (%rax,%rbx), %r14
movq 0x8(%rax,%rbx), %rsi
shrq %rsi
movq %r12, %rdi
callq 0x113c6
shrq %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x113c6
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movq 0x38(%rsp), %r9
incq %r13
addq $0x18, %rbx
jmp 0x105b2
xorl %r13d, %r13d
xorl %r14d, %r14d
movq 0x10(%rbp), %rax
testq %rax, %rax
je 0x10635
movb (%rbp), %cl
movl $0x1, %edx
shlq %cl, %rdx
jmp 0x10637
xorl %edx, %edx
cmpq %rdx, %r13
jae 0x10990
movq 0x8(%rbp), %rcx
movq %r13, %rdx
shrq $0x5, %rdx
movl (%rcx,%rdx,4), %ecx
btl %r13d, %ecx
jae 0x1091d
leaq (,%r13,2), %rcx
addq %r13, %rcx
movq (%rax,%rcx,8), %rsi
movq 0x8(%rax,%rcx,8), %rdi
movl 0x10(%rax,%rcx,8), %ebp
shrq %rdi
shrq %rsi
movq 0x10(%r12), %r8
movsd 0xf1c5(%rip), %xmm1     # 0x1f848
movapd %xmm1, %xmm0
testq %r8, %r8
je 0x10859
movl (%r12), %eax
movl $0x1, %edx
movl %eax, %ecx
shll %cl, %edx
movq %rdx, 0x20(%rsp)
leal -0x1(%rdx), %r10d
movq %rdi, %rcx
notq %rcx
movq %rdi, %rdx
shlq $0x15, %rdx
addq %rcx, %rdx
movq %rdx, %rcx
shrq $0x18, %rcx
xorq %rdx, %rcx
imulq $0x109, %rcx, %rcx      # imm = 0x109
movq %rcx, %rdx
shrq $0xe, %rdx
xorq %rcx, %rdx
leaq (%rdx,%rdx,4), %rcx
leaq (%rdx,%rcx,4), %rcx
movq %rcx, %rdx
shrq $0x1c, %rdx
xorl %ecx, %edx
movq %r12, %r9
imull $0x1e3779b9, %edx, %r12d # imm = 0x1E3779B9
movl %eax, %ecx
negl %ecx
shrl %cl, %r12d
movl $0x20, %edx
subl %eax, %edx
movq 0x8(%r9), %r11
movl %r12d, %ebx
movl %ebx, %ecx
shrl $0x5, %ecx
movl (%r11,%rcx,4), %ecx
btl %ebx, %ecx
jae 0x10725
movl %ebx, %ecx
leaq (%rcx,%rcx,2), %rcx
cmpq %rdi, (%r8,%rcx,4)
je 0x1072c
incl %ebx
andl %r10d, %ebx
cmpl %r12d, %ebx
jne 0x10701
movq 0x20(%rsp), %rcx
movl %ecx, %ebx
movl %ebx, %r9d
movl %eax, %ecx
shrl %cl, %r9d
movsd 0xf10c(%rip), %xmm0     # 0x1f848
testl %r9d, %r9d
jne 0x107ae
movl %ebx, %ecx
leaq (%rcx,%rcx,2), %rcx
cmpl $0x2, 0x8(%r8,%rcx,4)
movsd 0xf0f3(%rip), %xmm0     # 0x1f848
jl 0x107ae
movl %r12d, %ebx
movl %ebx, %ecx
shrl $0x5, %ecx
movl (%r11,%rcx,4), %ecx
btl %ebx, %ecx
jae 0x1077e
movl %ebx, %ecx
leaq (%rcx,%rcx,2), %rcx
cmpq %rdi, (%r8,%rcx,4)
je 0x10785
incl %ebx
andl %r10d, %ebx
cmpl %r12d, %ebx
jne 0x1075a
movq 0x20(%rsp), %rcx
movl %ecx, %ebx
movl %ebx, %r9d
movl %eax, %ecx
shrl %cl, %r9d
xorpd %xmm0, %xmm0
testl %r9d, %r9d
jne 0x107ae
movl %ebx, %ecx
leaq (%rcx,%rcx,2), %rcx
xorps %xmm0, %xmm0
cvtsi2sdl 0x8(%r8,%rcx,4), %xmm0
mulsd 0xf83a(%rip), %xmm0     # 0x1ffe8
movq %rsi, %rcx
notq %rcx
movq %rsi, %r9
shlq $0x15, %r9
addq %rcx, %r9
movq %r9, %rcx
shrq $0x18, %rcx
xorq %r9, %rcx
imulq $0x109, %rcx, %rcx      # imm = 0x109
movq %rcx, %r9
shrq $0xe, %r9
xorq %rcx, %r9
leaq (%r9,%r9,4), %rcx
leaq (%r9,%rcx,4), %rcx
movq %rcx, %r9
shrq $0x1c, %r9
xorl %ecx, %r9d
imull $0x1e3779b9, %r9d, %ebx # imm = 0x1E3779B9
movl %edx, %ecx
shrl %cl, %ebx
movl %ebx, %edx
movq 0x78(%rsp), %r12
movl %edx, %ecx
shrl $0x5, %ecx
movl (%r11,%rcx,4), %ecx
btl %edx, %ecx
jae 0x10820
movl %edx, %ecx
leaq (%rcx,%rcx,2), %rcx
cmpq %rsi, (%r8,%rcx,4)
je 0x10827
incl %edx
andl %r10d, %edx
cmpl %ebx, %edx
jne 0x107fd
movq 0x20(%rsp), %rcx
movl %ecx, %edx
movl %edx, %r9d
movl %eax, %ecx
shrl %cl, %r9d
testl %r9d, %r9d
jne 0x10846
movl %edx, %ecx
leaq (%rcx,%rcx,2), %rcx
cmpl $0x2, 0x8(%r8,%rcx,4)
jge 0x10925
movsd 0xeffa(%rip), %xmm1     # 0x1f848
movq 0x38(%rsp), %r9
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
shlq $0x5, %rdi
movl 0x10(%r9,%rdi), %eax
andl %r10d, %eax
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
divsd %xmm0, %xmm2
shlq $0x5, %rsi
movl 0x10(%r9,%rsi), %eax
andl %r10d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd %xmm1, %xmm0
minsd %xmm0, %xmm2
cvttsd2si %xmm2, %rbx
cmpl %ebx, %ebp
cmovael %ebx, %ebp
movq 0xb0(%rsp), %rax
cmpq %rax, %r14
jne 0x108dd
leaq (%rax,%rax), %r12
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %r12
movq %r12, %rsi
shlq $0x4, %rsi
movq 0x10(%rsp), %rdi
callq 0x2350
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movq 0x38(%rsp), %r9
movq %r12, 0xb0(%rsp)
movq 0x78(%rsp), %r12
jmp 0x108e2
movq 0x10(%rsp), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rbp, %xmm0
movl %ebx, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
divsd %xmm1, %xmm0
leaq 0x1(%r14), %rcx
shlq $0x4, %r14
movl %ebx, (%rax,%r14)
movl %ebp, 0x4(%rax,%r14)
movq %rax, 0x10(%rsp)
movsd %xmm0, 0x8(%rax,%r14)
movq %rcx, %r14
movq 0x18(%rsp), %rbp
incq %r13
jmp 0x1061f
movl %ebx, %ecx
movl %ecx, %edx
shrl $0x5, %edx
movl (%r11,%rdx,4), %edx
btl %ecx, %edx
jae 0x1094a
movl %ecx, %edx
leaq (%rdx,%rdx,2), %rdx
cmpq %rsi, (%r8,%rdx,4)
je 0x10951
incl %ecx
andl %r10d, %ecx
cmpl %ebx, %ecx
jne 0x10927
movq 0x20(%rsp), %r11
jmp 0x10954
movl %ecx, %r11d
movl %r11d, %edx
movl %eax, %ecx
shrl %cl, %edx
xorpd %xmm1, %xmm1
testl %edx, %edx
movq 0x38(%rsp), %r9
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
jne 0x10859
movl %r11d, %eax
leaq (%rax,%rax,2), %rax
xorps %xmm1, %xmm1
cvtsi2sdl 0x8(%r8,%rax,4), %xmm1
mulsd 0xf65d(%rip), %xmm1     # 0x1ffe8
jmp 0x10859
movq %r14, %xmm0
punpckldq 0xee63(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xee6b(%rip), %xmm0     # 0x1f810
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, 0x20(%rsp)
movapd %xmm1, %xmm0
mulsd 0xf60d(%rip), %xmm0     # 0x1ffd0
callq 0x2400
cvttsd2si %xmm0, %r13
movapd 0x20(%rsp), %xmm0
mulsd 0xf5fd(%rip), %xmm0     # 0x1ffd8
callq 0x24e0
cvttsd2si %xmm0, %rbx
movl %ebx, %eax
movq %rax, 0x20(%rsp)
movl $0x10, %edx
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
leaq 0xd2d(%rip), %rcx       # 0x11730
callq 0x20d0
cmpl %ebx, %r13d
jae 0x10a59
movl %r13d, %r13d
movq %r13, %rax
shlq $0x4, %rax
addq %rbp, %rax
addq $0x8, %rax
movq 0x18(%rsp), %rbp
movsd 0x90(%rsp), %xmm0
xorpd %xmm4, %xmm4
movapd 0xf568(%rip), %xmm5     # 0x1ffa0
movq 0x30(%rsp), %rsi
movq 0x20(%rsp), %rbx
ucomisd (%rax), %xmm0
jbe 0x10a74
incq %r13
addq $0x10, %rax
cmpq %r13, %rbx
jne 0x10a42
movl %ebx, %r13d
jmp 0x10a74
movq 0x18(%rsp), %rbp
xorpd %xmm4, %xmm4
movapd 0xf536(%rip), %xmm5     # 0x1ffa0
movq 0x30(%rsp), %rsi
movq 0x20(%rsp), %rbx
movl %ebx, %r14d
subl %r13d, %r14d
cmpl 0xac(%rsp), %r14d
jb 0x10ca4
cmpl $0x2, 0x110(%rsp)
jl 0x10a9b
cmpl %ebx, %r13d
jb 0x10c74
cmpl %r13d, %ebx
jbe 0x10b7c
movl %r13d, %ecx
movq %rbx, %rax
subq %rcx, %rax
shlq $0x4, %rcx
movq 0x10(%rsp), %rdx
addq %rcx, %rdx
xorpd %xmm1, %xmm1
xorpd %xmm0, %xmm0
movq %rax, %rdi
movsd (%rdx), %xmm2
unpcklps %xmm4, %xmm2            # xmm2 = xmm2[0],xmm4[0],xmm2[1],xmm4[1]
orpd %xmm5, %xmm2
subpd %xmm5, %xmm2
movapd %xmm2, %xmm3
unpcklpd %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0]
mulpd %xmm2, %xmm3
addpd %xmm3, %xmm1
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
addsd %xmm2, %xmm0
addq $0x10, %rdx
decq %rdi
jne 0x10ac4
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
divsd %xmm1, %xmm2
movq 0x58(%rsp), %rdx
movsd %xmm2, (%rdx,%rsi,8)
xorpd %xmm5, %xmm5
cmpl %r13d, %ebx
jbe 0x10b97
movl %r14d, %edx
xorps %xmm3, %xmm3
cvtsi2sd %rdx, %xmm3
divsd %xmm3, %xmm0
xorpd 0xf482(%rip), %xmm2     # 0x1ffb0
movq 0x10(%rsp), %rdx
addq %rdx, %rcx
addq $0x4, %rcx
movq 0x48(%rsp), %rbx
movq 0x70(%rsp), %r13
movl -0x4(%rcx), %edx
movl (%rcx), %edi
xorps %xmm3, %xmm3
cvtsi2sd %rdi, %xmm3
xorps %xmm4, %xmm4
cvtsi2sd %rdx, %xmm4
mulsd %xmm2, %xmm4
addsd %xmm3, %xmm4
subsd %xmm0, %xmm3
unpcklpd %xmm3, %xmm4            # xmm4 = xmm4[0],xmm3[0]
mulpd %xmm4, %xmm4
addpd %xmm4, %xmm5
addq $0x10, %rcx
decq %rax
jne 0x10b44
jmp 0x10ba1
movq 0x58(%rsp), %rax
movabsq $0x7ff8000000000000, %rcx # imm = 0x7FF8000000000000
movq %rcx, (%rax,%rsi,8)
xorpd %xmm5, %xmm5
xorpd %xmm1, %xmm1
movq 0x48(%rsp), %rbx
movq 0x70(%rsp), %r13
movapd %xmm5, %xmm0
leal -0x1(%r14), %eax
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
divsd %xmm1, %xmm0
divsd %xmm2, %xmm0
ucomisd 0xf42f(%rip), %xmm0     # 0x1fff0
jb 0x10bc9
sqrtsd %xmm0, %xmm0
jmp 0x10bdf
movapd %xmm5, 0x20(%rsp)
callq 0x2480
movapd 0x20(%rsp), %xmm5
movq 0x30(%rsp), %rsi
movl 0xc(%rsp), %r8d
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movq 0x68(%rsp), %rax
movsd %xmm0, (%rax,%rsi,8)
movapd %xmm5, %xmm0
unpckhpd %xmm5, %xmm0            # xmm0 = xmm0[1],xmm5[1]
divsd %xmm0, %xmm5
movsd 0xec40(%rip), %xmm3     # 0x1f848
movapd %xmm3, %xmm1
subsd %xmm5, %xmm1
cmpeqsd 0xf3d7(%rip), %xmm0     # 0x1fff0
movapd %xmm0, %xmm2
andnpd %xmm1, %xmm2
andpd %xmm3, %xmm0
orpd %xmm2, %xmm0
movq 0x60(%rsp), %rax
movlpd %xmm0, (%rax,%rsi,8)
movq 0x88(%rsp), %rax
movl %r14d, (%rax,%rsi,4)
cmpq 0x80(%rsp), %r13
je 0x10c9a
movl %esi, %eax
movq %rax, 0x40(%rsp)
leaq 0x1(%rsi), %rax
incq %r13
movq 0xc0(%rsp), %rcx
cmpq %rcx, 0x8(%rbx,%rsi,8)
movq 0x98(%rsp), %rbx
jge 0x10434
jmp 0x10ca4
movl %r13d, %edi
movq 0x10(%rsp), %rdx
movq %rbx, %rcx
callq 0x2a57
movq 0x30(%rsp), %rsi
movapd 0xf30f(%rip), %xmm5     # 0x1ffa0
xorpd %xmm4, %xmm4
jmp 0x10a9b
movq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
cmpl $0x0, 0x110(%rsp)
jle 0x10d2c
cmpl $0x3, 0x40(%rsp)
jb 0x10d2c
movl 0x40(%rsp), %r13d
addq $-0x2, %r13
xorl %ebx, %ebx
movq 0x15329(%rip), %rbp     # 0x25ff0
leaq 0xf6a4(%rip), %r14      # 0x20372
leaq 0xf67e(%rip), %r12      # 0x20353
movq (%rbp), %rdi
movq 0x88(%rsp), %rax
movl 0x8(%rax,%rbx,4), %r8d
movq 0xa0(%rsp), %rax
movq 0x10(%rax,%rbx,8), %r9
movq 0x58(%rsp), %rax
movsd 0x10(%rax,%rbx,8), %xmm0
movq 0x68(%rsp), %rax
movsd 0x10(%rax,%rbx,8), %xmm1
movq 0x60(%rsp), %rax
movsd 0x10(%rax,%rbx,8), %xmm2
movq %r14, %rsi
movq %r12, %rdx
movq %rbx, %rcx
movb $0x3, %al
callq 0x2280
incq %rbx
cmpq %rbx, %r13
jne 0x10cd5
movq 0x40(%rsp), %rbp
testl %ebp, %ebp
je 0x10de2
movq 0xb8(%rsp), %r14
testq %r14, %r14
movq 0x18(%rsp), %r13
je 0x10d72
leal -0x1(%rbp), %ebx
leaq (,%rbx,8), %rdi
callq 0x2310
movq %rax, (%r14)
movq 0x58(%rsp), %rsi
addq $0x10, %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0x22b0
movq 0x100(%rsp), %r12
testq %r12, %r12
movq 0x108(%rsp), %r14
je 0x10daf
leal -0x1(%rbp), %ebx
leaq (,%rbx,8), %rdi
callq 0x2310
movq %rax, (%r12)
movq 0x68(%rsp), %rsi
addq $0x10, %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0x22b0
testq %r14, %r14
movq 0x48(%rsp), %r12
je 0x10dee
leal -0x1(%rbp), %ebx
leaq (,%rbx,8), %rdi
callq 0x2310
movq %rax, (%r14)
movq 0x60(%rsp), %rsi
addq $0x10, %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0x22b0
jmp 0x10dee
xorl %ebp, %ebp
movq 0x48(%rsp), %r12
movq 0x18(%rsp), %r13
testq %r13, %r13
je 0x10e1a
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rbx
movq %rbx, %rdi
callq 0x1d6fb
movq 0x8(%r13), %rsi
movq %rbx, %rdi
callq 0x1d6fb
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1d6fb
movq 0x78(%rsp), %r14
testq %r14, %r14
je 0x10e4b
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rbx
movq %rbx, %rdi
callq 0x1d6fb
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0x1d6fb
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1d6fb
movq 0x10(%rsp), %rdi
callq 0x2060
movq %r15, %rdi
callq 0x2060
movq %r12, %rdi
callq 0x2060
movq 0xa0(%rsp), %rdi
callq 0x2060
movq 0x58(%rsp), %rdi
callq 0x2060
movq 0x68(%rsp), %rdi
callq 0x2060
movq 0x60(%rsp), %rdi
callq 0x2060
movq 0x88(%rsp), %rdi
callq 0x2060
xorl %eax, %eax
subl $0x1, %ebp
cmovbl %eax, %ebp
movl %ebp, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq