// File: /workspace/github_c_makefile_star2_O3/c-zhou[P]oatk/rotate.c
// Function: main
int main(int argc, char *argv[])
{
    const char *opt_str = "l:s:o:rVv:h";
    ketopt_t opt = KETOPT_INIT;
    int c, line_width, absent, ret = 0;
    sstream_t *fin;
    kh_str_t *reg_list;
    khint32_t k;
    FILE *fp_help;
    char *rotate_file, *seq_id, *seq;
    int seq_pos, strand, ln;
    
    sys_init();

    fp_help = stderr;
    line_width = 60;
    rotate_file = seq_id = 0;
    seq_pos = 0;
    strand = 0;

    while ((c = ketopt(&opt, argc, argv, 1, opt_str, long_options)) >=0 ) {
        if (c == 's') rotate_file = opt.arg;
        else if (c == 'l') line_width = atoi(opt.arg);
        else if (c == 'r') strand = 1;
        else if (c == 'v') VERBOSE = atoi(opt.arg);
        else if (c == 'h') fp_help = stdout;
        else if (c == 'o') {
            if (strcmp(opt.arg, "-") != 0) {
                if (freopen(opt.arg, "wb", stdout) == NULL) {
                    fprintf(stderr, "[ERROR]\033[1;31m failed to write the output to file '%s'\033[0m: %s\n", opt.arg, strerror(errno));
                    return 1;
                }
            }
        }
        else if (c == 'V') {
            puts(SEQROTATE_VERSION);
            return 0;
        }
        else if (c == '?') {
            fprintf(stderr, "[E::%s] unknown option: \"%s\"\n", __func__, argv[opt.i - 1]);
            return 1;
        }
        else if (c == ':') {
            fprintf(stderr, "[E::%s] missing option: \"%s\"\n", __func__, argv[opt.i - 1]);
            return 1;
        }
    }
    
    if (argc == opt.ind || fp_help == stdout) {
        fprintf(fp_help, "\n");
        fprintf(fp_help, "Usage: rotate [options] <file>[.fa[.gz]] [seq pos]\n");
        fprintf(fp_help, "Options:\n");
        fprintf(fp_help, "    -s STR        two/three-column rotation file\n");
        fprintf(fp_help, "    -r STR        rotate in reverse strand (effective without -s)\n");
        fprintf(fp_help, "    -l INT        number of residues per line; 0 for 2^31-1 [%d]\n", line_width);
        fprintf(fp_help, "    -o FILE       output results to FILE [stdout]\n");
        fprintf(fp_help, "    -v INT        verbose level [%d]\n", VERBOSE);
        fprintf(fp_help, "    --version     show version number\n");
        fprintf(fp_help, "\n");
        fprintf(fp_help, "Example: ./rotate asm.fa ctg1 100\n\n");
        return fp_help == stdout? 0 : 1;
    }

    if (argc - opt.ind < 1) {
        fprintf(stderr, "[E::%s] missing input: please specify the input FASTA file\n", __func__);
        return 1;
    }

    if (argc - opt.ind > 2) {
        seq_id  = argv[opt.ind + 1];
        seq_pos = atoll(argv[opt.ind + 2]);
        if (seq_pos <= 0) {
            fprintf(stderr, "[E::%s] rotate position must be positive: %d\n", __func__, seq_pos);
            exit(1);
        }
        if (rotate_file) {
            fprintf(stderr, "[W::%s] rotate file %s ignored\n", __func__, rotate_file);
            fprintf(stderr, "[W::%s] using positional parameters: %s %u\n", __func__, seq_id, seq_pos);
        }
    } else {
        if (!rotate_file) {
            fprintf(stderr, "[E::%s] need a file (-s) or two rotation parameters\n", __func__);
            return 1;
        }
    }

    if (line_width == 0) line_width = INT32_MAX;

    reg_list = kh_str_init();
    if (seq_id) {
        k = kh_str_put(reg_list, strdup(seq_id), &absent);
        kh_val(reg_list, k) = (uint64_t) seq_pos << 1 | strand;
    } else {
        gzFile fp;
        kstring_t s = {0,0,0};
        kstream_t *ks;
        int dret;
        int64_t pos, lineno = 0;
        char *p, *q, *sid;

        if (strand)
            fprintf(stderr, "[W::%s] the option '-r' is not effective with '-s' \n", __func__);

        fp = gzopen(rotate_file, "r");
        if (!fp) {
            fprintf(stderr, "[E::%s] failed to open file %s to read\n", __func__, rotate_file);
            exit(1);
        }
        ks = ks_init(fp);
        while (ks_getuntil(ks, KS_SEP_LINE, &s, &dret) >= 0) {
            ++lineno;
            
            p = q = s.s;
            while (isspace(*q) && *q != '\0') ++q;
            p = q;
            while (!isspace(*q) && *q != '\0') ++q;
            if (p == q) continue; // empty line
            MYMALLOC(sid, q - p + 1);
            memcpy(sid, p, q - p);
            sid[q-p] = '\0';

            while (isspace(*q) && *q != '\0') ++q;
            p = q;
            while (!isspace(*q) && *q != '\0') ++q;
            pos = atoll(p);
            if (p == q) {
                // no second column found
                fprintf(stderr, "[E::%s] invalid line at line %ld: %s\n", __func__, (long) lineno, s.s);
                fprintf(stderr, "[E::%s] need at least two columns\n", __func__);
                exit(1);
            }
            if (pos <= 0) {
                fprintf(stderr, "[E::%s] rotate position must be positive: %ld\n", __func__, pos);
                exit(1);
            }
            pos <<= 1;

            while (isspace(*q) && *q != '\0') ++q;
            p = q;
            while (!isspace(*q) && *q != '\0') ++q;
            
            if (p != q) {
                if (*p == '-') pos |= 1;
                else if (*p != '+') {
                    fprintf(stderr, "[E::%s] invalid line at line %ld: %s\n", __func__, (long) lineno, s.s);
                    fprintf(stderr, "[E::%s] the third column (strand) must be '+' or '-'\n", __func__);
                    exit(1);
                }
            }
            
            absent = 1;
            k = kh_str_put(reg_list, sid, &absent);
            if (absent)
                kh_val(reg_list, k) = (uint64_t) pos;
            else {
                fprintf(stderr, "[E::%s] invalid line at line %ld: %s\n", __func__, (long) lineno, s.s);
                fprintf(stderr, "[E::%s] duplicate sequence '%s'\n", __func__, sid);
                exit(1);
            }
        }

        ks_destroy(ks);
        gzclose(fp);
    }

    fin = sstream_open(&argv[opt.ind], 1);
    if (fin == 0) {
        fprintf(stderr, "[E::%s] failed to open files: %s\n", __func__, strerror(errno));
        exit(1);
    }
    while ((ln = sstream_read(fin)) >= 0) {
        seq_id = fin->s->ks->name.s;
        seq = fin->s->ks->seq.s;
        k = kh_str_get(reg_list, seq_id);
        fprintf(stdout, ">%s\n", seq_id);
        if (k != kh_end(reg_list)) {
            seq_pos = (kh_val(reg_list, k)) >> 1;
            strand = (kh_val(reg_list, k)) & 1;
            if (seq_pos > ln) {
                fprintf(stderr, "[E::%s] rotation position (%d) larger than sequence length (%d)\n", __func__, seq_pos, ln);
                exit(1);
            }
            if (strand) {
                print_seq(seq, seq_pos, 1, 0, line_width, stdout);
                print_seq(seq + seq_pos, ln - seq_pos, 1, seq_pos, line_width, stdout);
            } else {
                seq_pos -= 1;
                print_seq(seq + seq_pos, ln - seq_pos, 0, 0, line_width, stdout);
                print_seq(seq, seq_pos, 0, ln - seq_pos, line_width, stdout);
            }
            free((void *)kh_key(reg_list, k));
            kh_str_del(reg_list, k);
        } else
            print_seq(seq, ln, 0, 0, line_width, stdout);
        if (ln % line_width != 0) fputc('\n', stdout);
    }
    sstream_close(fin);

    for (k = (khint32_t) 0; k < kh_end(reg_list); k++) {
        if (kh_exist(reg_list, k)) {
            seq_id = (char *) kh_key(reg_list, k);
            fprintf(stderr, "[W::%s] sequence '%s' not found in the FASTA file\n", __func__, seq_id);
            free(seq_id);
        }
    }
    kh_str_destroy(reg_list);

    if (fflush(stdout) == EOF) {
        fprintf(stderr, "[E::%s] failed to write the results\n", __func__);
        exit(1);
    }

    if (VERBOSE >= 0 && !ret) {
        fprintf(stderr, "[M::%s] Version: %s\n", __func__, SEQROTATE_VERSION);
        fprintf(stderr, "[M::%s] CMD:", __func__);
        int i;
        for (i = 0; i < argc; ++i)
            fprintf(stderr, " %s", argv[i]);
        fprintf(stderr, "\n[M::%s] Real time: %.3f sec; CPU: %.3f sec; Peak RSS: %.3f GB\n", __func__, realtime() - realtime0, cputime(), peakrss() / 1024.0 / 1024.0 / 1024.0);
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, 0x40(%rsp)
movl %edi, %ebx
callq 0x47b3
movq 0x65a0(%rip), %r15      # 0x8ff0
movq (%r15), %r14
cmpl $0x2, %ebx
movq %rbx, 0x78(%rsp)
jl 0x2fa6
leal -0x1(%rbx), %eax
movl %eax, 0x84(%rsp)
movl %ebx, %r12d
negl %r12d
movl $0x1, %edx
xorl %esi, %esi
movl $0x3c, %r11d
xorl %r10d, %r10d
xorl %r8d, %r8d
movl $0x0, 0x30(%rsp)
movq 0x40(%rsp), %r9
movq %r12, 0x28(%rsp)
movq %r10, %rbp
movq %rsi, (%rsp)
movq %rdx, 0x8(%rsp)
movslq %edx, %r10
leal (%r8,%rbx), %ecx
subl %r10d, %ecx
movl %r10d, %eax
leaq (%r12,%rax), %rsi
movq %r10, %r12
shlq $0x20, %r12
leaq (%r9,%r10,8), %rdi
movq %rdi, %rbx
xorl %r13d, %r13d
movq %r8, 0x58(%rsp)
movl %r8d, %r15d
movq %r10, 0x48(%rsp)
movq (%rdi,%r13,8), %r8
cmpb $0x2d, (%r8)
jne 0x2ae2
cmpb $0x0, 0x1(%r8)
jne 0x2b09
incq %r10
incl %r15d
incq %r13
movabsq $0x100000000, %r8       # imm = 0x100000000
addq %r8, %r12
addq $0x8, %rbx
movl %esi, %r8d
addl %r13d, %r8d
jne 0x2ad1
jmp 0x2fbf
sarq $0x1d, %r12
movq (%r9,%r12), %rsi
cmpb $0x2d, (%rsi)
jne 0x39bb
leaq (%rax,%r13), %rcx
movq %rcx, 0x68(%rsp)
movl 0x58(%rsp), %ecx
leaq (%rcx,%r13), %rdx
movq %rdx, 0x38(%rsp)
movzbl 0x1(%rsi), %edx
cmpl $0x2d, %edx
movq %rbp, %r10
movq %rbp, 0x18(%rsp)
movl %r11d, 0x14(%rsp)
movq %r14, 0x50(%rsp)
je 0x2bc9
testl %edx, %edx
je 0x39db
movl 0x30(%rsp), %eax
cmpl $0x1, %eax
adcl $0x0, %eax
movl %eax, %r14d
movslq %eax, %rbp
movq %rsi, 0x88(%rsp)
movsbl (%rsi,%rbp), %esi
incq %rbp
movl $0xc, %edx
leaq 0x355a(%rip), %rdi      # 0x60d8
movq %rsi, 0x70(%rsp)
callq 0x21a0
testq %rax, %rax
je 0x2cf5
cmpb $0x3a, 0x1(%rax)
movq 0x40(%rsp), %r9
movq 0x68(%rsp), %rcx
jne 0x2d15
movq 0x88(%rsp), %rdi
cmpb $0x0, (%rdi,%rbp)
movq 0x18(%rsp), %r10
movq 0x38(%rsp), %r8
je 0x2daa
addq %rbp, %rdi
jmp 0x2d27
movb 0x2(%rsi), %dil
testb %dil, %dil
je 0x39f9
movq %r13, 0x90(%rsp)
leaq 0x2(%rsi), %r13
addq $0x3, %rsi
xorl %edx, %edx
testb %dil, %dil
je 0x2c0b
movzbl %dil, %eax
cmpl $0x3d, %eax
je 0x2c0b
movb (%rsi), %dil
incq %rsi
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rdx
jmp 0x2be8
movb %dil, 0x27(%rsp)
movq %rsi, 0x88(%rsp)
sarq $0x20, %rdx
xorl %r12d, %r12d
leaq 0x615a(%rip), %rbp      # 0x8d80
leaq 0x3a17(%rip), %rsi      # 0x6644
xorl %r14d, %r14d
movq %rdx, 0x30(%rsp)
movq %r13, %rdi
callq 0x20a0
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
cmoveq %rbp, %r12
addl %ecx, %r14d
movq 0x30(%rsp), %rdx
movq 0x10(%rbp), %rsi
addq $0x10, %rbp
testq %rsi, %rsi
jne 0x2c35
cmpl $0x1, %r14d
jne 0x2cb5
movl 0xc(%r12), %eax
movq %rax, 0x70(%rsp)
movb 0x27(%rsp), %al
cmpb $0x3d, %al
movq 0x40(%rsp), %r9
movl 0x14(%rsp), %r11d
movq 0x50(%rsp), %r14
movq 0x18(%rsp), %r10
movq 0x38(%rsp), %r8
movq 0x68(%rsp), %rcx
movq 0x90(%rsp), %r13
jne 0x2d65
movq (%rsp), %rsi
movq 0x28(%rsp), %r12
movq 0x88(%rsp), %rdi
jmp 0x2dec
movl $0x3f, %eax
movq %rax, 0x70(%rsp)
xorl %edi, %edi
movq 0x40(%rsp), %r9
movl 0x14(%rsp), %r11d
movq 0x50(%rsp), %r14
movq (%rsp), %rsi
movq 0x18(%rsp), %r10
movq 0x28(%rsp), %r12
movq 0x38(%rsp), %r8
movq 0x68(%rsp), %rcx
movq 0x90(%rsp), %r13
jmp 0x2dec
movl $0x3f, %eax
movq %rax, 0x70(%rsp)
movq 0x40(%rsp), %r9
movq 0x18(%rsp), %r10
movq 0x38(%rsp), %r8
movq 0x68(%rsp), %rcx
jmp 0x2d1f
movq 0x18(%rsp), %r10
movq 0x38(%rsp), %r8
cmpl $-0x2, %r14d
jg 0x2d36
xorl %edi, %edi
movl 0x14(%rsp), %r11d
movq 0x50(%rsp), %r14
jmp 0x2de3
movq (%r9,%r12), %rax
movl %ebp, %ecx
cmpb $0x0, (%rax,%rcx)
je 0x2d8e
movl %ebp, 0x30(%rsp)
movq 0x68(%rsp), %rdx
xorl %edi, %edi
movl 0x14(%rsp), %r11d
movq 0x50(%rsp), %r14
movq (%rsp), %rsi
movq 0x28(%rsp), %r12
jmp 0x2e5d
testb %al, %al
jne 0x2de1
cmpl $0x1, 0x8(%r12)
jne 0x2de1
cmpl %ecx, 0x84(%rsp)
jle 0x2dd7
movq 0x8(%rsp), %rax
leal (%rax,%r13), %ecx
incl %ecx
movslq %ecx, %rax
movq (%r9,%rax,8), %rdi
jmp 0x2de3
xorl %edi, %edi
movl 0x14(%rsp), %r11d
movq 0x50(%rsp), %r14
movq (%rsp), %rsi
movq 0x28(%rsp), %r12
movq 0x68(%rsp), %rcx
jmp 0x2dec
cmpl %ecx, 0x84(%rsp)
movq (%rsp), %rsi
movq 0x28(%rsp), %r12
jle 0x2f8b
movq 0x8(%rsp), %rax
leal (%rax,%r13), %ecx
incl %ecx
movslq %ecx, %rax
movq (%r9,%rax,8), %rdi
jmp 0x2f97
movl $0x3a, %eax
movq %rax, 0x70(%rsp)
xorl %edi, %edi
movq (%rsp), %rsi
movq 0x28(%rsp), %r12
leal 0x1(%rcx), %edx
movl $0x0, 0x30(%rsp)
testl %r8d, %r8d
jle 0x2e5d
movq %rdi, %rbp
movq %rdx, 0x8(%rsp)
movq 0x48(%rsp), %rsi
addq %r13, %rsi
movl %r8d, %eax
movslq %ecx, %rcx
movl %r15d, %edx
movq %rsi, %r15
negq %rdx
movq (%r9,%r15,8), %rsi
xorl %edi, %edi
movq -0x8(%rbx,%rdi,8), %r8
movq %r8, (%rbx,%rdi,8)
decq %rdi
cmpq %rdi, %rdx
jne 0x2e21
movq %r15, %rdi
subq %rax, %rdi
movq %rsi, (%r9,%rdi,8)
leaq 0x1(%r15), %rsi
addq $0x8, %rbx
cmpq %rcx, %r15
movq %rsi, %r15
jl 0x2e1b
movq 0x8(%rsp), %rdx
movq (%rsp), %rsi
movq 0x38(%rsp), %r8
movq %rbp, %rdi
movq 0x70(%rsp), %r15
testl %r15d, %r15d
movq 0x78(%rsp), %rbx
js 0x39cc
cmpl $0x67, %r15d
jle 0x2f60
addl $-0x68, %r15d
cmpl $0xe, %r15d
ja 0x2f7e
leaq 0x3181(%rip), %rcx      # 0x6010
movslq (%rcx,%r15,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x6131(%rip), %rax      # 0x8fd0
movq (%rax), %r14
jmp 0x2f7e
cmpb $0x2d, (%rdi)
jne 0x2eb6
cmpb $0x0, 0x1(%rdi)
je 0x2f7e
movq 0x6113(%rip), %rax      # 0x8fd0
movq %rdx, 0x8(%rsp)
movq (%rax), %rdx
movq %rdi, %rbp
leaq 0x3215(%rip), %rsi      # 0x60e4
movl %r11d, %r15d
callq 0x2160
movq 0x38(%rsp), %r8
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movl %r15d, %r11d
movq 0x18(%rsp), %r10
movq 0x40(%rsp), %r9
testq %rax, %rax
jne 0x2f7e
jmp 0x3ab5
movq %rdi, %r10
jmp 0x2f7e
movl $0x1, %esi
jmp 0x2f7e
movq %rdx, 0x8(%rsp)
movq %rsi, %r15
callq 0x2340
movq 0x38(%rsp), %r8
movq %r15, %rsi
movq 0x8(%rsp), %rdx
movq 0x18(%rsp), %r10
movq 0x40(%rsp), %r9
movl %eax, %r11d
jmp 0x2f7e
movq %rdx, %r15
callq 0x2340
movq 0x38(%rsp), %r8
movq (%rsp), %rsi
movq %r15, %rdx
movl 0x14(%rsp), %r11d
movq 0x18(%rsp), %r10
movq 0x40(%rsp), %r9
movl %eax, 0x62be(%rip)      # 0x921c
jmp 0x2f7e
cmpl $0x56, %r15d
je 0x3a5b
cmpl $0x3a, %r15d
je 0x3a6e
cmpl $0x3f, %r15d
je 0x3a89
cmpl %ebx, %edx
jl 0x2a96
jmp 0x39d7
movl $0x3a, %eax
movq %rax, 0x70(%rsp)
xorl %edi, %edi
movl 0x14(%rsp), %r11d
movq 0x50(%rsp), %r14
jmp 0x2dec
movl $0x1, %eax
movl $0x3c, %r11d
xorl %r10d, %r10d
xorl %esi, %esi
xorl %ecx, %ecx
movq 0x40(%rsp), %r9
jmp 0x2fd4
movq 0x78(%rsp), %rbx
movl %ebx, %eax
movq (%rsp), %rsi
movq %rbp, %r10
movq 0x601c(%rip), %r15      # 0x8ff0
subl %ecx, %eax
movq 0x5ff3(%rip), %r13      # 0x8fd0
cmpl %eax, %ebx
je 0x303c
cmpq (%r13), %r14
je 0x303c
movl %ebx, %ecx
subl %eax, %ecx
jle 0x3950
movq %rsi, %r12
cltq
cmpl $0x3, %ecx
movq %r10, 0x18(%rsp)
movq %rax, 0x28(%rsp)
jb 0x3140
movl %r11d, %ebp
movq 0x8(%r9,%rax,8), %r14
movq 0x10(%r9,%rax,8), %rdi
callq 0x21d0
movq %rax, %rbx
testl %ebx, %ebx
jle 0x3b0c
movq 0x18(%rsp), %rcx
testq %rcx, %rcx
jne 0x396f
movl %ebp, %r11d
jmp 0x3151
movl $0xa, %edi
movq %r14, %rsi
movl %r11d, %ebx
callq 0x2190
leaq 0x3119(%rip), %rdi      # 0x616c
movl $0x33, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2380
leaq 0x3134(%rip), %rdi      # 0x61a0
movl $0x9, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2380
leaq 0x3125(%rip), %rdi      # 0x61aa
movl $0x31, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2380
leaq 0x313e(%rip), %rdi      # 0x61dc
movl $0x42, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2380
leaq 0x3168(%rip), %rsi      # 0x621f
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2200
leaq 0x3197(%rip), %rdi      # 0x6261
movl $0x32, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2380
movl 0x613a(%rip), %edx      # 0x921c
leaq 0x31ab(%rip), %rsi      # 0x6294
movq %r14, %rdi
xorl %eax, %eax
callq 0x2200
leaq 0x31c0(%rip), %rdi      # 0x62ba
movl $0x26, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2380
movl $0xa, %edi
movq %r14, %rsi
callq 0x2190
leaq 0x31c1(%rip), %rdi      # 0x62e1
movl $0x23, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2380
xorl %ebx, %ebx
cmpq (%r13), %r14
setne %bl
jmp 0x393c
xorl %r14d, %r14d
movl $0x0, %ebx
testq %r10, %r10
je 0x3963
testl %r11d, %r11d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmovnel %r11d, %eax
movl %eax, 0x58(%rsp)
movl $0x1, %esi
movl $0x20, %edx
xorl %edi, %edi
callq 0x4c04
movq $0x0, 0x18(%rax)
testq %r14, %r14
movq %rax, 0x8(%rsp)
je 0x31b8
movq %rax, %r15
movq %r14, %rdi
callq 0x23b0
leaq 0x64(%rsp), %rdx
movq %r15, %rdi
movq %rax, %rsi
callq 0x3b1b
addl %ebx, %ebx
orl %r12d, %ebx
movq 0x10(%r15), %rcx
movl %eax, %eax
shlq $0x4, %rax
movq %rbx, 0x8(%rcx,%rax)
jmp 0x3570
testl %r12d, %r12d
jne 0x39b1
leaq 0x325d(%rip), %rsi      # 0x6425
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x22b0
testq %rax, %rax
je 0x3b13
movq %rax, %r14
movl $0x1, %edi
movl $0x20, %esi
callq 0x21c0
movq %rax, %r13
movq %r14, 0x38(%rsp)
movq %r14, 0x10(%rax)
movl $0x10000, 0x8(%rax)     # imm = 0x10000
movl $0x4000, %edi           # imm = 0x4000
callq 0x2260
movq %rax, 0x18(%r13)
xorl %eax, %eax
xorl %ecx, %ecx
xorl %ebx, %ebx
xorl %r14d, %r14d
movq $0x0, 0x48(%rsp)
cmpl %eax, %ecx
jl 0x3232
testb $0x3, 0x8(%r13)
jne 0x3549
xorl %r15d, %r15d
cmpl %eax, %ecx
jl 0x3284
movq %r14, %r12
movl 0x8(%r13), %r14d
testb $0x3, %r14b
jne 0x3346
movl $0x0, (%r13)
movq 0x10(%r13), %rdi
movq 0x18(%r13), %rsi
movl %r14d, %ebp
sarl $0x2, %ebp
movl %ebp, %edx
callq 0x21f0
movl %eax, 0x4(%r13)
cmpl %ebp, %eax
jge 0x3277
orl $0x1, %r14d
movl %r14d, 0x8(%r13)
testl %eax, %eax
movq %r12, %r14
je 0x3349
xorl %ecx, %ecx
movl %ecx, %r12d
cmpl %eax, %ecx
jge 0x32a8
movslq %ecx, %rdx
addq 0x18(%r13), %rdx
movl %ecx, %r12d
cmpb $0xa, (%rdx)
je 0x32a8
incl %r12d
incq %rdx
cmpl %r12d, %eax
jne 0x3295
movl %eax, %r12d
movq %rbx, %rdx
subq %r15, %rdx
movl %r12d, %eax
subl %ecx, %eax
leal 0x1(%rax), %esi
movslq %esi, %rsi
cmpq %rsi, %rdx
jae 0x330e
cltq
addq %r15, %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rbx
shrq $0x10, %rbx
orq %rax, %rbx
incq %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x22a0
movq %rax, %r14
movl (%r13), %ecx
movl %r12d, %eax
subl %ecx, %eax
leaq (%r14,%r15), %rdi
movslq %ecx, %rsi
addq 0x18(%r13), %rsi
movslq %eax, %rdx
callq 0x2230
movslq (%r13), %rax
movslq %r12d, %rcx
subq %rax, %rcx
addq %rcx, %r15
leal 0x1(%r12), %ecx
movl %ecx, (%r13)
movl 0x4(%r13), %eax
cmpl %eax, %r12d
jge 0x3235
jmp 0x3349
movq %r12, %r14
testq %r14, %r14
je 0x3364
cmpq $0x2, %r15
jb 0x337b
xorl %eax, %eax
cmpb $0xd, -0x1(%r14,%r15)
sete %al
subq %rax, %r15
jmp 0x337b
movl $0x1, %ebx
movl $0x1, %edi
movl $0x1, %esi
callq 0x21c0
movq %rax, %r14
movb $0x0, (%r14,%r15)
testl %r15d, %r15d
js 0x3549
callq 0x23e0
movq (%rax), %r8
leaq -0x1(%r14), %r12
leaq 0x1(%r14), %rsi
movq %r12, %rdx
movq %rsi, %rcx
incq %r12
movsbq 0x1(%rdx), %rsi
testq %rsi, %rsi
je 0x33c0
movzwl (%r8,%rsi,2), %edi
andl $0x2000, %edi           # imm = 0x2000
leaq 0x1(%rcx), %rsi
testw %di, %di
jne 0x3399
movq $-0x1, %r15
movq %rdx, %rbp
movsbq -0x1(%rcx), %rdx
incq %r15
testq %rdx, %rdx
je 0x33ee
movzwl (%r8,%rdx,2), %esi
andl $0x2000, %esi           # imm = 0x2000
incq %rcx
leaq 0x1(%rbp), %rdx
testw %si, %si
je 0x33c7
incq 0x48(%rsp)
testq %r15, %r15
je 0x353c
movq %r14, (%rsp)
leaq 0x1(%r15), %rdi
movq %rax, 0x30(%rsp)
callq 0x2260
movq %rax, %r14
movq %rax, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x2230
movq %r14, 0x18(%rsp)
movb $0x0, (%r14,%r15)
movq 0x30(%rsp), %rax
movq (%rax), %r15
movq %rbp, %rax
incq %rbp
movsbq 0x1(%rax), %rcx
testq %rcx, %rcx
je 0x344e
movzwl (%r15,%rcx,2), %ecx
andl $0x2000, %ecx           # imm = 0x2000
jne 0x3431
movl $0x1, %r14d
movq %rax, %r12
movsbq 0x1(%rax), %rcx
decq %r14
testq %rcx, %rcx
je 0x3476
leaq 0x1(%r12), %rax
movzwl (%r15,%rcx,2), %ecx
andl $0x2000, %ecx           # imm = 0x2000
je 0x3454
movq %rbp, %rdi
callq 0x21d0
testq %r14, %r14
je 0x3acd
movq %rax, %rbp
testq %rax, %rax
jle 0x3adb
movsbq 0x1(%r12), %rax
incq %r12
testq %rax, %rax
je 0x34ae
movzwl (%r15,%rax,2), %ecx
andl $0x2000, %ecx           # imm = 0x2000
jne 0x3493
movzbl %al, %eax
movl $0x1, %ecx
movsbq (%r12), %rdx
decq %rcx
testq %rdx, %rdx
je 0x34d6
movzwl (%r15,%rdx,2), %edx
andl $0x2000, %edx           # imm = 0x2000
incq %r12
testw %dx, %dx
je 0x34b6
addq %rbp, %rbp
testq %rcx, %rcx
je 0x34fc
cmpl $0x2b, %eax
movq 0x8(%rsp), %r14
movq 0x18(%rsp), %r15
je 0x3506
cmpl $0x2d, %eax
jne 0x3af4
orq $0x1, %rbp
jmp 0x3506
movq 0x8(%rsp), %r14
movq 0x18(%rsp), %r15
movl $0x1, 0x64(%rsp)
movq %r14, %rdi
movq %r15, %rsi
leaq 0x64(%rsp), %rdx
callq 0x3b1b
cmpl $0x0, 0x64(%rsp)
je 0x3ae3
movq 0x10(%r14), %rcx
movl %eax, %eax
shlq $0x4, %rax
movq %rbp, 0x8(%rcx,%rax)
movq (%rsp), %r14
movl (%r13), %ecx
movl 0x4(%r13), %eax
jmp 0x3223
movq 0x18(%r13), %rdi
callq 0x2060
movq %r13, %rdi
callq 0x2060
movq 0x38(%rsp), %rdi
callq 0x2050
movq 0x5a65(%rip), %r13      # 0x8fd0
movq 0x8(%rsp), %r15
movq 0x40(%rsp), %rax
movq 0x28(%rsp), %rcx
leaq (%rax,%rcx,8), %rdi
movl $0x1, %esi
callq 0x3fe3
testq %rax, %rax
je 0x3b02
movq %rax, %r12
movq %rax, %rdi
callq 0x40c1
testl %eax, %eax
js 0x38ab
movq %r12, 0x48(%rsp)
movl %eax, (%rsp)
movq 0x18(%r12), %rax
movq 0x8(%rax), %rax
movq 0x10(%rax), %rbp
movq 0x40(%rax), %rax
movq %rax, 0x18(%rsp)
movq %r15, %r14
movq 0x10(%r15), %r15
movl $0x0, %eax
movq %rax, 0x30(%rsp)
testq %r15, %r15
je 0x367e
movl (%r14), %ecx
movl $0x1, %r8d
shll %cl, %r8d
movsbl (%rbp), %eax
testl %eax, %eax
je 0x3612
movb 0x1(%rbp), %dl
testb %dl, %dl
je 0x3614
leaq 0x2(%rbp), %rsi
movl %eax, %edi
shll $0x5, %edi
subl %eax, %edi
movsbl %dl, %eax
addl %edi, %eax
movb (%rsi), %dl
incq %rsi
testb %dl, %dl
jne 0x35fb
jmp 0x3614
xorl %eax, %eax
imull $0x9e3779b9, %eax, %r12d # imm = 0x9E3779B9
negb %cl
shrl %cl, %r12d
movq %r8, 0x30(%rsp)
leal -0x1(%r8), %r14d
movq 0x8(%rsp), %rax
movq 0x8(%rax), %r13
movl %r12d, %ebx
movl %ebx, %eax
shrl $0x5, %eax
movl (%r13,%rax,4), %eax
btl %ebx, %eax
jae 0x366d
movl %ebx, %eax
shlq $0x4, %rax
movq (%r15,%rax), %rdi
movq %rbp, %rsi
callq 0x21e0
testl %eax, %eax
je 0x3666
incl %ebx
andl %r14d, %ebx
cmpl %r12d, %ebx
jne 0x3635
jmp 0x366d
movl %ebx, %eax
movq %rax, 0x30(%rsp)
movq 0x595c(%rip), %r13      # 0x8fd0
movq 0x8(%rsp), %r14
movq 0x48(%rsp), %r12
movq (%r13), %rdi
xorl %ebx, %ebx
leaq 0x2eb5(%rip), %rsi      # 0x6540
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2200
movq 0x10(%r14), %rax
testq %rax, %rax
movq %r14, %r15
je 0x36ab
movb (%r15), %cl
movl $0x1, %ebx
shll %cl, %ebx
movq 0x30(%rsp), %rcx
cmpl %ebx, %ecx
movl (%rsp), %r14d
jne 0x36d7
movq (%r13), %r9
movq 0x18(%rsp), %rdi
movl %r14d, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl 0x58(%rsp), %r8d
callq 0x3ea9
jmp 0x3881
movl %ecx, %ebx
shlq $0x4, %rbx
movq 0x8(%rax,%rbx), %rax
movq %rax, %r15
shrq %r15
movl %r14d, %ebp
subl %r15d, %ebp
jl 0x3ac2
testb $0x1, %al
jne 0x3739
movslq %r15d, %rax
leal -0x1(%r15), %ebp
movq 0x18(%rsp), %r12
leaq (%rax,%r12), %rdi
decq %rdi
movl %r14d, %r15d
subl %ebp, %r15d
movq (%r13), %r9
movl %r15d, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl 0x58(%rsp), %r14d
movl %r14d, %r8d
callq 0x3ea9
movq (%r13), %r9
movq %r12, %rdi
movl %ebp, %esi
xorl %edx, %edx
movl %r15d, %ecx
jmp 0x3776
movq (%r13), %r9
movq %r13, %r12
movq 0x18(%rsp), %r13
movq %r13, %rdi
movl %r15d, %esi
movl $0x1, %edx
xorl %ecx, %ecx
movl 0x58(%rsp), %r14d
movl %r14d, %r8d
callq 0x3ea9
movslq %r15d, %rdi
addq %r13, %rdi
movq %r12, %r13
movq (%r12), %r9
movl %ebp, %esi
movl $0x1, %edx
movl %r15d, %ecx
movl %r14d, %r8d
callq 0x3ea9
movq 0x8(%rsp), %r15
movq 0x10(%r15), %rax
movq (%rax,%rbx), %rdi
callq 0x2060
cmpq $0x0, 0x10(%r15)
movl (%rsp), %r14d
movq 0x48(%rsp), %r12
je 0x3881
movb (%r15), %cl
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
shll %cl, %eax
notl %eax
movq 0x30(%rsp), %r11
leal 0x1(%r11), %edx
andl %eax, %edx
cmpl %r11d, %edx
je 0x3867
movq 0x8(%r15), %rcx
movl %edx, %esi
shrl $0x5, %esi
movl (%rcx,%rsi,4), %ecx
btl %edx, %ecx
jae 0x3867
movq 0x10(%r15), %rsi
movl %edx, %edi
shlq $0x4, %rdi
movq (%rsi,%rdi), %r8
movsbl (%r8), %ecx
testl %ecx, %ecx
je 0x381a
movb 0x1(%r8), %r9b
testb %r9b, %r9b
je 0x381c
addq $0x2, %r8
movl %ecx, %r10d
shll $0x5, %r10d
subl %ecx, %r10d
movsbl %r9b, %ecx
addl %r10d, %ecx
movb (%r8), %r9b
incq %r8
testb %r9b, %r9b
jne 0x37fc
jmp 0x381c
xorl %ecx, %ecx
imull $0x9e3779b9, %ecx, %r8d # imm = 0x9E3779B9
movb (%r15), %r9b
xorl %ecx, %ecx
subb %r9b, %cl
shrl %cl, %r8d
cmpl %r11d, %edx
jbe 0x383d
cmpl %r11d, %r8d
jbe 0x384c
cmpl %edx, %r8d
ja 0x384c
cmpl %r11d, %edx
jae 0x3860
cmpl %r11d, %r8d
ja 0x3860
cmpl %edx, %r8d
jbe 0x3860
addq %rsi, %rdi
movl %r11d, %ecx
shlq $0x4, %rcx
movups (%rdi), %xmm0
movups %xmm0, (%rsi,%rcx)
movl %edx, %r11d
incl %edx
jmp 0x37b9
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
movl %r11d, %ecx
roll %cl, %eax
movq 0x8(%r15), %rcx
shrl $0x5, %r11d
andl %eax, (%rcx,%r11,4)
decl 0x4(%r15)
movl %r14d, %eax
cltd
idivl 0x58(%rsp)
testl %edx, %edx
je 0x389b
movq (%r13), %rsi
movl $0xa, %edi
callq 0x2190
movq %r12, %rdi
callq 0x40c1
testl %eax, %eax
jns 0x35a9
movq %r12, %rdi
callq 0x3f58
xorl %ebx, %ebx
movq 0x10(%r15), %rsi
testq %rsi, %rsi
je 0x38cb
movb (%r15), %cl
movl $0x1, %eax
shlq %cl, %rax
jmp 0x38cd
xorl %eax, %eax
cmpq %rax, %rbx
jae 0x38f7
movq 0x8(%r15), %rax
movq %rbx, %rcx
shrq $0x5, %rcx
movl (%rax,%rcx,4), %eax
btl %ebx, %eax
jb 0x38ea
incq %rbx
jmp 0x38b5
movq %rsi, %rdi
movq %rbx, %rsi
callq 0x25dc
jmp 0x38e5
movq 0x18(%r15), %rbx
movq %rbx, %rdi
callq 0x4c9f
movq 0x8(%r15), %rsi
movq %rbx, %rdi
callq 0x4c9f
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4c9f
movq (%r13), %rdi
callq 0x2270
cmpl $-0x1, %eax
je 0x3b07
xorl %ebx, %ebx
cmpl $0x0, 0x58e7(%rip)      # 0x921c
movq 0x40(%rsp), %rsi
jns 0x3957
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x27a9
jmp 0x3968
movq 0x78(%rsp), %rdi
callq 0x24c6
jmp 0x393c
callq 0x245b
movl $0x1, %ebx
jmp 0x393c
movq (%r15), %rdi
leaq 0x29f6(%rip), %rsi      # 0x636f
movq %r12, (%rsp)
leaq 0x27c5(%rip), %r12      # 0x6149
movq %r12, %rdx
xorl %eax, %eax
callq 0x2200
movq (%r15), %rdi
leaq 0x29f7(%rip), %rsi      # 0x638f
movq %r12, %rdx
movq (%rsp), %r12
movq %r14, %rcx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x2200
jmp 0x3034
callq 0x247a
jmp 0x31c1
movl %r10d, %eax
movq 0x78(%rsp), %rbx
movq (%rsp), %rsi
movq %rbp, %r10
jmp 0x39ec
subl 0x58(%rsp), %edx
subl %r13d, %edx
movl %edx, %eax
jmp 0x3a4f
movl %edx, %eax
jmp 0x39ec
movq 0x8(%rsp), %rax
addl %r13d, %eax
movq 0x78(%rsp), %rbx
movq (%rsp), %rsi
movq 0x58(%rsp), %rcx
addl %r13d, %ecx
jmp 0x2fcd
movq %rsi, %rbx
addq %r13, %rcx
addq %r13, %rax
testl %ecx, %ecx
movq (%rsp), %r12
jle 0x3a29
movl %ecx, %edx
negq %rdx
movslq %eax, %rsi
leaq (%r9,%rsi,8), %rsi
xorl %edi, %edi
movq -0x8(%rsi,%rdi,8), %r8
movq %r8, (%rsi,%rdi,8)
decq %rdi
cmpq %rdi, %rdx
jne 0x3a18
xorl %edx, %edx
testl %r15d, %r15d
cmovgl %r15d, %edx
movq 0x8(%rsp), %rsi
subl %edx, %esi
addl %esi, %r13d
movslq %r13d, %rdx
movq %rbx, (%r9,%rdx,8)
subl %ecx, %eax
incl %eax
movq 0x78(%rsp), %rbx
movq %r12, %rsi
movq 0x559a(%rip), %r15      # 0x8ff0
jmp 0x2fd6
leaq 0x26c5(%rip), %rdi      # 0x6127
callq 0x20b0
xorl %ebx, %ebx
jmp 0x393c
movq 0x557b(%rip), %rax      # 0x8ff0
movq (%rax), %rdi
movslq %edx, %rax
movq -0x8(%r9,%rax,8), %rcx
leaq 0x26c7(%rip), %rsi      # 0x614e
jmp 0x3aa2
movq 0x5560(%rip), %rax      # 0x8ff0
movq (%rax), %rdi
movslq %edx, %rax
movq -0x8(%r9,%rax,8), %rcx
leaq 0x2689(%rip), %rsi      # 0x612b
leaq 0x26a0(%rip), %rdx      # 0x6149
xorl %eax, %eax
callq 0x2200
jmp 0x3968
movq %rbp, %rdi
callq 0x2420
jmp 0x3968
movl %r15d, %edi
movl %r14d, %esi
callq 0x2499
movq 0x48(%rsp), %rdi
movq (%rsp), %rsi
callq 0x270c
movq %rbp, %rdi
callq 0x26e1
movq 0x48(%rsp), %rdi
movq (%rsp), %rsi
movq %r15, %rdx
callq 0x2692
movq 0x48(%rsp), %rdi
movq (%rsp), %rsi
callq 0x264a
callq 0x2610
callq 0x25b4
movl %ebx, %edi
callq 0x277f
movq %rbx, %rdi
callq 0x2754