// File: /workspace/github_c_makefile_star2_O1/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 $0x88, %rsp
movq %rsi, %r15
movl %edi, %ebx
callq 0x4693
movq %rbx, %r11
movq 0x659f(%rip), %rax      # 0x8ff0
movq (%rax), %rax
movq %rax, 0x50(%rsp)
movslq %r11d, %rbx
leal -0x1(%rbx), %eax
movl %eax, 0x64(%rsp)
movl %ebx, %eax
negl %eax
movq %rax, 0x38(%rsp)
movl $0x3c, 0x58(%rsp)
movl $0x1, %r9d
xorl %r10d, %r10d
movq $0x0, 0x10(%rsp)
movq $0x0, 0x68(%rsp)
xorl %ecx, %ecx
movq %r15, 0x40(%rsp)
movq %r11, 0x30(%rsp)
movq %rbx, 0x20(%rsp)
movl %ecx, %r13d
cmpl %r11d, %r9d
setl %cl
jge 0x2af7
movslq %r9d, %rax
leal (%r10,%r11), %edx
subl %r9d, %edx
incq %rax
movq 0x38(%rsp), %rcx
leal (%rcx,%r9), %edi
movb $0x1, %cl
xorl %esi, %esi
movq -0x8(%r15,%rax,8), %r8
cmpb $0x2d, (%r8)
jne 0x2ad7
cmpb $0x0, 0x1(%r8)
jne 0x2af1
cmpq %rbx, %rax
setl %cl
decl %esi
incq %rax
cmpl %esi, %edi
jne 0x2ac5
movl %edx, %r10d
movl %r11d, %r9d
movl %r11d, %ebp
jmp 0x2afa
subl %esi, %r10d
subl %esi, %r9d
movl %r9d, %ebp
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testb $0x1, %cl
je 0x2d4e
movslq %ebp, %rbx
movq (%r15,%rbx,8), %r8
cmpb $0x2d, (%r8)
jne 0x2b71
movzbl 0x1(%r8), %ecx
testl %ecx, %ecx
je 0x2b71
cmpl $0x2d, %ecx
jne 0x2b7d
cmpb $0x0, 0x2(%r8)
je 0x2cc6
movq %rbx, 0x70(%rsp)
movq %rbp, 0x18(%rsp)
movq %r9, 0x78(%rsp)
leaq 0x2(%r8), %rbx
addq $0x3, %r8
xorl %ebp, %ebp
movabsq $0x100000000, %rax      # imm = 0x100000000
movzbl -0x1(%r8), %r12d
testl %r12d, %r12d
je 0x2c00
cmpl $0x3d, %r12d
je 0x2c00
addq %rax, %rbp
incq %r8
jmp 0x2b51
xorl %edi, %edi
movq 0x20(%rsp), %rbx
jmp 0x2d50
movq %rbp, 0x18(%rsp)
movq %r11, %r12
movq %r9, %rbp
movq %r10, %r14
movl %r13d, 0x28(%rsp)
movq 0x10(%rsp), %rax
cmpl $0x1, %eax
adcl $0x0, %eax
cltq
movq %r8, 0x8(%rsp)
movsbl (%r8,%rax), %r13d
incq %rax
movq %rax, 0x10(%rsp)
movl $0xc, %edx
leaq 0x351d(%rip), %rdi      # 0x60d8
movl %r13d, %esi
callq 0x21a0
testq %rax, %rax
je 0x2ce9
cmpb $0x3a, 0x1(%rax)
movq %r14, %r10
movq %rbp, %r9
movq %r12, %r11
jne 0x2d28
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rdi
cmpb $0x0, (%rdi,%rax)
movq 0x18(%rsp), %rsi
je 0x2e70
addq %rax, %rdi
jmp 0x2e86
movq %r8, 0x8(%rsp)
movq %r10, 0x80(%rsp)
movl %r13d, 0x28(%rsp)
sarq $0x20, %rbp
xorl %r13d, %r13d
leaq 0x6160(%rip), %r15      # 0x8d80
leaq 0x3a1f(%rip), %rsi      # 0x6646
xorl %r14d, %r14d
movq %rbx, %rdi
movq %rbp, %rdx
callq 0x20a0
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
cmoveq %r15, %r13
addl %ecx, %r14d
movq 0x10(%r15), %rsi
addq $0x10, %r15
testq %rsi, %rsi
jne 0x2c2a
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x10(%rsp)
cmpl $0x1, %r14d
jne 0x2cfb
movl 0xc(%r13), %ecx
cmpb $0x3d, %r12b
movl $0x0, %eax
movq 0x8(%rsp), %rdi
cmovneq %rax, %rdi
testb %r12b, %r12b
movq 0x40(%rsp), %r15
movq 0x80(%rsp), %r10
movq 0x78(%rsp), %r9
movq 0x18(%rsp), %rsi
movq 0x70(%rsp), %rbx
jne 0x2f33
cmpl $0x1, 0x8(%r13)
movq 0x30(%rsp), %r11
jne 0x2f2c
movl $0x3a, %eax
cmpl 0x64(%rsp), %esi
movl %ecx, %r13d
jl 0x2e7a
jmp 0x2e93
testl %r10d, %r10d
jle 0x2d37
movl %r10d, %edx
leaq (%r15,%rbx,8), %rsi
xorl %ecx, %ecx
movq -0x8(%rsi), %rdi
movq %rdi, (%rsi)
addq $-0x8, %rsi
incq %rcx
cmpq %rcx, %rdx
jne 0x2cd4
jmp 0x2d39
movl $0x3f, %eax
xorl %edi, %edi
movq %r14, %r10
movq %rbp, %r9
movq %r12, %r11
jmp 0x2d2d
movl $0x3f, %eax
xorl %edi, %edi
movq 0x40(%rsp), %r15
movq 0x30(%rsp), %r11
movq 0x80(%rsp), %r10
movq 0x78(%rsp), %r9
movq 0x18(%rsp), %rsi
movq 0x70(%rsp), %rbx
jmp 0x2e93
xorl %edi, %edi
movl %r13d, %eax
movq 0x18(%rsp), %rsi
jmp 0x2e93
xorl %ecx, %ecx
movq 0x20(%rsp), %rbx
movl %ebp, %edx
subl %ecx, %edx
movslq %edx, %rcx
movq %r8, (%r15,%rcx,8)
incl %ebp
movl %ebp, %r9d
xorl %edi, %edi
testl %eax, %eax
js 0x2f55
cmpl $0x67, %eax
jle 0x2e4d
addl $-0x68, %eax
movl %r13d, %ecx
cmpl $0xe, %eax
ja 0x2aa0
movl %r13d, %r14d
movl $0x1, %ecx
leaq 0x3291(%rip), %rdx      # 0x6010
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
movq 0x6241(%rip), %rax      # 0x8fd0
movq (%rax), %rax
movq %rax, 0x50(%rsp)
jmp 0x2e45
leaq 0x3341(%rip), %rsi      # 0x60e4
movq %r10, %r13
movq %r9, %rbp
movq %rdi, 0x8(%rsp)
movq %r11, %r12
callq 0x21e0
movq %r12, %r11
movq 0x8(%rsp), %rdi
movq %rbp, %r9
movq %r13, %r10
movl %r14d, %ecx
testl %eax, %eax
je 0x2aa0
movq 0x61fa(%rip), %rax      # 0x8fd0
movq (%rax), %rdx
leaq 0x3306(%rip), %rsi      # 0x60e6
callq 0x2160
movq %r12, %r11
movq 0x8(%rsp), %rdi
movq %rbp, %r9
movq %r13, %r10
movl %r14d, %ecx
testq %rax, %rax
jne 0x2aa0
jmp 0x39c6
movq %r10, %r13
movq %r9, %rbp
movq %r11, %r12
callq 0x2340
movq %r12, %r11
movq %rbp, %r9
movq %r13, %r10
movl %eax, 0x63fb(%rip)      # 0x921c
jmp 0x2e45
movq %rdi, 0x68(%rsp)
jmp 0x2e45
movq %r10, %r13
movq %r9, %rbp
movq %r11, %r12
callq 0x2340
movq %r12, %r11
movq %rbp, %r9
movq %r13, %r10
movl %eax, 0x58(%rsp)
movl %r14d, %ecx
jmp 0x2aa0
cmpl $0x56, %eax
je 0x395a
cmpl $0x3a, %eax
je 0x3982
movl %r13d, %ecx
cmpl $0x3f, %eax
jne 0x2aa0
jmp 0x399d
cmpl 0x64(%rsp), %esi
jge 0x2f3f
leal 0x1(%rsi), %r9d
movslq %esi, %rax
movq 0x8(%r15,%rax,8), %rdi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x10(%rsp)
movl %r13d, %eax
movq 0x10(%rsp), %rdx
testl %edx, %edx
js 0x2eb8
movslq %r9d, %rcx
movq (%r15,%rcx,8), %rcx
movl %edx, %edx
cmpb $0x0, (%rcx,%rdx)
je 0x2eb8
movl %r9d, %ebp
movl 0x28(%rsp), %r13d
jmp 0x2b73
leal 0x1(%r9), %ecx
testl %r10d, %r10d
setle %dl
cmpl %r9d, %esi
setg %sil
movq $0x0, 0x10(%rsp)
orb %dl, %sil
movl 0x28(%rsp), %r13d
je 0x2ee6
movl %ecx, %r9d
movl %ecx, %ebp
jmp 0x2b73
movq %r11, %r12
movl %r10d, %edx
leaq (%r15,%rbx,8), %rsi
negq %rdx
movq (%r15,%rbx,8), %r11
xorl %r8d, %r8d
movq -0x8(%rsi,%r8,8), %r9
movq %r9, (%rsi,%r8,8)
decq %r8
cmpq %r8, %rdx
jne 0x2efa
movq %r11, (%rsi,%r8,8)
incq %rbx
addq $0x8, %rsi
cmpl %ebx, %ecx
jne 0x2ef3
movl %ecx, %r9d
movl %ecx, %ebp
movq 0x20(%rsp), %rbx
movq %r12, %r11
jmp 0x2d50
movl %ecx, %eax
jmp 0x2e93
movl %ecx, %eax
movq 0x30(%rsp), %r11
jmp 0x2e93
movl $0x3a, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, 0x10(%rsp)
xorl %edi, %edi
jmp 0x2e93
subl %r10d, %ebp
cmpl %ebp, %r11d
movq 0x50(%rsp), %r14
je 0x3001
movq 0x6063(%rip), %rax      # 0x8fd0
cmpq (%rax), %r14
je 0x3001
movl %r11d, %eax
subl %ebp, %eax
jle 0x396a
movl %r13d, %ebx
movslq %ebp, %rbp
cmpl $0x3, %eax
movq %rbp, 0x50(%rsp)
jl 0x310a
movq 0x8(%r15,%rbp,8), %r12
movq 0x10(%r15,%rbp,8), %rdi
callq 0x21d0
movq %rax, %r14
testl %r14d, %r14d
movq 0x68(%rsp), %rcx
jle 0x3a30
testq %rcx, %rcx
je 0x311f
movq 0x602b(%rip), %rbp      # 0x8ff0
movq (%rbp), %rdi
leaq 0x33a1(%rip), %rsi      # 0x6371
leaq 0x3174(%rip), %r13      # 0x614b
movq %r13, %rdx
xorl %eax, %eax
callq 0x2200
movq (%rbp), %rdi
leaq 0x33a5(%rip), %rsi      # 0x6391
movq %r13, %rdx
movq %r12, %rcx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x2200
jmp 0x311f
movl $0xa, %edi
movq %r14, %rsi
callq 0x2190
leaq 0x3159(%rip), %rdi      # 0x616e
movl $0x33, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2380
leaq 0x3174(%rip), %rdi      # 0x61a2
movl $0x9, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2380
leaq 0x3165(%rip), %rdi      # 0x61ac
movl $0x31, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2380
leaq 0x317e(%rip), %rdi      # 0x61de
movl $0x42, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2380
leaq 0x31a8(%rip), %rsi      # 0x6221
movq %r14, %rdi
movl 0x58(%rsp), %edx
xorl %eax, %eax
callq 0x2200
leaq 0x31d5(%rip), %rdi      # 0x6263
movl $0x32, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2380
movl 0x6176(%rip), %edx      # 0x921c
leaq 0x31e9(%rip), %rsi      # 0x6296
movq %r14, %rdi
xorl %eax, %eax
callq 0x2200
leaq 0x31fe(%rip), %rdi      # 0x62bc
movl $0x26, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2380
movl $0xa, %edi
movq %r14, %rsi
callq 0x2190
leaq 0x31ff(%rip), %rdi      # 0x62e3
movl $0x23, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2380
xorl %ebx, %ebx
movq 0x5ed1(%rip), %rax      # 0x8fd0
cmpq (%rax), %r14
setne %bl
jmp 0x39d0
xorl %r12d, %r12d
movl $0x0, %r14d
cmpq $0x0, 0x68(%rsp)
je 0x3971
movl 0x58(%rsp), %ecx
testl %ecx, %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmovnel %ecx, %eax
movl %eax, 0x20(%rsp)
movl $0x1, %esi
movl $0x20, %edx
xorl %edi, %edi
callq 0x4ae8
movq $0x0, 0x18(%rax)
testq %r12, %r12
movq %rax, 0x28(%rsp)
je 0x3195
movq %rax, %rbp
movq %r12, %rdi
callq 0x23b0
leaq 0x4c(%rsp), %rdx
movq %rbp, %rdi
movq %rax, %rsi
callq 0x3a40
addl %r14d, %r14d
orl %ebx, %r14d
movq 0x10(%rbp), %rcx
movl %eax, %eax
shlq $0x4, %rax
movq %r14, 0x8(%rcx,%rax)
movq 0x30(%rsp), %r12
movq 0x5e40(%rip), %r13      # 0x8fd0
jmp 0x3565
testl %ebx, %ebx
jne 0x3978
leaq 0x3283(%rip), %rsi      # 0x6427
movq 0x68(%rsp), %rbx
movq %rbx, %rdi
callq 0x22b0
testq %rax, %rax
movq 0x30(%rsp), %r12
je 0x3a38
movq %rax, %r14
movl $0x1, %edi
movl $0x20, %esi
callq 0x21c0
movq %rax, %r13
movq %r14, 0x58(%rsp)
movq %r14, 0x10(%rax)
movl 0x8(%rax), %eax
andl $0x3, %eax
orl $0x10000, %eax          # imm = 0x10000
movl %eax, 0x8(%r13)
movl $0x4000, %edi           # imm = 0x4000
callq 0x2260
movq %rax, 0x18(%r13)
xorl %ebp, %ebp
movq $0x0, 0x8(%rsp)
movq $0x0, 0x18(%rsp)
movl (%r13), %eax
cmpl 0x4(%r13), %eax
jl 0x322b
testb $0x3, 0x8(%r13)
je 0x322b
xorl %ecx, %ecx
movq 0x8(%rsp), %rax
jmp 0x3380
xorl %r14d, %r14d
movl (%r13), %eax
cmpl 0x4(%r13), %eax
jl 0x327b
movl 0x8(%r13), %r15d
testb $0x3, %r15b
jne 0x3341
movl $0x0, (%r13)
movq 0x10(%r13), %rdi
movq 0x18(%r13), %rsi
movl %r15d, %ebx
sarl $0x2, %ebx
movl %ebx, %edx
callq 0x21f0
movl %eax, 0x4(%r13)
cmpl %ebx, %eax
jge 0x3273
orl $0x1, %r15d
movl %r15d, 0x8(%r13)
testl %eax, %eax
je 0x3341
movl (%r13), %eax
movl 0x4(%r13), %ecx
movl %eax, %ebx
cmpl %ecx, %eax
jge 0x32a2
movslq %eax, %rdx
addq 0x18(%r13), %rdx
movl %eax, %ebx
cmpb $0xa, (%rdx)
je 0x32a2
incl %ebx
incq %rdx
cmpl %ebx, %ecx
jne 0x3292
movl %ecx, %ebx
movq %rbp, %rdx
subq %r14, %rdx
movl %ebx, %ecx
subl %eax, %ecx
leal 0x1(%rcx), %eax
cltq
cmpq %rax, %rdx
jae 0x32ff
movslq %ecx, %rax
addq %r14, %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, %rbp
shrq $0x10, %rbp
orq %rax, %rbp
incq %rbp
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x22a0
jmp 0x3304
movq 0x8(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq (%rax,%r14), %rdi
movslq (%r13), %rax
movq 0x18(%r13), %rsi
addq %rax, %rsi
movslq %ebx, %r15
movq %r15, %rdx
subq %rax, %rdx
callq 0x2230
movslq (%r13), %rax
subq %rax, %r15
addq %r15, %r14
leal 0x1(%rbx), %eax
movl %eax, (%r13)
cmpl 0x4(%r13), %ebx
jge 0x322e
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x3361
cmpq $0x2, %r14
jb 0x3375
xorl %ecx, %ecx
cmpb $0xd, -0x1(%rax,%r14)
sete %cl
subq %rcx, %r14
jmp 0x3375
movl $0x1, %ebp
movl $0x1, %edi
movl $0x1, %esi
callq 0x21c0
movb $0x0, (%rax,%r14)
testl %r14d, %r14d
setns %cl
testb %cl, %cl
je 0x3539
movq %rax, %rbx
callq 0x23e0
movq (%rax), %r8
leaq -0x1(%rbx), %r15
movq %rbx, 0x8(%rsp)
leaq 0x1(%rbx), %rsi
movq %r15, %rdx
movq %rsi, %rcx
incq %r15
movsbq 0x1(%rdx), %rsi
testq %rsi, %rsi
je 0x33c7
movzwl (%r8,%rsi,2), %edi
andl $0x2000, %edi           # imm = 0x2000
leaq 0x1(%rcx), %rsi
testw %di, %di
jne 0x33a0
movq $-0x1, %rbx
movq %rdx, %r14
movsbq -0x1(%rcx), %rdx
incq %rbx
testq %rdx, %rdx
je 0x33f5
movzwl (%r8,%rdx,2), %esi
andl $0x2000, %esi           # imm = 0x2000
incq %rcx
leaq 0x1(%r14), %rdx
testw %si, %si
je 0x33ce
incq 0x18(%rsp)
testq %rbx, %rbx
je 0x320e
leaq 0x1(%rbx), %rdi
movq %rax, 0x38(%rsp)
callq 0x2260
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2230
movq %r12, 0x10(%rsp)
movb $0x0, (%r12,%rbx)
movq 0x38(%rsp), %rax
movq (%rax), %rbx
movq %r14, %rax
incq %r14
movsbq 0x1(%rax), %rcx
testq %rcx, %rcx
je 0x3450
movzwl (%rbx,%rcx,2), %ecx
andl $0x2000, %ecx           # imm = 0x2000
jne 0x3434
movl $0x1, %r12d
movq %rax, %r15
movsbq 0x1(%rax), %rcx
decq %r12
testq %rcx, %rcx
je 0x3476
leaq 0x1(%r15), %rax
movzwl (%rbx,%rcx,2), %ecx
andl $0x2000, %ecx           # imm = 0x2000
je 0x3456
movq %r14, %rdi
callq 0x21d0
testq %r12, %r12
je 0x39ee
movq %rax, %r14
testq %rax, %rax
movq 0x30(%rsp), %r12
jle 0x39fd
movsbq 0x1(%r15), %rax
incq %r15
testq %rax, %rax
je 0x34b1
movzwl (%rbx,%rax,2), %ecx
andl $0x2000, %ecx           # imm = 0x2000
jne 0x3498
movzbl %al, %eax
movl $0x1, %ecx
movsbq (%r15), %rdx
decq %rcx
testq %rdx, %rdx
je 0x34d7
movzwl (%rbx,%rdx,2), %edx
andl $0x2000, %edx           # imm = 0x2000
incq %r15
testw %dx, %dx
je 0x34b9
addq %r14, %r14
testq %rcx, %rcx
je 0x34f8
cmpl $0x2b, %eax
movq 0x10(%rsp), %r15
je 0x34fd
cmpl $0x2d, %eax
jne 0x3a17
orq $0x1, %r14
jmp 0x34fd
movq 0x10(%rsp), %r15
movl $0x1, 0x4c(%rsp)
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
leaq 0x4c(%rsp), %rdx
callq 0x3a40
cmpl $0x0, 0x4c(%rsp)
je 0x3a05
movq 0x10(%rbx), %rcx
movl %eax, %eax
shlq $0x4, %rax
movq %r14, 0x8(%rcx,%rax)
jmp 0x320e
movq 0x18(%r13), %rdi
callq 0x2060
movq %r13, %rdi
callq 0x2060
movq 0x58(%rsp), %rdi
callq 0x2050
movq 0x5a75(%rip), %r13      # 0x8fd0
movq 0x40(%rsp), %r15
movq 0x28(%rsp), %rbp
movq 0x50(%rsp), %rax
leaq (%r15,%rax,8), %rdi
movl $0x1, %esi
callq 0x3ef7
testq %rax, %rax
je 0x3a26
movq %rax, %rbx
movq %rax, %rdi
callq 0x3fec
testl %eax, %eax
js 0x38ba
movl %eax, %r14d
movq %rbx, 0x18(%rsp)
movq 0x18(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x10(%rax), %r12
movq 0x40(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rbp), %rax
movl $0x0, %ebx
movq %rax, 0x8(%rsp)
testq %rax, %rax
movl %r14d, 0x38(%rsp)
je 0x3674
movl (%rbp), %ecx
movl $0x1, %ebx
shll %cl, %ebx
movsbl (%r12), %eax
testl %eax, %eax
je 0x3605
movb 0x1(%r12), %dl
testb %dl, %dl
je 0x3607
leaq 0x2(%r12), %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 0x35ee
jmp 0x3607
xorl %eax, %eax
imull $0x9e3779b9, %eax, %ebp # imm = 0x9E3779B9
negb %cl
shrl %cl, %ebp
leal -0x1(%rbx), %r14d
movq 0x28(%rsp), %rax
movq 0x8(%rax), %r13
movl %ebp, %r15d
movl %r15d, %eax
shrl $0x5, %eax
movl (%r13,%rax,4), %eax
btl %r15d, %eax
jae 0x365e
movl %r15d, %eax
shlq $0x4, %rax
movq 0x8(%rsp), %rcx
movq (%rcx,%rax), %rdi
movq %r12, %rsi
callq 0x21e0
testl %eax, %eax
je 0x365b
incl %r15d
andl %r14d, %r15d
cmpl %ebp, %r15d
jne 0x3621
jmp 0x365e
movl %r15d, %ebx
movq 0x596b(%rip), %r13      # 0x8fd0
movq 0x40(%rsp), %r15
movq 0x28(%rsp), %rbp
movl 0x38(%rsp), %r14d
movq %rbx, 0x8(%rsp)
movq (%r13), %rdi
xorl %ebx, %ebx
leaq 0x2ebc(%rip), %rsi      # 0x6542
movq %r12, %rdx
xorl %eax, %eax
callq 0x2200
movq 0x10(%rbp), %rax
testq %rax, %rax
je 0x36a3
movb (%rbp), %cl
movl $0x1, %ebx
shll %cl, %ebx
movq 0x8(%rsp), %rcx
cmpl %ebx, %ecx
jne 0x36d5
movq (%r13), %r9
movq 0x10(%rsp), %rdi
movl %r14d, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl 0x20(%rsp), %r8d
callq 0x3dbf
movq 0x30(%rsp), %r12
movq 0x18(%rsp), %rbx
jmp 0x388d
movl %ecx, %r12d
shlq $0x4, %r12
movq 0x8(%rax,%r12), %rax
movq %rax, %rbx
shrq %rbx
movl %r14d, %r15d
subl %ebx, %r15d
jl 0x39e4
testb $0x1, %al
jne 0x3740
movslq %ebx, %rax
leal -0x1(%rbx), %ecx
movl %ecx, 0x50(%rsp)
movq 0x10(%rsp), %rbx
leaq (%rax,%rbx), %rdi
decq %rdi
movl %r14d, %r15d
subl %ecx, %r15d
movq (%r13), %r9
movl %r15d, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl 0x20(%rsp), %r14d
movl %r14d, %r8d
callq 0x3dbf
movq (%r13), %r9
movq %rbx, %rdi
movl 0x50(%rsp), %esi
xorl %edx, %edx
movl %r15d, %ecx
movl %r14d, %r8d
jmp 0x3778
movq (%r13), %r9
movq 0x10(%rsp), %r14
movq %r14, %rdi
movl %ebx, %esi
movl $0x1, %edx
xorl %ecx, %ecx
movl 0x20(%rsp), %r8d
callq 0x3dbf
movslq %ebx, %rdi
addq %r14, %rdi
movq (%r13), %r9
movl %r15d, %esi
movl $0x1, %edx
movl %ebx, %ecx
movl 0x20(%rsp), %r8d
callq 0x3dbf
movq 0x10(%rbp), %rax
movq (%rax,%r12), %rdi
callq 0x2060
cmpq $0x0, 0x10(%rbp)
movq 0x40(%rsp), %r15
movq 0x30(%rsp), %r12
movq 0x5830(%rip), %r13      # 0x8fd0
movq 0x18(%rsp), %rbx
movl 0x38(%rsp), %r14d
je 0x388d
movb (%rbp), %cl
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
shll %cl, %eax
notl %eax
movq 0x8(%rsp), %r11
leal 0x1(%r11), %edx
andl %eax, %edx
cmpl %r11d, %edx
je 0x3874
movq 0x8(%rbp), %rcx
movl %edx, %esi
shrl $0x5, %esi
movl (%rcx,%rsi,4), %ecx
btl %edx, %ecx
jae 0x3874
movq 0x10(%rbp), %rsi
movl %edx, %edi
shlq $0x4, %rdi
movq (%rsi,%rdi), %r8
movsbl (%r8), %ecx
testl %ecx, %ecx
je 0x3826
movb 0x1(%r8), %r9b
testb %r9b, %r9b
je 0x3828
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 0x3808
jmp 0x3828
xorl %ecx, %ecx
imull $0x9e3779b9, %ecx, %r8d # imm = 0x9E3779B9
movb (%rbp), %r9b
xorl %ecx, %ecx
subb %r9b, %cl
shrl %cl, %r8d
cmpl %r11d, %edx
jbe 0x384a
cmpl %r11d, %r8d
jbe 0x3859
cmpl %edx, %r8d
ja 0x3859
cmpl %r11d, %edx
jae 0x386d
cmpl %r11d, %r8d
ja 0x386d
cmpl %edx, %r8d
jbe 0x386d
addq %rsi, %rdi
movl %r11d, %ecx
shlq $0x4, %rcx
movups (%rdi), %xmm0
movups %xmm0, (%rsi,%rcx)
movl %edx, %r11d
incl %edx
jmp 0x37c5
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
movl %r11d, %ecx
roll %cl, %eax
movq 0x8(%rbp), %rcx
shrl $0x5, %r11d
andl %eax, (%rcx,%r11,4)
decl 0x4(%rbp)
movl %r14d, %eax
cltd
idivl 0x20(%rsp)
testl %edx, %edx
je 0x38a7
movq (%r13), %rsi
movl $0xa, %edi
callq 0x2190
movq %rbx, %rdi
callq 0x3fec
movl %eax, %r14d
testl %eax, %eax
jns 0x359c
movq %rbx, %rdi
callq 0x3e6c
xorl %ebx, %ebx
movq 0x10(%rbp), %rsi
testq %rsi, %rsi
je 0x38da
movb (%rbp), %cl
movl $0x1, %eax
shlq %cl, %rax
jmp 0x38dc
xorl %eax, %eax
cmpq %rax, %rbx
jae 0x3904
movq 0x8(%rbp), %rax
movl %ebx, %ecx
shrl $0x5, %ecx
movl (%rax,%rcx,4), %eax
btl %ebx, %eax
jb 0x38f7
incq %rbx
jmp 0x38c4
movq %rsi, %rdi
movq %rbx, %rsi
callq 0x25a1
jmp 0x38f2
testq %rbp, %rbp
je 0x392c
movq 0x18(%rbp), %rbx
movq %rbx, %rdi
callq 0x4b8a
movq 0x8(%rbp), %rsi
movq %rbx, %rdi
callq 0x4b8a
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x4b8a
movq (%r13), %rdi
callq 0x2270
cmpl $-0x1, %eax
je 0x3a2b
xorl %ebx, %ebx
cmpl $0x0, 0x58d5(%rip)      # 0x921c
js 0x39d0
movl %r12d, %edi
movq %r15, %rsi
callq 0x248b
jmp 0x39d0
leaq 0x27c8(%rip), %rdi      # 0x6129
callq 0x20b0
xorl %ebx, %ebx
jmp 0x39d0
callq 0x276e
jmp 0x39cb
callq 0x2420
jmp 0x39cb
callq 0x243f
jmp 0x319d
movq 0x5667(%rip), %rax      # 0x8ff0
movq (%rax), %rdi
movslq %r9d, %rax
movq -0x8(%r15,%rax,8), %rcx
leaq 0x27b5(%rip), %rsi      # 0x6150
jmp 0x39b6
movq 0x564c(%rip), %rax      # 0x8ff0
movq (%rax), %rdi
movslq %r9d, %rax
movq -0x8(%r15,%rax,8), %rcx
leaq 0x2777(%rip), %rsi      # 0x612d
leaq 0x278e(%rip), %rdx      # 0x614b
xorl %eax, %eax
callq 0x2200
jmp 0x39cb
callq 0x278d
movl $0x1, %ebx
movl %ebx, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebx, %edi
movl %r14d, %esi
callq 0x245e
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x26d1
movq %r14, %rdi
callq 0x26a6
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x2657
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x260f
callq 0x25d5
callq 0x2579
movl %r14d, %edi
callq 0x2744
movq %rbx, %rdi
callq 0x2719