// File: /workspace/github_c_makefile_star2_O1/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 $0x108, %rsp            # imm = 0x108
movq %r8, %rbx
movsd %xmm0, 0x100(%rsp)
movl %ecx, 0x68(%rsp)
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %r14
movl $0x1, %esi
movl $0x28, %edx
xorl %edi, %edi
callq 0xb260
movq %rax, %r13
movq %r15, %rdi
movl %ebp, %esi
callq 0x11f82
movq %rax, 0x90(%rsp)
leaq 0x1369c(%rip), %rsi     # 0x2240f
movq %r14, %rdi
callq 0x56db
testq %rax, %rax
je 0xfcc2
movq %rax, %r12
leaq 0x12282(%rip), %rsi     # 0x21010
movq %rbx, %rdi
callq 0x23e0
testq %rax, %rax
je 0xfcca
movq %rax, %r14
movq %rax, %rdi
callq 0x4c49
movq %r14, %rdi
movq 0x90(%rsp), %rbx
movq %rbx, %rsi
callq 0x156fa
movq %rax, 0xf8(%rsp)
movq %r12, %rdi
callq 0x508a
movq %rax, %rbp
movl $0x1, %edi
movl $0x38, %esi
callq 0x2290
movq %rax, %r15
movq %rbp, %rdi
callq 0x5527
movl %eax, 0x18(%rsp)
xorl %eax, %eax
movq %rax, 0xa0(%rsp)
movq %rax, 0xa8(%rsp)
movl %eax, 0x5c(%rsp)
movl %eax, 0x2c(%rsp)
movl %eax, 0x14(%rsp)
movl %eax, 0x10(%rsp)
movl %eax, 0x78(%rsp)
movl %eax, 0x7c(%rsp)
movl %eax, 0x20(%rsp)
movl %eax, 0x24(%rsp)
leaq 0x98(%rsp), %rcx
movq %rax, (%rcx)
movl (%rbx), %edi
callq 0x16058
movq %rax, 0x38(%rsp)
movl $0x8, %esi
movl $0x1, %edx
leaq 0x98(%rsp), %rdi
movq %r14, 0xd0(%rsp)
movq %r14, %rcx
callq 0x24d0
cmpl $0x1, 0x18(%rsp)
jne 0xf569
movq %r13, %rax
addq $0x18, %rax
movq %rax, 0xe0(%rsp)
movl $0x7ffffff, %eax        # imm = 0x7FFFFFF
movq %rax, 0x40(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0xc0(%rsp)
movq $0x0, 0xb8(%rsp)
movq $0x0, 0x50(%rsp)
xorl %ebx, %ebx
movq $0x0, 0x18(%rsp)
movq %r12, 0xc8(%rsp)
movq %r12, %rdi
movq %r15, %rsi
callq 0x5286
testl %eax, %eax
js 0xfadb
testb %bl, %bl
je 0xef45
movb $-0x1, 0xe(%rsp)
movq %r15, %rdi
movq %rbp, %rsi
leaq 0x14(%rsp), %rdx
leaq 0x5c(%rsp), %rcx
leaq 0xe(%rsp), %r8
leaq 0xa0(%rsp), %r9
callq 0xfcd2
testq %rax, %rax
je 0xeeba
movq %rax, %r14
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x22a0
testl %eax, %eax
je 0xef8b
movq 0xa0(%rsp), %rax
movq %rax, 0xa8(%rsp)
movl 0x14(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x5c(%rsp), %eax
movl %eax, 0x2c(%rsp)
movb 0xe(%rsp), %al
movb %al, 0xf(%rsp)
movb $0x1, %bl
movq 0x18(%rsp), %rdi
jmp 0xf440
movb $-0x1, 0xf(%rsp)
movq %r15, %rdi
movq %rbp, %rsi
leaq 0x10(%rsp), %rdx
leaq 0x2c(%rsp), %rcx
leaq 0xf(%rsp), %r8
leaq 0xa8(%rsp), %r9
callq 0xfcd2
movl $0x0, %ecx
movq %rcx, 0x18(%rsp)
testq %rax, %rax
je 0xeeba
movb $0x1, %bl
movq %rax, 0x18(%rsp)
jmp 0xf44a
movq 0xa8(%rsp), %rsi
movq 0x90(%rsp), %r12
movq %r12, %rdi
movq %rsi, 0x48(%rsp)
callq 0x11945
movl %eax, %ebx
movl %eax, 0x24(%rsp)
movq 0xa0(%rsp), %rsi
movq %r12, %rdi
movq %rsi, %r12
callq 0x11945
movl %eax, 0x20(%rsp)
movzbl 0xf(%rsp), %edx
movzbl 0xe(%rsp), %ecx
cmpb %cl, %dl
cmovbl %edx, %ecx
cmpl $-0x1, %ebx
je 0xf3de
cmpl $-0x1, %eax
je 0xf408
cmpb 0x68(%rsp), %cl
movq 0xc8(%rsp), %r12
jb 0xf42e
movl %ecx, 0xb0(%rsp)
movl 0x10(%rsp), %edi
testl %edi, %edi
movl $0x0, %edx
cmovlel %edx, %edi
movq 0x90(%rsp), %rcx
movq 0x8(%rcx), %rsi
movl %ebx, 0xdc(%rsp)
movl %ebx, %ebx
leaq (,%rbx,8), %rcx
leaq (%rcx,%rcx,2), %r10
movl 0x10(%rsi,%r10), %ecx
decl %ecx
cmpl %ecx, %edi
cmovael %ecx, %edi
movl %edi, 0x10(%rsp)
movl 0x2c(%rsp), %r8d
testl %r8d, %r8d
cmovlel %edx, %r8d
cmpl %ecx, %r8d
cmovael %ecx, %r8d
movq %r8, 0x60(%rsp)
movl %r8d, 0x2c(%rsp)
movl 0x14(%rsp), %ecx
testl %ecx, %ecx
cmovlel %edx, %ecx
movl %eax, 0xd8(%rsp)
movl %eax, %eax
movq %rax, 0xf0(%rsp)
leaq (%rax,%rax,2), %r9
movl 0x10(%rsi,%r9,8), %eax
decl %eax
cmpl %eax, %ecx
cmovael %eax, %ecx
movq %rcx, 0x48(%rsp)
movl %ecx, 0x14(%rsp)
movl 0x5c(%rsp), %ecx
testl %ecx, %ecx
cmovlel %edx, %ecx
cmpl %eax, %ecx
cmovael %eax, %ecx
movq %rcx, 0x70(%rsp)
movl %ecx, 0x5c(%rsp)
movq 0x38(%rsp), %r8
movq 0x8(%r8), %rax
movq 0x8(%rax,%r10), %rcx
cmpq %rcx, (%rax,%r10)
movq %r9, 0x88(%rsp)
movq %rdi, 0x80(%rsp)
movq %r10, 0xe8(%rsp)
jne 0xf121
leaq (%rax,%r10), %rdx
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rax,%r10)
movq 0x8(%rdx), %rsi
movq 0x10(%rdx), %rdi
shlq $0x3, %rsi
callq 0x2390
movq 0xe8(%rsp), %r10
movq 0x88(%rsp), %r9
movq 0x80(%rsp), %rdi
movq 0x38(%rsp), %r8
movq 0x8(%r8), %rcx
movq %rax, 0x10(%rcx,%r10)
movq %rdi, %rcx
shlq $0x20, %rcx
incq %rcx
movq 0x8(%r8), %rax
leaq (%rbx,%rbx,2), %rbx
movq (%rax,%rbx,8), %rdx
movq 0x10(%rax,%rbx,8), %rdi
leaq 0x1(%rdx), %rsi
movq %rsi, (%rax,%rbx,8)
movq %rcx, (%rdi,%rdx,8)
movq 0x8(%rax,%rbx,8), %rcx
cmpq %rcx, (%rax,%rbx,8)
jne 0xf197
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
leaq (%rax,%rbx,8), %rcx
movq %rdx, 0x8(%rax,%r10)
movq 0x8(%rcx), %rsi
shlq $0x3, %rsi
callq 0x2390
movq 0x88(%rsp), %r9
movq 0x38(%rsp), %r8
movq 0x8(%r8), %rcx
movq 0xe8(%rsp), %rdx
movq %rax, 0x10(%rcx,%rdx)
movq 0x60(%rsp), %rcx
shlq $0x20, %rcx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
orq %rax, %rcx
movq 0x8(%r8), %rax
movq (%rax,%rbx,8), %rdx
movq 0x10(%rax,%rbx,8), %rsi
leaq 0x1(%rdx), %rdi
movq %rdi, (%rax,%rbx,8)
movq %rcx, (%rsi,%rdx,8)
movq 0x8(%rax,%r9,8), %rcx
cmpq %rcx, (%rax,%r9,8)
jne 0xf220
leaq (%rax,%r9,8), %rdx
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq 0xf0(%rsp), %rcx
leaq (,%rcx,8), %rcx
leaq (%rcx,%rcx,2), %rbx
movq %rsi, 0x8(%rax,%rbx)
movq 0x8(%rdx), %rsi
movq 0x10(%rdx), %rdi
shlq $0x3, %rsi
callq 0x2390
movq 0x88(%rsp), %r9
movq 0x38(%rsp), %r8
movq 0x8(%r8), %rcx
movq %rax, 0x10(%rcx,%rbx)
movq 0x48(%rsp), %rcx
shlq $0x20, %rcx
incq %rcx
movq 0x8(%r8), %rax
movq (%rax,%r9,8), %rdx
movq 0x10(%rax,%r9,8), %rdi
leaq 0x1(%rdx), %rsi
movq %rsi, (%rax,%r9,8)
movq %rcx, (%rdi,%rdx,8)
movq 0x8(%rax,%r9,8), %rcx
cmpq %rcx, (%rax,%r9,8)
jne 0xf29c
leaq (%rax,%r9,8), %rdx
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq 0xf0(%rsp), %rcx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rbx
movq %rsi, 0x8(%rax,%rbx)
movq 0x8(%rdx), %rsi
shlq $0x3, %rsi
callq 0x2390
movq 0x88(%rsp), %r9
movq 0x38(%rsp), %r8
movq 0x8(%r8), %rcx
movq %rax, 0x10(%rcx,%rbx)
movq 0x70(%rsp), %rax
shlq $0x20, %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
orq %rcx, %rax
movq 0x8(%r8), %rcx
movq (%rcx,%r9,8), %rdx
movq 0x10(%rcx,%r9,8), %rsi
leaq 0x1(%rdx), %rdi
movq %rdi, (%rcx,%r9,8)
movq %rax, (%rsi,%rdx,8)
movq 0x30(%rsp), %rbx
addq $0x4, %rbx
cmpq 0x40(%rsp), %rbx
ja 0xf4ed
movq %rbx, 0x30(%rsp)
movq 0x80(%rsp), %rdx
movl %edx, %eax
shrl %eax
movq 0x60(%rsp), %rcx
andl %ecx, %edx
shrl %ecx
addl %eax, %ecx
andl $0x1, %edx
addl %ecx, %edx
movl %edx, 0x7c(%rsp)
movq 0x48(%rsp), %rsi
movl %esi, %eax
shrl %eax
movq 0x70(%rsp), %rcx
andl %ecx, %esi
shrl %ecx
addl %eax, %ecx
andl $0x1, %esi
addl %ecx, %esi
movl %esi, 0x78(%rsp)
movl 0xdc(%rsp), %eax
movl 0xd8(%rsp), %ecx
cmpl %ecx, %eax
jbe 0xf33e
movl %ecx, 0x24(%rsp)
movl %eax, 0x20(%rsp)
movl %esi, 0x7c(%rsp)
movl %edx, 0x78(%rsp)
movl $0x4, %esi
movl $0x1, %edx
leaq 0x24(%rsp), %rdi
movq 0xd0(%rsp), %rbx
movq %rbx, %rcx
callq 0x24d0
movl $0x4, %esi
movl $0x1, %edx
leaq 0x7c(%rsp), %rdi
movq %rbx, %rcx
callq 0x24d0
movl $0x4, %esi
movl $0x1, %edx
leaq 0x20(%rsp), %rdi
movq %rbx, %rcx
callq 0x24d0
movl $0x4, %esi
movl $0x1, %edx
leaq 0x78(%rsp), %rdi
movq %rbx, %rcx
callq 0x24d0
movsbl 0xb0(%rsp), %edi
movq %rbx, %rsi
callq 0x2260
movl 0x24(%rsp), %eax
xorl %ecx, %ecx
xorl %edx, %edx
cmpl 0x20(%rsp), %eax
setne %cl
sete %dl
addq %rdx, 0xc0(%rsp)
addq %rcx, 0xb8(%rsp)
incq 0x98(%rsp)
jmp 0xf42e
movq %r13, %rdi
movq 0x48(%rsp), %rbx
movq %rbx, %rsi
leaq 0x28(%rsp), %rdx
callq 0xfd31
cmpl $0x0, 0x28(%rsp)
jne 0xf4bf
movq 0xc8(%rsp), %r12
jmp 0xf42e
movq %r13, %rdi
movq %r12, %rbx
movq %r12, %rsi
leaq 0x28(%rsp), %rdx
callq 0xfd31
cmpl $0x0, 0x28(%rsp)
movq 0xc8(%rsp), %r12
jne 0xf4d6
movq 0x18(%rsp), %rdi
callq 0x2060
xorl %ebx, %ebx
movq %r14, %rdi
xorl %r14d, %r14d
callq 0x2060
movq %r14, 0x18(%rsp)
movq 0x50(%rsp), %rsi
incq %rsi
movq %rsi, %rax
movabsq $0x431bde82d7b634db, %rcx # imm = 0x431BDE82D7B634DB
mulq %rcx
movq %rdx, %rcx
movq %rsi, 0x50(%rsp)
movabsq $0x790fb65668c26139, %rdx # imm = 0x790FB65668C26139
imulq %rdx, %rsi
rorq $0x6, %rsi
movabsq $0x10c6f7a0b5ed, %rdx   # imm = 0x10C6F7A0B5ED
cmpq %rdx, %rsi
ja 0xeeba
shrq $0x12, %rcx
movq 0x1bb5e(%rip), %rax     # 0x2aff8
movq (%rax), %rdi
movq 0x98(%rsp), %r8
leaq 0x1257e(%rip), %rsi     # 0x21a2a
leaq 0x124a2(%rip), %rdx     # 0x21955
xorl %eax, %eax
callq 0x22c0
jmp 0xeeba
movq %rbx, %rdi
movq 0xe0(%rsp), %rsi
movl %eax, %edx
callq 0x2a8b
jmp 0xf3fe
movq %rbx, %rdi
movq 0xe0(%rsp), %rsi
movl %eax, %edx
callq 0x2a49
jmp 0xf42e
movq %r8, %rdi
callq 0x16118
movq %rax, %r8
movq %rax, 0x30(%rsp)
movq 0x1baf4(%rip), %rax     # 0x2aff8
movq (%rax), %rdi
leaq 0x124ab(%rip), %rsi     # 0x219b9
leaq 0x12440(%rip), %rdx     # 0x21955
movq %rbx, %rcx
movq 0x40(%rsp), %r9
xorl %eax, %eax
callq 0x22c0
shrq %rbx
movq 0x30(%rsp), %rax
cmpq %rbx, %rax
movq %rax, %rbx
jbe 0xf2da
movq 0x40(%rsp), %rcx
addq %rcx, %rcx
movq 0x1bab1(%rip), %rax     # 0x2aff8
movq (%rax), %rdi
leaq 0x124a4(%rip), %rsi     # 0x219f5
leaq 0x123fd(%rip), %rdx     # 0x21955
movq %rcx, 0x40(%rsp)
xorl %eax, %eax
callq 0x22c0
jmp 0xf2da
movl 0x68(%rsp), %eax
testb %al, %al
je 0xf579
movzbl %al, %edi
callq 0x29a2
movq 0xa8(%rsp), %rax
movq %rax, 0x68(%rsp)
movl 0x2c(%rsp), %eax
movq %rax, 0x48(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x80(%rsp)
movq %r13, %rax
addq $0x18, %rax
movq %rax, 0xb0(%rsp)
movl $0x7ffffff, %eax        # imm = 0x7FFFFFF
movq %rax, 0x40(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0xc0(%rsp)
movq $0x0, 0xb8(%rsp)
movq $0x0, 0x50(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x14(%rsp), %r14d
movq %r12, %rdi
movq %r15, %rsi
callq 0x5286
testl %eax, %eax
js 0xfa92
movq 0x8(%r15), %rax
shrq $0x20, %rax
testl $0xf0c, %eax            # imm = 0xF0C
setne %cl
testw %ax, %ax
sete %al
orb %cl, %al
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jne 0xf673
movq 0x8(%rbp), %rax
movslq (%r15), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x68(%rsp)
movl 0x4(%r15), %eax
movl %eax, 0x18(%rsp)
movq %r15, %rdi
callq 0x56a1
movq %rax, 0x48(%rsp)
movq 0x8(%rbp), %rax
movslq 0x14(%r15), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x60(%rsp)
movl 0x18(%r15), %r14d
movq 0x8(%r15), %rbx
shrq $0x26, %rbx
andl $0x1, %ebx
testl %ebx, %ebx
js 0xf5fc
movl 0x18(%rsp), %eax
movl %eax, 0x10(%rsp)
movl %r14d, 0x14(%rsp)
movq 0x90(%rsp), %r14
movq %r14, %rdi
movq 0x68(%rsp), %rsi
callq 0x11945
movl %eax, 0x24(%rsp)
cmpl $-0x1, %eax
je 0xf812
movq %r14, %rcx
movl 0x10(%rsp), %r14d
testl %r14d, %r14d
movl $0x0, %edx
cmovlel %edx, %r14d
movq 0x8(%rcx), %rsi
movl %eax, 0x18(%rsp)
movl %eax, %edi
leaq (,%rdi,8), %rcx
leaq (%rcx,%rcx,2), %r9
movl 0x10(%rsi,%r9), %eax
decl %eax
cmpl %eax, %r14d
cmovael %eax, %r14d
movq 0x48(%rsp), %rcx
testl %ecx, %ecx
cmovlel %edx, %ecx
movl %r14d, 0x10(%rsp)
cmpl %eax, %ecx
cmovael %eax, %ecx
movq %rcx, 0x48(%rsp)
movq 0x38(%rsp), %r8
movq 0x8(%r8), %rax
movq 0x8(%rax,%r9), %rcx
cmpq %rcx, (%rax,%r9)
movq %r9, 0x70(%rsp)
jne 0xf75d
leaq (%rax,%r9), %rdx
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rax,%r9)
movq 0x8(%rdx), %rsi
movq %rdi, 0x88(%rsp)
movq 0x10(%rdx), %rdi
shlq $0x3, %rsi
callq 0x2390
movq 0x88(%rsp), %rdi
movq 0x70(%rsp), %r9
movq 0x38(%rsp), %r8
movq 0x8(%r8), %rcx
movq %rax, 0x10(%rcx,%r9)
shlq $0x20, %r14
incq %r14
movq 0x8(%r8), %rax
leaq (%rdi,%rdi,2), %r10
movq (%rax,%r10,8), %rcx
movq 0x10(%rax,%r10,8), %rdi
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax,%r10,8)
movq %r14, (%rdi,%rcx,8)
movq 0x8(%rax,%r10,8), %rcx
cmpq %rcx, (%rax,%r10,8)
jne 0xf7cb
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
leaq (%rax,%r10,8), %rcx
movq %rdx, 0x8(%rax,%r9)
movq 0x8(%rcx), %rsi
shlq $0x3, %rsi
movq %r10, %r14
callq 0x2390
movq %r14, %r10
movq 0x38(%rsp), %r8
movq 0x8(%r8), %rcx
movq 0x70(%rsp), %rdx
movq %rax, 0x10(%rcx,%rdx)
movq 0x48(%rsp), %rax
shlq $0x20, %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
orq %rcx, %rax
movq 0x8(%r8), %rcx
movq (%rcx,%r10,8), %rdx
movq 0x10(%rcx,%r10,8), %rsi
leaq 0x1(%rdx), %rdi
movq %rdi, (%rcx,%r10,8)
movq %rax, (%rsi,%rdx,8)
movq 0x30(%rsp), %rcx
addq $0x2, %rcx
movq %rcx, 0x30(%rsp)
cmpq 0x40(%rsp), %rcx
ja 0xfa0e
movl 0x18(%rsp), %eax
testl %ebx, %ebx
je 0xf88b
movq 0x50(%rsp), %rbx
incq %rbx
movq %rbx, %rax
movabsq $0x431bde82d7b634db, %rcx # imm = 0x431BDE82D7B634DB
mulq %rcx
movq %rdx, %rcx
movq %rbx, 0x50(%rsp)
movabsq $0x790fb65668c26139, %rdx # imm = 0x790FB65668C26139
imulq %rdx, %rbx
rorq $0x6, %rbx
movabsq $0x10c6f7a0b5ed, %rdx   # imm = 0x10C6F7A0B5ED
cmpq %rdx, %rbx
ja 0xf5ef
shrq $0x12, %rcx
movq 0x1b792(%rip), %rax     # 0x2aff8
movq (%rax), %rdi
leaq 0x121ba(%rip), %rsi     # 0x21a2a
leaq 0x120de(%rip), %rdx     # 0x21955
movq 0x80(%rsp), %r8
xorl %eax, %eax
callq 0x22c0
jmp 0xf5ef
movq 0x90(%rsp), %rbx
movl %eax, %r14d
movq %rbx, %rdi
movq 0x60(%rsp), %rsi
callq 0x11945
movl %eax, 0x20(%rsp)
cmpl $-0x1, %r14d
je 0xf99d
cmpl $-0x1, %eax
je 0xf9d8
movl %r14d, %edi
movl 0x14(%rsp), %edx
testl %edx, %edx
movl $0x0, %ecx
cmovlel %ecx, %edx
movq 0x8(%rbx), %rcx
movl %eax, %esi
leaq (%rsi,%rsi,2), %rsi
movl 0x10(%rcx,%rsi,8), %ecx
decl %ecx
cmpl %ecx, %edx
cmovbl %edx, %ecx
movl %ecx, 0x14(%rsp)
cmpl %eax, %r14d
jbe 0xf8fd
movl %eax, 0x24(%rsp)
movl %edi, 0x20(%rsp)
movl 0x10(%rsp), %eax
movl %ecx, 0x10(%rsp)
movl %eax, 0x14(%rsp)
movl $0x4, %esi
movl $0x1, %edx
leaq 0x24(%rsp), %rdi
movq 0xd0(%rsp), %rbx
movq %rbx, %rcx
callq 0x24d0
movl $0x4, %esi
movl $0x1, %edx
leaq 0x10(%rsp), %rdi
movq %rbx, %rcx
callq 0x24d0
movl $0x4, %esi
movl $0x1, %edx
leaq 0x20(%rsp), %rdi
movq %rbx, %rcx
callq 0x24d0
movl $0x4, %esi
movl $0x1, %edx
leaq 0x14(%rsp), %rdi
movq %rbx, %rcx
callq 0x24d0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movq %rbx, %rsi
callq 0x2260
movl 0x24(%rsp), %eax
xorl %ecx, %ecx
xorl %edx, %edx
cmpl 0x20(%rsp), %eax
setne %cl
sete %dl
addq %rdx, 0xc0(%rsp)
addq %rcx, 0xb8(%rsp)
incq 0x80(%rsp)
jmp 0xf816
movq %r13, %rdi
movq 0x68(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0xfd31
cmpl $0x0, 0x28(%rsp)
movq 0x50(%rsp), %rbx
je 0xf81b
movq 0x68(%rsp), %rdi
movq 0xb0(%rsp), %rsi
movl %eax, %edx
callq 0x2a07
jmp 0xf81b
movq %r13, %rdi
movq 0x60(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0xfd31
cmpl $0x0, 0x28(%rsp)
je 0xf816
movq 0x60(%rsp), %rdi
movq 0xb0(%rsp), %rsi
movl %eax, %edx
callq 0x29c5
jmp 0xf816
movq %r8, %rdi
callq 0x16118
movq %rax, %r8
movq %rax, 0x70(%rsp)
movq 0x1b5d3(%rip), %rax     # 0x2aff8
movq (%rax), %rdi
leaq 0x11f8a(%rip), %rsi     # 0x219b9
leaq 0x11f1f(%rip), %rdx     # 0x21955
movq 0x30(%rsp), %r14
movq %r14, %rcx
movq 0x40(%rsp), %r9
xorl %eax, %eax
callq 0x22c0
shrq %r14
movq 0x70(%rsp), %rax
cmpq %r14, %rax
movq %rax, %r14
ja 0xfa64
movq %r14, 0x30(%rsp)
jmp 0xf80e
movq 0x40(%rsp), %rcx
addq %rcx, %rcx
movq 0x1b585(%rip), %rax     # 0x2aff8
movq (%rax), %rdi
leaq 0x11f78(%rip), %rsi     # 0x219f5
leaq 0x11ed1(%rip), %rdx     # 0x21955
movq %rcx, 0x40(%rsp)
xorl %eax, %eax
callq 0x22c0
jmp 0xfa5a
movq 0x80(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0xa8(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x10(%rsp)
movq 0x48(%rsp), %rax
movl %eax, 0x2c(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0xa0(%rsp)
movl %r14d, 0x14(%rsp)
movq $0x0, 0x18(%rsp)
movq 0x38(%rsp), %rdi
callq 0x16118
movq 0x1b50c(%rip), %rcx     # 0x2aff8
movq (%rcx), %rdi
leaq 0x11ec3(%rip), %rsi     # 0x219b9
leaq 0x11e58(%rip), %rdx     # 0x21955
xorl %ebx, %ebx
movq 0x30(%rsp), %rcx
movq %rax, %r8
movq 0x40(%rsp), %r9
xorl %eax, %eax
callq 0x22c0
cmpl $0x0, (%r13)
je 0xfb51
xorl %r14d, %r14d
movq 0x10(%r13), %rax
movl %r14d, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %eax
movl %ebx, %ecx
andb $0x1e, %cl
shrl %cl, %eax
testb $0x3, %al
jne 0xfb42
movq 0x18(%r13), %rax
movq (%rax,%r14,8), %rdi
callq 0x2060
incq %r14
movl (%r13), %eax
addl $0x2, %ebx
cmpq %rax, %r14
jb 0xfb1d
movq 0x18(%r13), %rsi
xorl %edi, %edi
callq 0xb302
movq 0x10(%r13), %rsi
xorl %edi, %edi
callq 0xb302
movq 0x20(%r13), %rsi
xorl %edi, %edi
callq 0xb302
xorl %edi, %edi
movq %r13, %rsi
callq 0xb302
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0xfb8b
callq 0x2060
testq %r15, %r15
je 0xfba1
movq 0x30(%r15), %rdi
callq 0x2060
movq %r15, %rdi
callq 0x2060
movq %rbp, %rdi
callq 0x501d
movq %r12, %rdi
callq 0x5762
movq 0xf8(%rsp), %rsi
addq $0x8, %rsi
movq 0xd0(%rsp), %r15
movq %r15, %rdi
xorl %edx, %edx
callq 0x2370
leaq 0x98(%rsp), %rbx
movl $0x8, %esi
movl $0x1, %edx
movq %rbx, %rdi
movq %r15, %rcx
callq 0x24d0
movq (%rbx), %rbx
movq %rbx, %rsi
shlq $0x4, %rsi
addq %rbx, %rsi
movq %r15, %rdi
movl $0x1, %edx
callq 0x2370
movq 0x1b3eb(%rip), %rax     # 0x2aff8
movq (%rax), %rdi
movq 0xb8(%rsp), %rax
movq %rax, (%rsp)
leaq 0x11e9b(%rip), %rsi     # 0x21abe
leaq 0x11d2b(%rip), %rdx     # 0x21955
movq %rbx, %rcx
movq 0x50(%rsp), %r8
movq 0xc0(%rsp), %r9
xorl %eax, %eax
callq 0x22c0
movq 0x38(%rsp), %r12
movq %r12, %rdi
movq 0x90(%rsp), %r14
movq %r14, %rsi
movsd 0x100(%rsp), %xmm0
callq 0x3338
movq %rax, %rbx
movl $0x8, %esi
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rcx
callq 0x24d0
movq (%rbx), %rdx
movq 0x10(%rbx), %rax
movq (%rax), %rdi
movl $0x8, %esi
movq %r15, %rcx
callq 0x24d0
movq %r12, %rdi
callq 0x160a3
movq %rbx, %rdi
callq 0x160f0
movq %r14, %rdi
callq 0x1148c
movq %r15, %rdi
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2150
movq %r14, %rdi
callq 0x2af8
movq %rbx, %rdi
callq 0x2acd