// File: /workspace/github_c_makefile_star2_O2/c-zhou[P]yahs/link.c
// Function: dump_links_from_bam_file
void dump_links_from_bam_file(const char *f, const char *fai, uint32_t ml, uint8_t mq, double q_drop, const char *out)
{
    bamFile fp;
    FILE *fo;
    bam_header_t *h;
    bam1_t *b;
    char *cname0, *cname1, *rname0, *rname1;
    int32_t s0, s1, e0, e1, first;
    uint32_t i0, i1, p0, p1;
    uint8_t q, q0, q1;
    int8_t buff;
    uint64_t rec_c, pair_c, inter_c, intra_c, sd_l, n, m, max_m;
    enum bam_sort_order so;
    cov_t *cov;
    
    khash_t(str) *hmseq; // for absent sequences
    khint_t k;
    int absent;
    hmseq = kh_init(str);

    sdict_t *dict = make_sdict_from_index(fai, ml);
    
    fp = bam_open(f, "r");
    if (fp == NULL) {
        fprintf(stderr, "[E::%s] cannot open file %s for reading\n", __func__, f);
        exit(EXIT_FAILURE);
    }
    
    fo = fopen(out, "w");
    if (fo == NULL) {
        fprintf(stderr, "[E::%s] cannot open file %s for writing\n", __func__, out);
        exit(EXIT_FAILURE);
    }
    write_bin_header(fo);
    sd_l = write_sequence_dictionary(fo, dict);

    h = bam_header_read(fp);
    b = bam_init1();
    so = bam_hrecs_sort_order(h);
    cname0 = cname1 = rname0 = rname1 = 0;
    s0 = s1 = e0 = e1 = 0;
    i0 = i1 = p0 = p1 = 0;
    rec_c = pair_c = inter_c = intra_c = 0;
    buff = 0;
    cov = cov_init(dict->n);
    n = 0;
    max_m = 0x7FFFFFFULL; // 128MB - ~1GB mem for covs

    fwrite(&pair_c, sizeof(uint64_t), 1, fo);

    if (so == ORDER_NAME) {
        // sorted by read names
        while (bam_read1(fp, b) >= 0 ) {

            if (buff == 0) {
                q0 = 255;
                rname0 = parse_bam_rec(b, h, &s0, &e0, &q0, &cname0);
                if (!rname0)
                    continue;
                ++buff;
            } else if (buff == 1) {
                q1 = 255;
                rname1 = parse_bam_rec(b, h, &s1, &e1, &q1, &cname1);
                if (!rname1)
                    continue;
                if (strcmp(rname0, rname1) == 0) {
                    buff = 0;

                    i0 = sd_get(dict, cname0);
                    i1 = sd_get(dict, cname1);
                    q = MIN(q0, q1);

                    if (i0 == UINT32_MAX) {
                        k = kh_put(str, hmseq, cname0, &absent);
                        if (absent) {
                            kh_key(hmseq, k) = strdup(cname0);
                            fprintf(stderr, "[W::%s] sequence \"%s\" not found \n", __func__, cname0);
                        }
                    } else if (i1 == UINT32_MAX) {
                        k = kh_put(str, hmseq, cname1, &absent);
                        if (absent) {
                            kh_key(hmseq, k) = strdup(cname1);
                            fprintf(stderr, "[W::%s] sequence \"%s\" not found \n", __func__, cname1);
                        }
                    } else if (q >= mq) {
                        // update read coverage
                        // fix bad alignments
                        s0 = MIN_MAX(s0, 0, dict->s[i0].len - 1);
                        e0 = MIN_MAX(e0, 0, dict->s[i0].len - 1);
                        s1 = MIN_MAX(s1, 0, dict->s[i1].len - 1);
                        e1 = MIN_MAX(e1, 0, dict->s[i1].len - 1);
                        kv_push(uint64_t, cov->p[i0], (uint64_t) s0 << 32 | (uint32_t) 1);
                        kv_push(uint64_t, cov->p[i0], (uint64_t) e0 << 32 | (uint32_t) -1);
                        kv_push(uint64_t, cov->p[i1], (uint64_t) s1 << 32 | (uint32_t) 1);
                        kv_push(uint64_t, cov->p[i1], (uint64_t) e1 << 32 | (uint32_t) -1);
                        n += 4;
                        if (n > max_m) {
                            m = pos_compression(cov); // m is the position size after compression
                            fprintf(stderr, "[I::%s] position compression n = %lu, m = %lu, max_m = %lu\n", __func__, n, m, max_m);
                            if (m > n>>1) {
                                max_m <<= 1; // increase m limit if compression ratio smaller than 0.5
                                fprintf(stderr, "[I::%s] position memory buffer expanded max_m = %lu\n", __func__, max_m);
                            }
                            n = m;
                        }

                        // from zero-based to one-based
                        p0 = s0 / 2 + e0 / 2 + (s0 & 1 && e0 & 1);
                        p1 = s1 / 2 + e1 / 2 + (s1 & 1 && e1 & 1);
                        if (i0 > i1) {
                            SWAP(uint32_t, i0, i1);
                            SWAP(uint32_t, p0, p1);
                        }
                        fwrite(&i0, sizeof(uint32_t), 1, fo);
                        fwrite(&p0, sizeof(uint32_t), 1, fo);
                        fwrite(&i1, sizeof(uint32_t), 1, fo);
                        fwrite(&p1, sizeof(uint32_t), 1, fo);
                        fwrite(&q, sizeof(uint8_t), 1, fo);

                        if (i0 == i1)
                            ++intra_c;
                        else
                            ++inter_c;

                        ++pair_c;
                    }
                    
                    free(rname0);
                    free(rname1);
                    rname0 = 0;
                    rname1 = 0;
                } else {
                    buff = 1;

                    cname0 = cname1;
                    s0 = s1;
                    e0 = e1;
                    q0 = q1;
                    free(rname0);
                    rname0 = rname1;
                    rname1 = 0;
                }
            }

            if (++rec_c % 1000000 == 0)
                fprintf(stderr, "[I::%s] %lu million records processed, %lu read pairs \n", __func__, rec_c / 1000000, pair_c);
        }
    } else {
        // sorted by coordinates or others
        if (mq > 0)
            fprintf(stderr, "[W::%s] BAM file is not sorted by read name. Filtering by mapping quality %hhu suppressed \n", __func__, mq);
        q = 255;

        while (bam_read1(fp, b) >= 0) {

            first = parse_bam_rec1(b, h, &cname0, &s0, &e0, &cname1, &s1);

            if (first < 0) continue; // read not paired or not primary

            i0 = sd_get(dict, cname0);
            if (i0 != UINT32_MAX) {
                // update read coverage
                // fix bad alignments
                s0 = MIN_MAX(s0, 0, dict->s[i0].len - 1);
                e0 = MIN_MAX(e0, 0, dict->s[i0].len - 1);
                kv_push(uint64_t, cov->p[i0], (uint64_t) s0 << 32 | (uint32_t) 1);
                kv_push(uint64_t, cov->p[i0], (uint64_t) e0 << 32 | (uint32_t) -1);
                n += 2;
                if (n > max_m) {
                    m = pos_compression(cov); // m is the position size after compression
                    fprintf(stderr, "[I::%s] position compression n = %lu, m = %lu, max_m = %lu\n", __func__, n, m, max_m);
                    if (m > n>>1) {
                        max_m <<= 1; // increase m limit if compression ratio smaller than 0.5
                        fprintf(stderr, "[I::%s] position memory buffer expanded max_m = %lu\n", __func__, max_m);
                    }
                    n = m;
                }
            }

            if (first == 0) { // second read only for each read pair
                // i0 = sd_get(dict, cname0);
                i1 = sd_get(dict, cname1);

                if (i0 == UINT32_MAX) {
                    k = kh_put(str, hmseq, cname0, &absent);
                    if (absent) {
                        kh_key(hmseq, k) = strdup(cname0);
                        fprintf(stderr, "[W::%s] sequence \"%s\" not found \n", __func__, cname0);
                    }
                } else if (i1 == UINT32_MAX) {
                    k = kh_put(str, hmseq, cname1, &absent);
                    if (absent) {
                        kh_key(hmseq, k) = strdup(cname1);
                        fprintf(stderr, "[W::%s] sequence \"%s\" not found \n", __func__, cname1);
                    }
                } else {
                    // fix bad alignments
                    s1 = MIN_MAX(s1, 0, dict->s[i1].len - 1);
                    if (i0 > i1) {
                        SWAP(uint32_t, i0, i1);
                        SWAP(uint32_t, s0, s1);
                    }
                    fwrite(&i0, sizeof(uint32_t), 1, fo);
                    fwrite(&s0, sizeof(uint32_t), 1, fo);
                    fwrite(&i1, sizeof(uint32_t), 1, fo);
                    fwrite(&s1, sizeof(uint32_t), 1, fo);
                    fwrite(&q, sizeof(uint8_t), 1, fo);

                    if (i0 == i1)
                        ++intra_c;
                    else
                        ++inter_c;

                    ++pair_c;
                }
            }

            if (++rec_c % 1000000 == 0)
                fprintf(stderr, "[I::%s] %lu million records processed, %lu read pairs \n", __func__, rec_c / 1000000, pair_c);
        }
    }

    m = pos_compression(cov);
    fprintf(stderr, "[I::%s] position compression n = %lu, m = %lu, max_m = %lu\n", __func__, n, m, max_m);

    for (k = 0; k < kh_end(hmseq); ++k)
        if (kh_exist(hmseq, k))
            free((char *) kh_key(hmseq, k));
    kh_destroy(str, hmseq);

    if (rname0)
        free(rname0);
    if (rname1)
        free(rname1);
    bam_destroy1(b);
    bam_header_destroy(h);
    bam_close(fp);
    // write pair number
    fseek(fo, sizeof(uint64_t) + sd_l, SEEK_SET);
    fwrite(&pair_c, sizeof(uint64_t), 1, fo);
    fseek(fo, pair_c * 17, SEEK_CUR);

    fprintf(stderr, "[I::%s] dumped %lu read pairs from %lu records: %lu intra links + %lu inter links \n", __func__, pair_c, rec_c, intra_c, inter_c);

    // cov_t *cov = bam_cstats(f, dict, 0);
    cov_norm_t *cov_norm = calc_cov_norms(cov, dict, q_drop);
    fwrite(&cov_norm->n, sizeof(uint64_t), 1, fo);
    fwrite(cov_norm->norm[0], sizeof(double), cov_norm->n, fo);
    cov_destroy(cov);
    cov_norm_destroy(cov_norm);

    sd_destroy(dict);
    fclose(fo);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %r8, %rbx
movsd %xmm0, 0xf0(%rsp)
movl %ecx, 0x98(%rsp)
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %r14
callq 0xcb76
movq %rax, %r13
movq %r15, %rdi
movl %ebp, %esi
callq 0xeb03
movq %rax, 0x60(%rsp)
leaq 0x1366b(%rip), %rsi     # 0x1f311
movq %r14, %rdi
callq 0x339b
testq %rax, %rax
je 0xcb2f
movq %rax, %r12
leaq 0x1234f(%rip), %rsi     # 0x1e010
movq %rbx, %rdi
callq 0x23e0
testq %rax, %rax
je 0xcb4c
movq %rax, %rbp
movq %rax, %rdi
callq 0x2952
movq %rbp, %rdi
movq 0x60(%rsp), %r14
movq %r14, %rsi
callq 0x1185a
movq %rax, 0xe8(%rsp)
movq %r12, %rdi
callq 0x2d85
movq %rax, %rbx
pushq $0x1
popq %rdi
pushq $0x38
popq %rsi
callq 0x2290
movq %rax, %r15
movq %rbx, 0x38(%rsp)
movq %rbx, %rdi
callq 0x3232
andq $0x0, 0xc8(%rsp)
andq $0x0, 0xd0(%rsp)
andl $0x0, 0x58(%rsp)
andl $0x0, 0x5c(%rsp)
andl $0x0, 0x1c(%rsp)
andl $0x0, 0xc(%rsp)
movl %eax, %ebx
andl $0x0, 0x80(%rsp)
andl $0x0, 0x84(%rsp)
leaq 0xa0(%rsp), %rax
andq $0x0, (%rax)
movl (%r14), %edi
callq 0x121fc
movq %rax, 0x30(%rsp)
pushq $0x8
popq %rsi
leaq 0xa0(%rsp), %rdi
pushq $0x1
popq %rdx
movq %rbp, 0xb8(%rsp)
movq %rbp, %rcx
callq 0x24d0
cmpl $0x1, %ebx
jne 0xc465
movl $0x7ffffff, %eax        # imm = 0x7FFFFFF
movq %rax, 0x50(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x88(%rsp)
movq $0x0, 0x40(%rsp)
movq $0x0, 0xb0(%rsp)
movq $0x0, 0xa8(%rsp)
movq $0x0, 0x20(%rsp)
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x38(%rsp), %rbp
testb %bl, %bl
sete %bl
movq %r14, %rax
movq %rax, 0x48(%rsp)
movq %r12, %rdi
movq %r15, %rsi
callq 0x2fb4
testl %eax, %eax
js 0xc94b
testb $0x1, %bl
jne 0xbe36
movb $-0x1, 0xa(%rsp)
movq %r15, %rdi
movq %rbp, %rsi
leaq 0x1c(%rsp), %rdx
leaq 0x58(%rsp), %rcx
leaq 0xa(%rsp), %r8
leaq 0xc8(%rsp), %r9
callq 0xcb83
xorl %ebx, %ebx
testq %rax, %rax
je 0xbdee
jmp 0xbe75
movb $-0x1, 0xb(%rsp)
movq %r15, %rdi
movq %rbp, %rsi
leaq 0xc(%rsp), %rdx
leaq 0x5c(%rsp), %rcx
leaq 0xb(%rsp), %r8
leaq 0xd0(%rsp), %r9
callq 0xcb83
movq %rax, %r14
movb $0x1, %bl
movl $0x0, %eax
testq %r14, %r14
je 0xbde9
jmp 0xc343
movq %rax, %r14
movq 0x48(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x22a0
testl %eax, %eax
je 0xbec3
movq 0xc8(%rsp), %rax
movq %rax, 0xd0(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0x58(%rsp), %eax
movl %eax, 0x5c(%rsp)
movb 0xa(%rsp), %al
movb %al, 0xb(%rsp)
movq %rbx, %rdi
callq 0x2060
movb $0x1, %bl
jmp 0xc343
movq 0xd0(%rsp), %rsi
movq 0x60(%rsp), %rbx
movq %rbx, %rdi
movq %rsi, 0x28(%rsp)
callq 0xe65a
movl %eax, %ebp
movl %eax, 0x18(%rsp)
movq 0xc8(%rsp), %rax
movq %rbx, %rdi
movq %rax, %rbx
movq %rax, %rsi
callq 0xe65a
movl %eax, %edi
movl %eax, 0x14(%rsp)
movzbl 0xb(%rsp), %eax
movzbl 0xa(%rsp), %esi
cmpb %sil, %al
cmovbl %eax, %esi
cmpl $-0x1, %ebp
je 0xc041
cmpl $-0x1, %edi
je 0xc070
cmpb 0x98(%rsp), %sil
jb 0xc061
movl 0xc(%rsp), %r8d
testl %r8d, %r8d
movl $0x0, %edx
cmovlel %edx, %r8d
movq 0x60(%rsp), %rax
movq 0x8(%rax), %rax
movl %ebp, %ecx
imulq $0x18, %rcx, %rbx
movl 0x10(%rax,%rbx), %ecx
decl %ecx
cmpl %ecx, %r8d
cmovael %ecx, %r8d
movl %r8d, 0xc(%rsp)
movl 0x5c(%rsp), %r9d
testl %r9d, %r9d
cmovlel %edx, %r9d
cmpl %ecx, %r9d
cmovael %ecx, %r9d
movq %r9, 0x28(%rsp)
movl %r9d, 0x5c(%rsp)
movl 0x1c(%rsp), %r9d
testl %r9d, %r9d
cmovlel %edx, %r9d
movl %edi, %ecx
imulq $0x18, %rcx, %rcx
movq %rcx, 0x68(%rsp)
movl 0x10(%rax,%rcx), %eax
decl %eax
cmpl %eax, %r9d
cmovael %eax, %r9d
movq %r9, 0x90(%rsp)
movl %r9d, 0x1c(%rsp)
movl 0x58(%rsp), %r9d
testl %r9d, %r9d
cmovlel %edx, %r9d
cmpl %eax, %r9d
cmovael %eax, %r9d
movl %r9d, 0x58(%rsp)
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rcx
movq (%rcx,%rbx), %rdx
cmpq 0x8(%rcx,%rbx), %rdx
movq %r8, 0x78(%rsp)
movl %esi, 0xe4(%rsp)
movl %ebp, 0xe0(%rsp)
movl %edi, 0xdc(%rsp)
movq %r9, 0x70(%rsp)
jne 0xc0cf
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rdx
cmoveq %rdx, %rsi
movq %rax, %rbp
leaq (%rcx,%rbx), %rax
movq %rsi, 0x8(%rcx,%rbx)
movq 0x10(%rax), %rdi
shlq $0x3, %rsi
callq 0x2390
movq 0x78(%rsp), %r8
movq 0x8(%rbp), %rcx
movq 0x38(%rsp), %rbp
movq %rax, 0x10(%rcx,%rbx)
movq (%rcx,%rbx), %rdx
jmp 0xc0d4
movq %r13, %rdi
movq 0x28(%rsp), %rbx
movq %rbx, %rsi
leaq 0x10(%rsp), %rdx
callq 0xcbe1
cmpl $0x0, 0x10(%rsp)
jne 0xc392
movq 0x48(%rsp), %rdi
movq 0x38(%rsp), %rbp
jmp 0xc331
movq %r13, %rdi
movq %rbx, %rsi
leaq 0x10(%rsp), %rdx
callq 0xcbe1
cmpl $0x0, 0x10(%rsp)
movq 0x38(%rsp), %rbp
je 0xc32c
movq %rbx, %rdi
movl %eax, 0x28(%rsp)
callq 0x2510
movq 0x18(%r13), %rcx
movl 0x28(%rsp), %edx
movq %rax, (%rcx,%rdx,8)
movq 0x1bf49(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
leaq 0x128ce(%rip), %rsi     # 0x1e987
leaq 0x12885(%rip), %rdx     # 0x1e945
movq %rbx, %rcx
xorl %eax, %eax
callq 0x22c0
jmp 0xc32c
movq 0x38(%rsp), %rbp
movq %r8, %rsi
shlq $0x20, %rsi
incq %rsi
movq 0x10(%rcx,%rbx), %rax
leaq 0x1(%rdx), %rdi
movq %rdi, (%rcx,%rbx)
movq %rsi, (%rax,%rdx,8)
movq (%rcx,%rbx), %rdx
cmpq 0x8(%rcx,%rbx), %rdx
jne 0xc12b
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rdx
cmoveq %rdx, %rsi
movq %rsi, 0x8(%rcx,%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2390
movq 0x30(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rax, 0x10(%rcx,%rbx)
movq (%rcx,%rbx), %rdx
movq 0x68(%rsp), %r10
movq 0x28(%rsp), %rsi
shlq $0x20, %rsi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
orq %rdi, %rsi
leaq 0x1(%rdx), %rdi
movq %rdi, (%rcx,%rbx)
movq %rsi, (%rax,%rdx,8)
movq (%rcx,%r10), %rdx
cmpq 0x8(%rcx,%r10), %rdx
jne 0xc193
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rax
cmoveq %rax, %rsi
leaq (%rcx,%r10), %rax
movq %rsi, 0x8(%rcx,%r10)
movq 0x10(%rax), %rdi
shlq $0x3, %rsi
callq 0x2390
movq 0x68(%rsp), %r10
movq 0x30(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rax, 0x10(%rcx,%r10)
movq (%rcx,%r10), %rdx
movq 0x90(%rsp), %rbx
movq %rbx, %rsi
shlq $0x20, %rsi
incq %rsi
movq 0x10(%rcx,%r10), %rax
leaq 0x1(%rdx), %rdi
movq %rdi, (%rcx,%r10)
movq %rsi, (%rax,%rdx,8)
movq (%rcx,%r10), %rdx
cmpq 0x8(%rcx,%r10), %rdx
jne 0xc1f7
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rdx
cmoveq %rdx, %rsi
movq %rsi, 0x8(%rcx,%r10)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2390
movq 0x68(%rsp), %r10
movq 0x30(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rax, 0x10(%rcx,%r10)
movq (%rcx,%r10), %rdx
movq 0x78(%rsp), %r8
movq 0x70(%rsp), %r9
movq %r9, %rsi
shlq $0x20, %rsi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
orq %rdi, %rsi
leaq 0x1(%rdx), %rdi
movq %rdi, (%rcx,%r10)
movq %rsi, (%rax,%rdx,8)
movq 0x40(%rsp), %rcx
addq $0x4, %rcx
movq %rcx, 0x40(%rsp)
cmpq 0x50(%rsp), %rcx
ja 0xc3cd
movl %r8d, %eax
shrl %eax
movq 0x28(%rsp), %rcx
andl %ecx, %r8d
shrl %ecx
addl %eax, %ecx
andl $0x1, %r8d
addl %ecx, %r8d
movl %r8d, 0x84(%rsp)
movl %ebx, %eax
shrl %eax
andl %r9d, %ebx
shrl %r9d
addl %eax, %r9d
andl $0x1, %ebx
addl %r9d, %ebx
movl %ebx, 0x80(%rsp)
movl 0xe0(%rsp), %eax
movl 0xdc(%rsp), %ecx
cmpl %ecx, %eax
jbe 0xc298
movl %ecx, 0x18(%rsp)
movl %eax, 0x14(%rsp)
movl %ebx, 0x84(%rsp)
movl %r8d, 0x80(%rsp)
leaq 0x18(%rsp), %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq 0xb8(%rsp), %rbx
movq %rbx, %rcx
callq 0x24d0
leaq 0x84(%rsp), %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x24d0
leaq 0x14(%rsp), %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x24d0
leaq 0x80(%rsp), %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x24d0
movsbl 0xe4(%rsp), %edi
movq %rbx, %rsi
callq 0x2260
movl 0x18(%rsp), %eax
xorl %ecx, %ecx
xorl %edx, %edx
cmpl 0x14(%rsp), %eax
setne %cl
sete %dl
addq %rdx, 0xb0(%rsp)
addq %rcx, 0xa8(%rsp)
incq 0x88(%rsp)
movq 0x48(%rsp), %rdi
callq 0x2060
movq %r14, %rdi
callq 0x2060
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x20(%rsp), %rax
incq %rax
movq %rax, 0x20(%rsp)
xorl %edx, %edx
movl $0xf4240, %ecx          # imm = 0xF4240
divq %rcx
testq %rdx, %rdx
jne 0xbde1
movq 0x1bc8e(%rip), %rcx     # 0x27ff8
movq (%rcx), %rdi
leaq 0x126a6(%rip), %rsi     # 0x1ea1a
leaq 0x125ca(%rip), %rdx     # 0x1e945
movq %rax, %rcx
movq 0x88(%rsp), %r8
xorl %eax, %eax
callq 0x22c0
jmp 0xbde1
movl %eax, %ebp
movq %rbx, %rdi
callq 0x2510
movq 0x18(%r13), %rcx
movl %ebp, %edx
movq %rax, (%rcx,%rdx,8)
movq 0x1bc4b(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
leaq 0x125d0(%rip), %rsi     # 0x1e987
leaq 0x12587(%rip), %rdx     # 0x1e945
movq %rbx, %rcx
xorl %eax, %eax
callq 0x22c0
jmp 0xc061
movq 0x30(%rsp), %rdi
callq 0x122af
movq %rax, %r8
movq %rax, 0x68(%rsp)
movq 0x1bc12(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
leaq 0x125b9(%rip), %rsi     # 0x1e9a9
leaq 0x1254e(%rip), %rdx     # 0x1e945
movq 0x40(%rsp), %rbx
movq %rbx, %rcx
movq 0x50(%rsp), %r9
xorl %eax, %eax
callq 0x22c0
shrq %rbx
movq 0x68(%rsp), %rax
cmpq %rbx, %rax
movq %rax, %rbx
ja 0xc437
movq %rbx, 0x40(%rsp)
movq 0x78(%rsp), %r8
movq 0x90(%rsp), %rbx
movq 0x70(%rsp), %r9
jmp 0xc235
movq 0x50(%rsp), %rcx
addq %rcx, %rcx
movq 0x1bbb2(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
leaq 0x12595(%rip), %rsi     # 0x1e9e5
leaq 0x124ee(%rip), %rdx     # 0x1e945
movq %rcx, 0x50(%rsp)
xorl %eax, %eax
callq 0x22c0
jmp 0xc41b
movl 0x98(%rsp), %eax
testb %al, %al
jne 0xcb08
movl $0x7ffffff, %eax        # imm = 0x7FFFFFF
movq %rax, 0x50(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x88(%rsp)
movq $0x0, 0x48(%rsp)
movq $0x0, 0x40(%rsp)
movq $0x0, 0xb0(%rsp)
movq $0x0, 0xa8(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x38(%rsp), %rbp
movq 0x60(%rsp), %r14
movq %r12, 0xc0(%rsp)
movq %r12, %rdi
movq %r15, %rsi
callq 0x2fb4
testl %eax, %eax
js 0xc94b
movq 0x8(%r15), %rax
shrq $0x20, %rax
testw $0xf0c, %ax             # imm = 0xF0C
setne %cl
testw %ax, %ax
sete %al
orb %cl, %al
jne 0xc4d3
movq 0x8(%rbp), %rax
movslq (%r15), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x28(%rsp)
movl 0x4(%r15), %r12d
movl %r12d, 0xc(%rsp)
movq %r15, %rdi
callq 0x3362
movl %eax, %ebx
movq 0x8(%rbp), %rax
movslq 0x14(%r15), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x98(%rsp)
movl 0x18(%r15), %eax
movl %eax, 0x90(%rsp)
movq 0x8(%r15), %rax
movq %rax, 0x68(%rsp)
movq %r14, %rdi
movq 0x28(%rsp), %rsi
callq 0xe65a
movl %eax, 0x18(%rsp)
cmpl $-0x1, %eax
movl %eax, 0x78(%rsp)
je 0xc5f7
testl %r12d, %r12d
movl $0x0, %edx
cmovlel %edx, %r12d
movq 0x8(%r14), %rsi
movl %eax, %ecx
imulq $0x18, %rcx, %rbp
movl 0x10(%rsi,%rbp), %ecx
decl %ecx
cmpl %ecx, %r12d
cmovael %ecx, %r12d
testl %ebx, %ebx
cmovlel %edx, %ebx
movl %r12d, 0xc(%rsp)
cmpl %ecx, %ebx
cmovael %ecx, %ebx
movq 0x30(%rsp), %rdi
movq 0x8(%rdi), %rcx
movq (%rcx,%rbp), %rdx
cmpq 0x8(%rcx,%rbp), %rdx
movq %r12, %r8
jne 0xc609
movq $0x0, 0x48(%rsp)
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rdx
cmoveq %rdx, %rsi
movq %rdi, %r12
leaq (%rcx,%rbp), %rax
movq %rsi, 0x8(%rcx,%rbp)
movq 0x10(%rax), %rdi
shlq $0x3, %rsi
movq %r8, %r14
callq 0x2390
movq %r14, %r8
movq 0x8(%r12), %rcx
movq %rax, 0x10(%rcx,%rbp)
movq (%rcx,%rbp), %rdx
jmp 0xc612
movq %r12, 0x70(%rsp)
movq 0xc0(%rsp), %r12
jmp 0xc6ac
movq $0x0, 0x48(%rsp)
movq 0xc0(%rsp), %r12
movq %r8, %rsi
shlq $0x20, %rsi
incq %rsi
movq 0x10(%rcx,%rbp), %rax
leaq 0x1(%rdx), %rdi
movq %rdi, (%rcx,%rbp)
movq %rsi, (%rax,%rdx,8)
movq (%rcx,%rbp), %rdx
cmpq 0x8(%rcx,%rbp), %rdx
movq %r8, 0x70(%rsp)
jne 0xc676
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rdx
cmoveq %rdx, %rsi
movq %rsi, 0x8(%rcx,%rbp)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2390
movq 0x30(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rax, 0x10(%rcx,%rbp)
movq (%rcx,%rbp), %rdx
shlq $0x20, %rbx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
orq %rsi, %rbx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rcx,%rbp)
movq %rbx, (%rax,%rdx,8)
movq 0x40(%rsp), %rbx
addq $0x2, %rbx
cmpq 0x50(%rsp), %rbx
ja 0xc888
movq %rbx, 0x40(%rsp)
movq 0x60(%rsp), %r14
movq 0x38(%rsp), %rbp
btq $0x26, 0x68(%rsp)
movq 0x28(%rsp), %rbx
movq 0x98(%rsp), %rsi
jb 0xc839
movq %r14, %rdi
callq 0xe65a
movl %eax, 0x14(%rsp)
movl 0x78(%rsp), %esi
cmpl $-0x1, %esi
je 0xc7c9
cmpl $-0x1, %eax
je 0xc816
movl 0x90(%rsp), %edi
testl %edi, %edi
movl $0x0, %ecx
cmovlel %ecx, %edi
movq 0x8(%r14), %rcx
movl %eax, %edx
imulq $0x18, %rdx, %rdx
movl 0x10(%rcx,%rdx), %ecx
decl %ecx
cmpl %ecx, %edi
cmovbl %edi, %ecx
movl %ecx, 0x1c(%rsp)
cmpl %eax, %esi
jbe 0xc730
movl %eax, 0x18(%rsp)
movl %esi, 0x14(%rsp)
movl %ecx, 0xc(%rsp)
movq 0x70(%rsp), %rax
movl %eax, 0x1c(%rsp)
leaq 0x18(%rsp), %rdi
pushq $0x4
popq %r14
movq %r14, %rsi
pushq $0x1
popq %rdx
movq 0xb8(%rsp), %rbx
movq %rbx, %rcx
callq 0x24d0
leaq 0xc(%rsp), %rdi
movq %r14, %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x24d0
leaq 0x14(%rsp), %rdi
movq %r14, %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x24d0
leaq 0x1c(%rsp), %rdi
movq %r14, %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x24d0
pushq $-0x1
popq %rdi
movq %rbx, %rsi
callq 0x2260
movl 0x18(%rsp), %eax
xorl %ecx, %ecx
xorl %edx, %edx
cmpl 0x14(%rsp), %eax
setne %cl
sete %dl
addq %rdx, 0xb0(%rsp)
addq %rcx, 0xa8(%rsp)
incq 0x88(%rsp)
movq 0x20(%rsp), %rax
movq 0x60(%rsp), %r14
jmp 0xc83e
movq %r13, %rdi
movq %rbx, %rsi
leaq 0x10(%rsp), %rdx
callq 0xcbe1
cmpl $0x0, 0x10(%rsp)
je 0xc839
movq %rbx, %rdi
movl %eax, %ebx
callq 0x2510
movq 0x18(%r13), %rcx
movl %ebx, %edx
movq %rax, (%rcx,%rdx,8)
movq 0x1b7fd(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
leaq 0x12182(%rip), %rsi     # 0x1e987
leaq 0x12139(%rip), %rdx     # 0x1e945
movq 0x28(%rsp), %rcx
jmp 0xc911
movq %r13, %rdi
movq 0x98(%rsp), %rbx
movq %rbx, %rsi
leaq 0x10(%rsp), %rdx
callq 0xcbe1
cmpl $0x0, 0x10(%rsp)
jne 0xc8de
movq 0x20(%rsp), %rax
incq %rax
movq %rax, 0x20(%rsp)
xorl %edx, %edx
movl $0xf4240, %ecx          # imm = 0xF4240
divq %rcx
testq %rdx, %rdx
jne 0xc4d3
movq 0x1b798(%rip), %rcx     # 0x27ff8
movq (%rcx), %rdi
leaq 0x121b0(%rip), %rsi     # 0x1ea1a
leaq 0x120d4(%rip), %rdx     # 0x1e945
movq %rax, %rcx
movq 0x88(%rsp), %r8
xorl %eax, %eax
callq 0x22c0
jmp 0xc4d3
movq 0x30(%rsp), %rdi
callq 0x122af
movq %rax, %r14
movq 0x1b75c(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
leaq 0x12103(%rip), %rsi     # 0x1e9a9
leaq 0x12098(%rip), %rdx     # 0x1e945
movq %rbx, %rcx
movq %r14, %r8
movq 0x50(%rsp), %r9
xorl %eax, %eax
callq 0x22c0
shrq %rbx
cmpq %rbx, %r14
movq 0x60(%rsp), %rbx
movq 0x38(%rsp), %rbp
ja 0xc91d
movq %r14, 0x40(%rsp)
movq %rbx, %r14
jmp 0xc6b1
movq %rbx, %rdi
movl %eax, 0x28(%rsp)
callq 0x2510
movq 0x18(%r13), %rcx
movl 0x28(%rsp), %edx
movq %rax, (%rcx,%rdx,8)
movq 0x1b6fb(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
leaq 0x12080(%rip), %rsi     # 0x1e987
leaq 0x12037(%rip), %rdx     # 0x1e945
movq %rbx, %rcx
xorl %eax, %eax
callq 0x22c0
jmp 0xc839
movq 0x50(%rsp), %rcx
addq %rcx, %rcx
movq 0x1b6cc(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
leaq 0x120af(%rip), %rsi     # 0x1e9e5
leaq 0x12008(%rip), %rdx     # 0x1e945
movq %rcx, 0x50(%rsp)
xorl %eax, %eax
callq 0x22c0
jmp 0xc8d1
movq 0x30(%rsp), %rdi
movq 0x88(%rsp), %rax
movq %rax, 0xa0(%rsp)
callq 0x122af
movq 0x1b68c(%rip), %rcx     # 0x27ff8
movq (%rcx), %rdi
leaq 0x12033(%rip), %rsi     # 0x1e9a9
leaq 0x11fc8(%rip), %rdx     # 0x1e945
xorl %ebx, %ebx
movq 0x40(%rsp), %rcx
movq %rax, %r8
movq 0x50(%rsp), %r9
xorl %eax, %eax
callq 0x22c0
xorl %r14d, %r14d
movl (%r13), %eax
cmpq %rax, %r14
jae 0xc9cd
movq 0x10(%r13), %rax
movq %r14, %rcx
shrq $0x4, %rcx
movl (%rax,%rcx,4), %eax
movl %ebx, %ecx
andb $0x1e, %cl
shrl %cl, %eax
testb $0x3, %al
jne 0xc9c5
movq 0x18(%r13), %rax
movq (%rax,%r14,8), %rdi
callq 0x2060
incq %r14
addl $0x2, %ebx
jmp 0xc996
movq %r13, %rdi
callq 0xcdc7
movq 0x48(%rsp), %rdi
callq 0x2060
testq %r15, %r15
je 0xc9f5
movq 0x30(%r15), %rdi
callq 0x2060
movq %r15, %rdi
callq 0x2060
movq %rbp, %rdi
callq 0x2d2a
movq %r12, %rdi
callq 0x3496
movq 0xe8(%rsp), %rsi
addq $0x8, %rsi
movq 0xb8(%rsp), %r12
movq %r12, %rdi
xorl %edx, %edx
callq 0x2370
leaq 0xa0(%rsp), %r15
pushq $0x8
popq %rbx
pushq $0x1
popq %r14
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0x24d0
movq (%r15), %r15
imulq $0x11, %r15, %rsi
pushq $0x1
popq %rdx
movq %r12, %rdi
callq 0x2370
movq 0x1b59c(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
movq 0xa8(%rsp), %rax
movq %rax, (%rsp)
leaq 0x1203c(%rip), %rsi     # 0x1eaae
leaq 0x11ecc(%rip), %rdx     # 0x1e945
movq %r15, %rcx
movq 0x20(%rsp), %r8
movq 0xb0(%rsp), %r9
xorl %eax, %eax
callq 0x22c0
movq 0x30(%rsp), %r13
movq %r13, %rdi
movq 0x60(%rsp), %rbp
movq %rbp, %rsi
movsd 0xf0(%rsp), %xmm0
callq 0x132a3
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0x24d0
movq (%r15), %rdx
movq 0x10(%r15), %rax
movq (%rax), %rdi
movq %rbx, %rsi
movq %r12, %rcx
callq 0x24d0
movq %r13, %rdi
callq 0x12243
movq %r15, %rdi
callq 0x12287
movq %rbp, %rdi
callq 0xe20a
movq %r12, %rdi
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2150
movzbl %al, %ecx
movq 0x1b4e6(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
leaq 0x11f36(%rip), %rsi     # 0x1ea52
leaq 0x11e22(%rip), %rdx     # 0x1e945
xorl %eax, %eax
callq 0x22c0
jmp 0xc474
movq 0x1b4c2(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
leaq 0x116b0(%rip), %rsi     # 0x1e1f0
leaq 0x11dfe(%rip), %rdx     # 0x1e945
movq %r14, %rcx
jmp 0xcb67
movq 0x1b4a5(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
leaq 0x11e01(%rip), %rsi     # 0x1e95e
leaq 0x11de1(%rip), %rdx     # 0x1e945
movq %rbx, %rcx
xorl %eax, %eax
callq 0x22c0
pushq $0x1
popq %rdi
callq 0x24b0