// File: /workspace/github_c_makefile_star2_O2/c-zhou[P]oatk/syncerr.c
// Function: read_error_correction_analysis_thread
static void read_error_correction_analysis_thread(void *_data, long i, int tid) // kt_for() callback
{
    ec_shared_t *shared = (ec_shared_t *) _data;
    sr_t *sr;
    asmg_t *asmg;
    syncmer_t *scms;
    uint32_t *m_pos, beg_pos, end_pos;
    uint64_t *k_mer, beg_utg, end_utg;
    int32_t j, l, r, n, n_scm, kmer_size, beg, end;
    int updated;
    double max_edist;
    long *stats;
    FILE *fo;
    wf_config_t *conf;
    dfs_info_t *dfs;
    kstring_t *seq, *c_seq;
    kvec64_t *c_kmer;
    kvec32_t *c_mpos;

    asmg = shared->g->utg_asmg;
    scms = shared->g->scm_db->a;
    kmer_size = shared->sr_db->k;
    sr = &shared->sr_db->a[i];
    k_mer = sr->k_mer;
    m_pos = sr->m_pos;
    n_scm = sr->n;
    max_edist = shared->max_edist;
    fo = shared->fo;
    stats = shared->cache[tid].stats;
    conf = shared->cache[tid].conf;
    dfs = shared->cache[tid].dfs;
    seq = shared->cache[tid].seq;
    c_seq = shared->cache[tid].c_seq;
    c_kmer = shared->cache[tid].c_kmer;
    c_mpos = shared->cache[tid].c_mpos;

#ifdef DEBUG_SYNCMER_CORRECTION
    // read information for debugging
    fprintf(stderr, "[DEBUG_SYNCMER_CORRECTION::%s] %lu %s %u %u:", __func__, 
            sr->sid, sr->sname, sr->hoco_l, sr->n);
    for (j = 0; j < n_scm; ++j) {
        if (j > 0) { // print arc coverage
            fprintf(stderr, " [%u]", asmg_arc(asmg, 
                        (k_mer[j-1]&MASK_ONE) | (m_pos[j-1]&1),
                        (k_mer[j]&MASK_ONE) | (m_pos[j]&1))->cov);
        }
        fprintf(stderr, " (%d u%lu%c %u)", j, k_mer[j]>>1, "+-"[m_pos[j]&1], scms[k_mer[j]>>1].cov);
    }
    fputc('\n', stderr);
    // position of syncmers on read
    fprintf(stderr, "[DEBUG_SYNCMER_CORRECTION::%s] %lu %s %u %u:", __func__,
            sr->sid, sr->sname, sr->hoco_l, sr->n);
    for (j = 0; j < n_scm; ++j) fprintf(stderr, " %u", m_pos[j]>>1);
    fputc('\n', stderr);
#endif

    // find error syncmer blocks and do correction
    int err_c1;
    // reset preallocated sequence and path for corrections
    c_seq->l = 0;
    c_kmer->n = 0;
    c_mpos->n = 0;
    updated = 1;
#ifdef DEBUG_SYNCMER_CORRECTION
    int err_block = 0, edist = 0;
#endif
    beg = -1; // beg is a bad syncmer
    while (1) {
        beg_pos = beg < 1? 0 : ((m_pos[beg - 1] >> 1) + kmer_size);
        beg_pos += MIN_ERR_SEQ_LEN;

        // find the rigth boundary - end is a good syncmer
        // the distance between beg and end syncmer is no less than MIN_ERR_SEQ_LEN
        // with this restriction a good syncmer could be included for error correction
        for (end = beg + 1; end < n_scm; ++end)
            if (!scms[k_mer[end]>>1].del && !(k_mer[end]&1) && (m_pos[end] >> 1) >= beg_pos) // good syncmer
                break;

#ifdef DEBUG_SYNCMER_CORRECTION
        fprintf(stderr, "[DEBUG_SYNCMER_CORRECTION::%s] RID %lu ERROR BLOCK %d: %d %d\n", __func__, sr->sid, ++err_block, beg, end);
#endif

        // do error correction for reads with at least one syncmer anchor
        if (beg >= 0 || end < n_scm) {
            // do graph search for error correction
            // with restrictions in distance and source and sink utg nodes
            // here assembly utgs are syncmer singletons, i.e., utg_id is scm_id
            // always guarantee the source utg exist
            if (beg < 0) {
                // no left boundary
                // start from end instead
                // also do reverse complementary
                beg = end; // now beg is a good syncmer
                beg_utg = (k_mer[beg]&MASK_ONE) | (!(m_pos[beg]&1));
                beg_pos = 0;
                end_utg = UINT64_MAX;
                l = m_pos[beg] >> 1;
                r = 1;
            } else {
                // beg >= 0
                // in fact beg > 0
                --beg; // now beg is a good syncmer
                beg_utg = (k_mer[beg]&MASK_ONE) | (m_pos[beg]&1);
                // beg is a correct syncmer
                // start from the next base after this sycnmer
                beg_pos = (m_pos[beg]>>1) + kmer_size;
                if (end >= n_scm) {
                    // no right boundary
                    end_utg = UINT64_MAX;
                    l = (int) sr->hoco_l - beg_pos;
                } else {
                    // bounded by correct syncmer
                    end_utg = (k_mer[end]&MASK_ONE) | (m_pos[end]&1);
                    l = (int) (m_pos[end]>>1) - beg_pos;
                }
                r = 0;
            }
            
            // the error sequence to correct
            assert(l >= 0);
            ks_resize(seq, l);
            get_kmer_dna_seq(sr->hoco_s, beg_pos, l, r, seq->s);
            seq->l = l;
            if (l >= MIN_ERR_SEQ_LEN) {
                // do error correction
                // edit distance configuration
                conf->ts = seq->s;
                conf->tl = seq->l;
                conf->score = 0;
                conf->qs = 0;
                conf->ql = 0;
                conf->is_ext = 1;
                conf->bw = ceil(l * max_edist);
                // TODO is this good?
                if (conf->bw < MIN_ERR_BASE)
                    conf->bw = MIN_ERR_BASE;
                if (!conf->wf_diag)
                    MYCALLOC(conf->wf_diag, 1);
                if (conf->wf_diag->m < l * 4) {
                    conf->wf_diag->m = l * 4;
                    MYREALLOC(conf->wf_diag->a, l * 4);
                }
                conf->wf_diag->n = 1;
                conf->wf_diag->a[0].d =  0;
                conf->wf_diag->a[0].k = -1;

                err_c1 = error_correction_by_graph_path_search(asmg, scms, beg_utg, end_utg, conf, dfs);

#ifdef DEBUG_SYNCMER_CORRECTION
                fprintf(stderr, "[DEBUG_SYNCMER_CORRECTION::%s] RID %lu ERROR BLOCK %d [%s] (PATH = %d): %u %d (u%lu%c u%lu%c) %.*s\n",
                        __func__, sr->sid, err_block, EC_STATUS[err_c1], dfs->n_path, 
                        beg_pos, l, beg_utg>>1, "+-"[beg_utg&1], end_utg>>1, "+-"[end_utg&1], l, seq->s);
#endif
                if (err_c1)
                    assert(beg_utg == dfs->opt_path.a[0] && (end_utg == UINT64_MAX || end_utg == dfs->opt_path.a[dfs->opt_path.n-1]));

                if (end_utg == UINT64_MAX) {
                    ++stats[0];
                    ++stats[1 + err_c1];
                } else {
                    ++stats[5];
                    ++stats[6 + err_c1];
                }
            } else {
                err_c1 = EC_FAILURE;
                ++stats[10];
#ifdef DEBUG_SYNCMER_CORRECTION
                fprintf(stderr, "[DEBUG_SYNCMER_CORRECTION::WARN::%s] RID %lu ERROR BLOCK %d FLANKING SYNCMER OVERLAPPED: %u %d (%lu%c %lu%c)\n",
                        __func__, sr->sid, err_block, beg_pos, l, beg_utg>>1, "+-"[beg_utg&1], end_utg>>1, "+-"[end_utg&1]);
                print_aligned_syncmers_on_seq(sr, kmer_size, 0, UINT32_MAX, stderr);
#endif
            }

            // update c_path
            if (err_c1 == EC_SUCCESS) {
                n = dfs->opt_path.n; // n > 0
                // append the corrected syncmer list
                if (r) {
                    // end_utg == UINT64_MAX
                    for (j = n - 1; j > 0; --j) {
                        kv_push(uint64_t, *c_kmer, (dfs->opt_path.a[j]&MASK_ONE) | 1);
                        kv_push(uint32_t, *c_mpos, UINT32_MAX ^ (dfs->opt_path.a[j]&1));
                    }
                } else {
                    for (j = 1; j < n - 1; ++j) {
                        kv_push(uint64_t, *c_kmer, (dfs->opt_path.a[j]&MASK_ONE) | 1);
                        kv_push(uint32_t, *c_mpos, MASK_ONE | (dfs->opt_path.a[j]&1));
                    }
                    if (end_utg == UINT64_MAX && n > 1) {
                        // j == n-1
                        kv_push(uint64_t, *c_kmer, (dfs->opt_path.a[j]&MASK_ONE) | 1);
                        kv_push(uint32_t, *c_mpos, MASK_ONE | (dfs->opt_path.a[j]&1));
                    }
                }
            } else {
                // append the original sycnmer list
                if (r) {
                    kv_pushn(uint64_t, *c_kmer, k_mer, beg);
                    kv_pushn(uint32_t, *c_mpos, m_pos, beg);
                } else if (beg + 1 < n_scm) {
                    kv_pushn(uint64_t, *c_kmer, &k_mer[beg + 1], end - beg - 1);
                    kv_pushn(uint32_t, *c_mpos, &m_pos[beg + 1], end - beg - 1);
                }
            }
            // update c_seq if necessary
            if (fo) {
                if (err_c1 == EC_SUCCESS || err_c1 == EC_AMBISNQ) {
                    // append the corrected sequence
                    if (r)
                        kputsn_rev(dfs->opt_seq.s, dfs->opt_seq.l, c_seq);
                    else
                        kputsn(dfs->opt_seq.s, dfs->opt_seq.l, c_seq);
                } else {
                    // append the original sequence
                    if (r)
                        kputsn_rev(seq->s, seq->l, c_seq);
                    else
                        kputsn(seq->s, seq->l, c_seq);
                }
            }

#ifdef DEBUG_SYNCMER_CORRECTION
            if (err_c1 == EC_SUCCESS || err_c1 == EC_AMBISNQ)
                edist += dfs->edist;
#endif
        } else {
            // no good syncmers on the read
#ifdef DEBUG_SYNCMER_CORRECTION
            pthread_mutex_lock(&mutex);
            fprintf(stderr, "[DEBUG_SYNCMER_CORRECTION::%s] %s RID %lu no correct syncmers L=%u N=%u:", __func__, sr->sname, sr->sid, sr->hoco_l, sr->n);
            for (j = 0; j < n_scm; ++j) fprintf(stderr, " %u", scms[k_mer[j]>>1].cov);
            fputc('\n', stderr);
            pthread_mutex_unlock(&mutex);
#endif
            updated = 0;
        }

        // end is always a good syncmer
        // find next bad syncmer as beg
        for (beg = end + 1; beg < n_scm; ++beg)
            if (scms[k_mer[beg]>>1].del || (k_mer[end]&1))
                // bad syncmer
                break;
        
        if (beg > n_scm) break;

        // append kmer and mpos between [end, beg-1]
        kv_pushn(uint64_t, *c_kmer, &k_mer[end], beg - end);
        kv_pushn(uint32_t, *c_mpos, &m_pos[end], beg - end);

        // append sequence between [end, beg-1]
        if (fo) {
            beg_pos = m_pos[end] >> 1;
            end_pos = m_pos[beg-1] >> 1;
            l = end_pos + kmer_size - beg_pos;
            ks_resize(c_seq, c_seq->l + l);
            get_kmer_dna_seq(sr->hoco_s, beg_pos, l, 0, &c_seq->s[c_seq->l]);
            c_seq->l += l;
        }
    }
    
    if (updated) {
        // here is to update syncmer seq for the read
        // TODO need to consider data consistency
        size_t s, n_c = c_kmer->n;
        MYREALLOC(sr->k_mer, n_c);
        memcpy(sr->k_mer, c_kmer->a, sizeof(uint64_t) * n_c);
        MYREALLOC(sr->m_pos, n_c);
        memcpy(sr->m_pos, c_mpos->a, sizeof(uint32_t) * n_c);
        MYREALLOC(sr->s_mer, n_c);
        for (s = 0; s < n_c; ++s)
            sr->s_mer[s] = scms[sr->k_mer[s]>>1].s;
        sr->n = n_c;
    }

    if (fo) {
        if (!updated) {
            l = sr->hoco_l;
            ks_resize(c_seq, l);
            get_kmer_dna_seq(sr->hoco_s, 0, l, 0, c_seq->s);
            c_seq->l = l;
        }
        pthread_mutex_lock(&mutex);
        fprintf(fo, ">%s\n%.*s\n", sr->sname, (int) c_seq->l, c_seq->s);
        pthread_mutex_unlock(&mutex);
    }

#ifdef DEBUG_SYNCMER_CORRECTION
    // read information for debugging
    fprintf(stderr, "[DEBUG_SYNCMER_CORRECTION::%s] ERROR CORRECTION RESULT - %lu %s %u %u:", __func__,
            sr->sid, sr->sname, sr->hoco_l, sr->n);
    n_scm = sr->n;
    k_mer = sr->k_mer;
    m_pos = sr->m_pos;
    for (j = 0; j < n_scm; ++j) {
        if (j > 0) { // print arc coverage
            fprintf(stderr, " [%u]", asmg_arc(asmg,
                        (k_mer[j-1]&MASK_ONE) | (m_pos[j-1]&1),
                        (k_mer[j]&MASK_ONE) | (m_pos[j]&1))->cov);
        }
        fprintf(stderr, " (%d u%lu%c %u)", j, k_mer[j]>>1, "+-"[m_pos[j]&1], scms[k_mer[j]>>1].cov);
    }
    fputc('\n', stderr);
    // position of syncmers on read
    fprintf(stderr, "[DEBUG_SYNCMER_CORRECTION::%s] ERROR CORRECTION RESULT - %lu %s %u %u:", __func__,
            sr->sid, sr->sname, sr->hoco_l, sr->n);
    for (j = 0; j < n_scm; ++j) fprintf(stderr, " %u", m_pos[j]>>1);
    fputc('\n', stderr);

    if (fo) {
        int score = 0, t_end = 0, q_end = 0, n_cigar = 0;
        l = sr->hoco_l;
        ks_resize(seq, l);
        get_kmer_dna_seq(sr->hoco_s, 0, l, 0, seq->s);
        seq->l = l;
        uint32_t *cigar = wf_ed(seq->l, seq->s, c_seq->l, c_seq->s, 1, -1, &score, &t_end, &q_end, &n_cigar);
        fprintf(stderr, "[DEBUG_SYNCMER_CORRECTION::%s] ERROR CORRECTION RESULT - ", __func__);
        wf_print_cigar(cigar, n_cigar, stderr);
        fprintf(stderr, "[DEBUG_SYNCMER_CORRECTION::%s] ED_ALIGNMENT: ED=%d BW=%d tL=%d t_EN=%d qL=%d q_EN=%d\n",
                __func__, score, -1, (int) seq->l, t_end, (int) c_seq->l, q_end);
        wf_print_alignment(seq->s, seq->l, c_seq->s, c_seq->l, cigar, n_cigar, 0, stderr);
        free(cigar);
        if (score != edist)
            fprintf(stderr, "[DEBUG_SYNCMER_CORRECTION::WARN::%s] RID %lu INCONSISTENT ERROR CORRECTION RESULT - EC=%d, EDIST=%d\n", 
                    __func__, sr->sid, score, edist);
    }
#endif

    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
movq (%rcx), %r8
movq 0x8(%rcx), %rcx
movq %rcx, 0xd0(%rsp)
movq 0x10(%r8), %rcx
movq %rcx, 0x68(%rsp)
movl 0x18(%rax), %r9d
movq 0x10(%rax), %rax
imulq $0x58, %rsi, %rcx
movq 0x40(%rax,%rcx), %rbp
movq 0x50(%rax,%rcx), %r10
movslq 0x38(%rax,%rcx), %rsi
movq %rsi, 0x48(%rsp)
movsd 0x10(%rdi), %xmm0
movsd %xmm0, 0xc8(%rsp)
movq 0x20(%rdi), %rsi
movq %rsi, 0x60(%rsp)
movq 0x18(%rdi), %rsi
movslq %edx, %rdx
imulq $0x88, %rdx, %rdx
leaq (%rsi,%rdx), %r8
addq $0x30, %r8
movq -0x30(%r8), %rdi
movq %rdi, 0xc0(%rsp)
movq -0x28(%r8), %rdi
movq %rdi, 0x90(%rsp)
movq -0x8(%r8), %rdi
movq %rdi, (%rsp)
movq -0x20(%r8), %rdi
movq -0x18(%r8), %r13
movq %r8, 0x88(%rsp)
movq -0x10(%r8), %r8
movq %rdi, 0x20(%rsp)
andq $0x0, (%rdi)
andq $0x0, (%r13)
movq %r8, 0x18(%rsp)
andq $0x0, (%r8)
addq %rcx, %rax
movq %rax, 0x28(%rsp)
leaq (%rsi,%rdx), %rax
movq %rax, 0xb8(%rsp)
leaq 0x60(%rsi,%rdx), %rax
movq %rax, 0xb0(%rsp)
leaq 0x38(%rsi,%rdx), %rax
movq %rax, 0x80(%rsp)
leaq 0x58(%rsi,%rdx), %rax
movq %rax, 0xa8(%rsp)
movq %r9, 0xa0(%rsp)
leal 0xa(%r9), %eax
movl %eax, 0x7c(%rsp)
movq %r10, 0x30(%rsp)
leaq 0x8(%r10), %rax
movq %rax, 0xe0(%rsp)
leaq 0x4(%rbp), %rax
movq %rax, 0xd8(%rsp)
pushq $-0x1
popq %r15
pushq $0x1
popq %rax
movl %eax, 0x54(%rsp)
movq %r13, 0x70(%rsp)
movq %rbp, 0x10(%rsp)
movl %r15d, %eax
pushq $0xa
popq %rdx
testl %r15d, %r15d
jle 0xff4c
movq 0x10(%rsp), %rcx
movl -0x4(%rcx,%rax,4), %edx
shrl %edx
addl 0x7c(%rsp), %edx
movslq %eax, %rsi
movq %rax, %rcx
shlq $0x20, %rcx
movabsq $0x100000000, %r15      # imm = 0x100000000
addq %r15, %rcx
leaq 0x1(%rsi), %r8
movq 0xe0(%rsp), %rdi
leaq (%rdi,%rsi,8), %r9
movq 0xd8(%rsp), %rdi
leaq (%rdi,%rsi,4), %r10
xorl %edi, %edi
movq 0x68(%rsp), %r12
movq 0x30(%rsp), %rbp
movq 0x48(%rsp), %r14
leaq (%r8,%rdi), %rsi
cmpq %r14, %rsi
jge 0xffca
movq (%r9,%rdi,8), %r11
movq %r11, %rbx
shlq $0x4, %rbx
andq $-0x20, %rbx
cmpl $0x0, 0x10(%r12,%rbx)
js 0xffc2
andl $0x1, %r11d
jne 0xffc2
movl (%r10,%rdi,4), %r11d
shrl %r11d
cmpl %edx, %r11d
jae 0xffe6
incq %rdi
addq %r15, %rcx
jmp 0xff90
leaq (%rax,%rdi), %r15
leaq (%rax,%rdi), %r8
incq %r8
testl %eax, %eax
jns 0xfff9
movl $0x0, 0x54(%rsp)
jmp 0x1079d
leaq (%rax,%rdi), %r15
leaq (%rax,%rdi), %r8
incq %r8
testl %eax, %eax
js 0x1056a
movq 0x10(%rsp), %rdi
movq %r15, 0x40(%rsp)
cmpq %r14, %rsi
jge 0x10026
movslq %r8d, %rcx
movq (%rbp,%rcx,8), %rdx
andq $-0x2, %rdx
movl (%rdi,%rcx,4), %r15d
movl %r15d, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
shrl %r15d
jmp 0x10032
movq 0x28(%rsp), %rcx
movl 0x10(%rcx), %r15d
pushq $-0x1
popq %rcx
cltq
movl -0x4(%rdi,%rax,4), %r12d
movl %r12d, %ebp
shrl %ebp
addl 0xa0(%rsp), %ebp
subl %ebp, %r15d
js 0x10ac0
movq %rcx, 0x98(%rsp)
movq %r8, 0x38(%rsp)
leal -0x1(%rax), %ecx
movq %rcx, 0x58(%rsp)
movq 0x30(%rsp), %rcx
movq -0x8(%rcx,%rax,8), %rax
andq $-0x2, %rax
andl $0x1, %r12d
orq %rax, %r12
xorl %ebx, %ebx
movb $0x1, %al
movl %eax, 0xc(%rsp)
movl %r15d, %r13d
movq 0x90(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x10cb3
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x10(%r14), %r8
movl %ebp, %esi
movl %r15d, %edx
movl %ebx, %ecx
callq 0xc063
movq %r13, (%r14)
cmpl $0xa, %r15d
jb 0x10153
movq 0x10(%r14), %rax
movq 0xc0(%rsp), %rbx
movq %rax, (%rbx)
movl %r15d, 0x10(%rbx)
andl $0x0, 0x30(%rbx)
andq $0x0, 0x8(%rbx)
andl $0x0, 0x14(%rbx)
movl $0x1, 0x28(%rbx)
cvtsi2sd %r15d, %xmm0
mulsd 0xc8(%rsp), %xmm0
callq 0x24e0
cvttsd2si %xmm0, %eax
cmpl $0x7, %eax
pushq $0x6
popq %rcx
cmovll %ecx, %eax
movl %eax, 0x2c(%rbx)
movq 0x18(%rbx), %rax
testq %rax, %rax
movq 0x70(%rsp), %r13
jne 0x10123
pushq $0x1
popq %rdi
pushq $0x18
popq %rsi
callq 0x2250
movq %rax, 0x18(%rbx)
shll $0x2, %r15d
cmpq %r15, 0x8(%rax)
movq 0x98(%rsp), %r14
jae 0x1017d
movq %r15, 0x8(%rax)
movq 0x10(%rax), %rdi
imulq $0xc, %r15, %rsi
callq 0x2350
movq %rax, %rcx
movq 0x18(%rbx), %rax
movq %rcx, 0x10(%rax)
jmp 0x10181
movq 0xb8(%rsp), %rax
incq 0x80(%rax)
xorl %r15d, %r15d
movq 0x68(%rsp), %r12
movq 0x70(%rsp), %r13
movq (%rsp), %r8
movq 0x58(%rsp), %rsi
jmp 0x1030c
movq 0x10(%rax), %rcx
movq (%rsp), %rsi
movq $0x1, (%rax)
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, (%rcx)
movq 0xd0(%rsp), %rdi
movq %r12, %rdx
movq %r14, %rcx
movq %rbx, %r8
movq %rsi, %rbx
movq %rsi, %r9
callq 0xf070
movl %eax, %r15d
testl %eax, %eax
je 0x101ec
movq 0x68(%rbx), %rax
cmpq (%rax), %r12
movq 0x68(%rsp), %r12
movq 0x58(%rsp), %rsi
jne 0x10adf
movq %rbx, %r8
cmpq $-0x1, %r14
je 0x10213
movq 0x58(%r8), %rcx
cmpq -0x8(%rax,%rcx,8), %r14
je 0x101ff
jmp 0x10adf
cmpq $-0x1, %r14
movq 0x68(%rsp), %r12
movq %rbx, %r8
movq 0x58(%rsp), %rsi
je 0x10213
xorl %ebp, %ebp
movq 0xa8(%rsp), %rax
movq 0xb0(%rsp), %rcx
jmp 0x10226
movb $0x1, %bpl
movq 0x88(%rsp), %rax
movq 0x80(%rsp), %rcx
incq (%rax)
movslq %r15d, %rax
incq (%rcx,%rax,8)
cmpl $0x1, %r15d
jne 0x1030c
movq 0x58(%r8), %rbx
cmpb $0x0, 0xc(%rsp)
je 0x105c3
leal -0x1(%rbx), %eax
movslq %eax, %r15
pushq $0x1
popq %r14
cmpq %r15, %r14
jge 0x10681
movq (%r13), %rdx
movq 0x10(%r13), %rax
cmpq 0x8(%r13), %rdx
jne 0x10294
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r13)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2350
movq (%rsp), %r8
movq %rax, 0x10(%r13)
movq (%r13), %rdx
movq 0x68(%r8), %rcx
movq (%rcx,%r14,8), %rsi
orq $0x1, %rsi
leaq 0x1(%rdx), %rdi
movq %rdi, (%r13)
movq %rsi, (%rax,%rdx,8)
movq 0x18(%rsp), %r13
movq (%r13), %rdx
movq 0x10(%r13), %rax
cmpq 0x8(%r13), %rdx
jne 0x102ed
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r13)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2350
movq (%rsp), %r8
movq %rax, 0x10(%r13)
movq 0x68(%r8), %rcx
movq (%r13), %rdx
movl (%rcx,%r14,8), %ecx
orl $-0x2, %ecx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r13)
movl %ecx, (%rax,%rdx,4)
incq %r14
movq 0x70(%rsp), %r13
jmp 0x10253
cmpb $0x0, 0xc(%rsp)
je 0x1044f
leal 0x1(%rsi), %ebp
cmpl 0x48(%rsp), %ebp
jge 0x10560
movq (%r13), %rcx
movq 0x10(%r13), %rax
movq 0x40(%rsp), %rdx
subl %esi, %edx
movslq %edx, %rbx
leaq (%rcx,%rbx), %rdx
cmpq 0x8(%r13), %rdx
jbe 0x10394
decq %rdx
movq %rdx, %rcx
shrq %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x2, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x8, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x10, %rcx
orq %rdx, %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r13)
leaq 0x8(,%rcx,8), %rsi
movq %rax, %rdi
callq 0x2350
movq %rax, 0x10(%r13)
movq (%r13), %rcx
leaq (%rax,%rcx,8), %rdi
movslq %ebp, %r14
movq 0x30(%rsp), %rbp
leaq (,%r14,8), %rsi
addq %rbp, %rsi
leaq (,%rbx,8), %rdx
callq 0x22b0
addq %rbx, (%r13)
movq 0x18(%rsp), %r13
movq (%r13), %rcx
movq 0x10(%r13), %rax
leaq (%rcx,%rbx), %rdx
cmpq 0x8(%r13), %rdx
jbe 0x10427
decq %rdx
movq %rdx, %rcx
shrq %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x2, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x8, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x10, %rcx
orq %rdx, %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r13)
leaq 0x4(,%rcx,4), %rsi
movq %rax, %rdi
callq 0x2350
movq %rax, 0x10(%r13)
movq (%r13), %rcx
movq 0x10(%rsp), %rdx
leaq (%rax,%rcx,4), %rdi
leaq (%rdx,%r14,4), %rsi
leaq (,%rbx,4), %rdx
callq 0x22b0
addq %rbx, (%r13)
movq 0x70(%rsp), %r13
jmp 0x10557
movq (%r13), %rcx
movq 0x10(%r13), %rax
movslq %esi, %rbx
leaq (%rcx,%rbx), %rdx
cmpq 0x8(%r13), %rdx
movq 0x30(%rsp), %rbp
jbe 0x104bd
decq %rdx
movq %rdx, %rcx
shrq %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x2, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x8, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x10, %rcx
orq %rdx, %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r13)
leaq 0x8(,%rcx,8), %rsi
movq %rax, %rdi
callq 0x2350
movq %rax, 0x10(%r13)
movq (%r13), %rcx
leaq (%rax,%rcx,8), %rdi
leaq (,%rbx,8), %rdx
movq %rbp, %rsi
callq 0x22b0
addq %rbx, (%r13)
movq 0x18(%rsp), %r14
movq (%r14), %rcx
movq 0x10(%r14), %rax
leaq (%rcx,%rbx), %rdx
cmpq 0x8(%r14), %rdx
jbe 0x1053e
decq %rdx
movq %rdx, %rcx
shrq %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x2, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x8, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x10, %rcx
orq %rdx, %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r14)
leaq 0x4(,%rcx,4), %rsi
movq %rax, %rdi
callq 0x2350
movq %rax, 0x10(%r14)
movq (%r14), %rcx
movq 0x10(%rsp), %rsi
leaq (%rax,%rcx,4), %rdi
leaq (,%rbx,4), %rdx
callq 0x22b0
addq %rbx, (%r14)
movq (%rsp), %r8
jmp 0x10741
movq 0x30(%rsp), %rbp
jmp 0x10741
movq %r15, 0x40(%rsp)
movq %rcx, %rax
sarq $0x1d, %rax
movq (%rbp,%rax), %rax
andq $-0x2, %rax
sarq $0x1e, %rcx
movq 0x10(%rsp), %rdx
movl (%rdx,%rcx), %r15d
movl %r15d, %r12d
notl %r12d
andl $0x1, %r12d
orq %rax, %r12
shrl %r15d
xorl %ebp, %ebp
pushq $-0x1
popq %rax
movq %rax, 0x98(%rsp)
pushq $0x1
popq %rbx
movq %r8, 0x38(%rsp)
movq %r8, 0x58(%rsp)
movl $0x0, 0xc(%rsp)
jmp 0x10080
leal -0x1(%rbx), %r14d
movq 0x18(%rsp), %r15
movq 0x30(%rsp), %rbp
cmpl $0x2, %ebx
jl 0x1073d
movq (%r13), %rcx
movq 0x10(%r13), %rax
cmpq 0x8(%r13), %rcx
jne 0x10612
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r13)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2350
movq (%rsp), %r8
movq %rax, 0x10(%r13)
movq (%r13), %rcx
movq 0x68(%r8), %rdx
movq (%rdx,%r14,8), %rsi
orq $0x1, %rsi
leaq 0x1(%rcx), %rdi
movq %rdi, (%r13)
movq %rsi, (%rax,%rcx,8)
movq (%r15), %rcx
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rcx
jne 0x10664
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r15)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2350
movq (%rsp), %r8
movq %rax, 0x10(%r15)
movq 0x68(%r8), %rdx
movq (%r15), %rcx
movl (%rdx,%r14,8), %edx
notl %edx
orl $-0x2, %edx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r15)
movl %edx, (%rax,%rcx,4)
decl %ebx
decq %r14
jmp 0x105d1
cmpl $0x2, %ebx
setge %al
andb %al, %bpl
pushq $0x1
popq %r15
cmpb $0x1, %bpl
movq 0x30(%rsp), %rbp
jne 0x10741
movq (%r13), %rdx
movq 0x10(%r13), %rax
cmpq 0x8(%r13), %rdx
jne 0x106d5
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r13)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2350
movq (%rsp), %r8
movq %rax, 0x10(%r13)
movq (%r13), %rdx
movq 0x18(%rsp), %rbx
movq 0x68(%r8), %rcx
movq (%rcx,%r14,8), %rsi
orq $0x1, %rsi
leaq 0x1(%rdx), %rdi
movq %rdi, (%r13)
movq %rsi, (%rax,%rdx,8)
movq (%rbx), %rdx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rdx
jne 0x1072c
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2350
movq (%rsp), %r8
movq %rax, 0x10(%rbx)
movq 0x68(%r8), %rcx
movq (%rbx), %rdx
movl (%rcx,%r14,8), %ecx
orl $-0x2, %ecx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rbx)
movl %ecx, (%rax,%rdx,4)
pushq $0x1
popq %r15
cmpq $0x0, 0x60(%rsp)
je 0x1075c
decl %r15d
cmpl $0x1, %r15d
ja 0x10768
movq 0x38(%r8), %rdi
movl 0x28(%r8), %esi
jmp 0x10776
movq 0x38(%rsp), %r8
movq 0x40(%rsp), %r15
jmp 0x1079d
movq 0x90(%rsp), %rax
movq 0x10(%rax), %rdi
movl (%rax), %esi
cmpb $0x0, 0xc(%rsp)
movq 0x40(%rsp), %r15
je 0x1078e
movq 0x20(%rsp), %rdx
callq 0x10bb0
jmp 0x10798
movq 0x20(%rsp), %rdx
callq 0x10afe
movq 0x38(%rsp), %r8
addl $0x2, %r15d
movslq %r8d, %rbx
leaq (,%rbx,8), %r14
addq %rbp, %r14
movslq %r15d, %r15
movq 0x48(%rsp), %rcx
cmpl %r15d, %ecx
movl %r15d, %eax
cmovgl %ecx, %eax
cmpq 0x48(%rsp), %r15
jge 0x107e7
movq (%rbp,%r15,8), %rcx
shlq $0x4, %rcx
andq $-0x20, %rcx
cmpl $0x0, 0x10(%r12,%rcx)
js 0x107ea
testb $0x1, (%r14)
jne 0x107ea
incq %r15
jmp 0x107c0
movl %eax, %r15d
cmpl 0x48(%rsp), %r15d
jg 0x1096f
movq (%r13), %rcx
movq 0x10(%r13), %rax
movl %r15d, %edx
subl %r8d, %edx
movslq %edx, %r12
leaq (%rcx,%r12), %rdx
cmpq 0x8(%r13), %rdx
jbe 0x10864
decq %rdx
movq %rdx, %rcx
shrq %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x2, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x8, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x10, %rcx
orq %rdx, %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r13)
leaq 0x8(,%rcx,8), %rsi
movq %rax, %rdi
callq 0x2350
movq %rax, 0x10(%r13)
movq (%r13), %rcx
leaq (%rax,%rcx,8), %rdi
leaq (,%r12,8), %rdx
movq %r14, %rsi
callq 0x22b0
addq %r12, (%r13)
movq 0x18(%rsp), %r14
movq (%r14), %rcx
movq 0x10(%r14), %rax
leaq (%rcx,%r12), %rdx
cmpq 0x8(%r14), %rdx
jbe 0x108e5
decq %rdx
movq %rdx, %rcx
shrq %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x2, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x8, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x10, %rcx
orq %rdx, %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r14)
leaq 0x4(,%rcx,4), %rsi
movq %rax, %rdi
callq 0x2350
movq %rax, 0x10(%r14)
movq (%r14), %rcx
movq 0x10(%rsp), %rbp
leaq (%rax,%rcx,4), %rdi
leaq (,%rbx,4), %rbx
addq %rbp, %rbx
leaq (,%r12,4), %rdx
movq %rbx, %rsi
callq 0x22b0
addq %r12, (%r14)
cmpq $0x0, 0x60(%rsp)
je 0xff32
movl (%rbx), %ebx
shrl %ebx
movslq %r15d, %rax
movl -0x4(%rbp,%rax,4), %eax
shrl %eax
movq 0xa0(%rsp), %rcx
subl %ebx, %ecx
addl %eax, %ecx
movslq %ecx, %r14
movq 0x20(%rsp), %r12
movq (%r12), %rsi
addq %r14, %rsi
movq %r12, %rdi
callq 0x10cb3
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x10(%r12), %r8
addq (%r12), %r8
movl %ebx, %esi
movl %r14d, %edx
xorl %ecx, %ecx
callq 0xc063
addq %r14, (%r12)
jmp 0xff32
cmpl $0x0, 0x54(%rsp)
je 0x10a21
movq (%r13), %r15
movq 0x28(%rsp), %rbp
movq 0x50(%rbp), %rdi
leaq (,%r15,8), %rbx
movq %rbx, %rsi
callq 0x2350
movq %rax, 0x50(%rbp)
movq 0x10(%r13), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0x22b0
movq 0x40(%rbp), %rdi
leaq (,%r15,4), %r14
movq %r14, %rsi
callq 0x2350
movq %rax, 0x40(%rbp)
movq 0x18(%rsp), %rcx
movq 0x10(%rcx), %rsi
movq %rax, %rdi
movq %r14, %rdx
movq %rbp, %r14
callq 0x22b0
movq 0x48(%rbp), %rdi
movq %rbx, %rsi
callq 0x2350
movq %rax, 0x48(%rbp)
xorl %ecx, %ecx
cmpq %rcx, %r15
je 0x10a0e
movq 0x50(%r14), %rdx
movq (%rdx,%rcx,8), %rdx
shlq $0x4, %rdx
andq $-0x20, %rdx
movq 0x8(%r12,%rdx), %rdx
movq %rdx, (%rax,%rcx,8)
incq %rcx
jmp 0x109eb
movl %r15d, 0x38(%r14)
movq 0x60(%rsp), %r15
testq %r15, %r15
jne 0x10a66
jmp 0x10aae
movq 0x60(%rsp), %r15
testq %r15, %r15
movq 0x28(%rsp), %rax
je 0x10aae
movl 0x10(%rax), %eax
movslq %eax, %rbx
movq 0x20(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x10cb3
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x10(%r14), %r8
xorl %esi, %esi
movl %ebx, %edx
xorl %ecx, %ecx
callq 0xc063
movq %rbx, (%r14)
movq 0x28(%rsp), %r14
leaq 0x1084b(%rip), %rbx     # 0x212b8
movq %rbx, %rdi
callq 0x2500
movq 0x8(%r14), %rdx
movq 0x20(%rsp), %rax
movl (%rax), %ecx
movq 0x10(%rax), %r8
leaq 0x9f80(%rip), %rsi      # 0x1aa0b
movq %r15, %rdi
xorl %eax, %eax
callq 0x2280
movq %rbx, %rdi
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22f0
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x9e8b(%rip), %rdi      # 0x1a952
leaq 0x9e8b(%rip), %rsi      # 0x1a959
leaq 0x9e8e(%rip), %rcx      # 0x1a963
movl $0x1ca, %edx            # imm = 0x1CA
callq 0x21d0
leaq 0x9ebb(%rip), %rdi      # 0x1a9a1
leaq 0x9e6c(%rip), %rsi      # 0x1a959
leaq 0x9e6f(%rip), %rcx      # 0x1a963
movl $0x1ed, %edx            # imm = 0x1ED
callq 0x21d0