// File: /workspace/github_c_makefile_star2_O1/c-zhou[P]oatk/run_hmmannot.c
// Function: main
int main(int argc, char *argv[])
{
    const char *opt_str = "t:b:T:o:Vv:h";
    ketopt_t opt = KETOPT_INIT;
    int c, ret = 0;
    int n_threads, batch_size, n_file;
    FILE *fp_help, *out_fp;
    char *out, *nhmmdb, *tmpdir;
    char **file_in;

    sys_init();
    
    fp_help = stderr;
    out_fp = stdout;
    out = nhmmdb = tmpdir = 0;
    file_in = 0;
    n_file = 0;
    batch_size = 1000000;
    n_threads = 4;
    char *nhmmscan = "nhmmscan";

    while ((c = ketopt(&opt, argc, argv, 1, opt_str, long_options)) >=0 ) {
        if (c == 't') n_threads = atoi(opt.arg);
        else if (c == 'b') batch_size = atoi(opt.arg);
        else if (c == 'T') tmpdir = opt.arg;
        else if (c == 301) nhmmscan = opt.arg;
        else if (c == 'v') VERBOSE = atoi(opt.arg);
        else if (c == 'h') fp_help = stdout;
        else if (c == 'o') {
            if (strcmp(opt.arg, "-") != 0) {
                out = opt.arg;
            }
        }
        else if (c == 'V') {
            puts(HMMANNOTATION_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: hmmannot [options] <hmmdb> <query>[.gfa|.fa|.fq][.gz] [...]\n");
        fprintf(fp_help, "Options:\n");
        fprintf(fp_help, "    -b INT           batch size [%d]\n", batch_size);
        fprintf(fp_help, "    -t INT           number threads [4]\n");
        fprintf(fp_help, "    -T STR           temporary directory [NULL]\n");
        fprintf(fp_help, "    -o FILE          output results to FILE [stdout]\n");
        fprintf(fp_help, "    --nhmmscan STR   nhmmscan executable path [%s]\n", nhmmscan);
        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: ./hmmannot -t 8 --nhmmscan /usr/bin/nhmmscan -o asm_annot.mito.txt angiosperm_mito.fam asm.gfa\n\n");
        return fp_help == stdout? 0 : 1;
    }

    if (argc - opt.ind < 1) {
        fprintf(stderr, "[E::%s] missing input: please specify the hmmdb file\n", __func__);
        return 1;
    } else {
        nhmmdb = argv[opt.ind];
        if (!is_file(nhmmdb)) {
            fprintf(stderr, "[E::%s] input database file does not exist: %s\n", __func__, nhmmdb);
            exit(EXIT_FAILURE);
        }
    }

    if (argc - opt.ind < 2) {
        fprintf(stderr, "[E::%s] missing input: please specify at least one query file\n", __func__);
        return 1;
    } else {
        file_in = argv + opt.ind + 1;
        n_file = argc - opt.ind - 1;
    }

    // check if nhmmscan executable is available
    check_executable(nhmmscan);

    if (out) out_fp = fopen(out, "w");

    ret = hmm_annotate(file_in, n_file, nhmmscan, nhmmdb, out_fp, batch_size, n_threads * 5, n_threads, tmpdir);

    if (out) fclose(out_fp);

    if (ret) {
        fprintf(stderr, "[E::%s] annotation failed\n", __func__);
        exit(EXIT_FAILURE);
    }

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

    if (VERBOSE >= 0) {
        fprintf(stderr, "[M::%s] Version: %s\n", __func__, HMMANNOTATION_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, %r12
movl %edi, %r13d
callq 0x534b
movq 0x6e0e(%rip), %rax      # 0x9ff0
movq (%rax), %rax
movq %rax, 0x78(%rsp)
movq 0x6ddf(%rip), %rax      # 0x9fd0
movq (%rax), %rax
movq %rax, 0x60(%rsp)
movslq %r13d, %r11
leal -0x1(%r11), %eax
movl %eax, 0x3c(%rsp)
movl %r11d, %eax
negl %eax
movq %rax, 0x80(%rsp)
leaq 0x3df8(%rip), %rdx      # 0x7010
movl $0xf4240, 0x24(%rsp)    # imm = 0xF4240
movl $0x4, %eax
movq %rax, 0x70(%rsp)
movl $0x1, %r9d
xorl %r15d, %r15d
movq $0x0, 0x10(%rsp)
xorl %ebx, %ebx
xorl %ecx, %ecx
movq %rdx, 0x58(%rsp)
movq %r12, 0x28(%rsp)
movq %r13, 0x50(%rsp)
movq %r11, (%rsp)
movq %rcx, %r10
cmpl %r13d, %r9d
setl %cl
jge 0x32ad
movslq %r9d, %rax
leal (%r15,%r13), %edx
subl %r9d, %edx
incq %rax
movq 0x80(%rsp), %rcx
leal (%rcx,%r9), %edi
movb $0x1, %cl
xorl %esi, %esi
movq -0x8(%r12,%rax,8), %r8
cmpb $0x2d, (%r8)
jne 0x328d
cmpb $0x0, 0x1(%r8)
jne 0x32a7
cmpq %r11, %rax
setl %cl
decl %esi
incq %rax
cmpl %esi, %edi
jne 0x327b
movl %edx, %r15d
movl %r13d, %r9d
movl %r13d, %esi
jmp 0x32b0
subl %esi, %r15d
subl %esi, %r9d
movl %r9d, %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testb $0x1, %cl
je 0x3592
movq %rbx, 0x18(%rsp)
movslq %esi, %rbx
movq (%r12,%rbx,8), %r8
cmpb $0x2d, (%r8)
jne 0x3322
movzbl 0x1(%r8), %ecx
testl %ecx, %ecx
je 0x3322
cmpl $0x2d, %ecx
jne 0x332e
cmpb $0x0, 0x2(%r8)
je 0x346b
movq %rbx, 0x68(%rsp)
leaq 0x2(%r8), %rbx
addq $0x3, %r8
xorl %ebp, %ebp
movabsq $0x100000000, %rax      # imm = 0x100000000
movzbl -0x1(%r8), %r12d
testl %r12d, %r12d
je 0x33a9
cmpl $0x3d, %r12d
je 0x33a9
addq %rax, %rbp
incq %r8
jmp 0x3302
xorl %edi, %edi
movq 0x18(%rsp), %rbx
jmp 0x3594
movq %rsi, 0x30(%rsp)
movq %r9, 0x8(%rsp)
movq %r15, %r14
movq %r10, %r15
movq 0x10(%rsp), %rbp
cmpl $0x1, %ebp
adcl $0x0, %ebp
movslq %ebp, %rbp
movq %r8, 0x10(%rsp)
movsbl (%r8,%rbp), %r13d
incq %rbp
movl $0xd, %edx
leaq 0x3cfa(%rip), %rdi      # 0x705f
movl %r13d, %esi
callq 0x21d0
testq %rax, %rax
je 0x34a0
cmpb $0x3a, 0x1(%rax)
movq %r15, %r10
jne 0x34d2
movq 0x10(%rsp), %rdi
cmpb $0x0, (%rdi,%rbp)
movq (%rsp), %r11
movq %r14, %r15
je 0x36d8
addq %rbp, %rdi
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %r13d, %eax
jmp 0x34de
movq %rsi, 0x30(%rsp)
movq %r8, 0x10(%rsp)
movq %r9, 0x8(%rsp)
movq %r15, 0x40(%rsp)
movq %r10, 0x48(%rsp)
sarq $0x20, %rbp
xorl %r15d, %r15d
leaq 0x6960(%rip), %r14      # 0x9d30
leaq 0x3c39(%rip), %rsi      # 0x7010
xorl %r13d, %r13d
movq %rbx, %rdi
movq %rbp, %rdx
callq 0x2090
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
cmoveq %r14, %r15
addl %ecx, %r13d
movq 0x10(%r14), %rsi
addq $0x10, %r14
testq %rsi, %rsi
jne 0x33da
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x1, %r13d
jne 0x34ac
movl 0xc(%r15), %r13d
cmpb $0x3d, %r12b
movl $0x0, %eax
movq 0x10(%rsp), %rdi
cmovneq %rax, %rdi
testb %r12b, %r12b
movq 0x48(%rsp), %r10
movq 0x8(%rsp), %r9
movq 0x68(%rsp), %rbx
jne 0x370a
cmpl $0x1, 0x8(%r15)
movq 0x28(%rsp), %r12
jne 0x3705
movl $0x3a, %eax
movq 0x30(%rsp), %rdx
cmpl 0x3c(%rsp), %edx
movq (%rsp), %r11
movq 0x40(%rsp), %r15
jge 0x34e3
jmp 0x36e8
testl %r15d, %r15d
jle 0x357b
movq %rsi, %r9
movl %r15d, %edx
leaq (%r12,%rbx,8), %rsi
xorl %ecx, %ecx
movq -0x8(%rsi), %rdi
movq %rdi, (%rsi)
addq $-0x8, %rsi
incq %rcx
cmpq %rcx, %rdx
jne 0x3480
movq 0x18(%rsp), %rbx
movq %r9, %rsi
jmp 0x3582
movl $0x3f, %eax
xorl %edi, %edi
movq %r15, %r10
jmp 0x34d7
movl $0x3f, %eax
xorl %edi, %edi
movq 0x28(%rsp), %r12
movq 0x48(%rsp), %r10
movq (%rsp), %r11
movq 0x40(%rsp), %r15
movq 0x8(%rsp), %r9
movq 0x68(%rsp), %rbx
jmp 0x34e3
xorl %edi, %edi
movl %r13d, %eax
movq (%rsp), %r11
movq %r14, %r15
movq 0x8(%rsp), %r9
testl %ebp, %ebp
js 0x3508
movslq %r9d, %rcx
movq (%r12,%rcx,8), %rcx
movl %ebp, %edx
cmpb $0x0, (%rcx,%rdx)
je 0x3508
movq %rbp, 0x10(%rsp)
movl %r9d, %esi
movq 0x50(%rsp), %r13
jmp 0x3324
leal 0x1(%r9), %ecx
testl %r15d, %r15d
setle %dl
cmpl %r9d, 0x30(%rsp)
setg %sil
movq $0x0, 0x10(%rsp)
orb %dl, %sil
movq 0x50(%rsp), %r13
je 0x3538
movl %ecx, %r9d
movl %ecx, %esi
jmp 0x3324
movq %rdi, %r14
movl %r15d, %edx
leaq (%r12,%rbx,8), %rsi
negq %rdx
movq (%r12,%rbx,8), %rdi
xorl %r8d, %r8d
movq -0x8(%rsi,%r8,8), %r9
movq %r9, (%rsi,%r8,8)
decq %r8
cmpq %r8, %rdx
jne 0x354c
movq %rdi, (%rsi,%r8,8)
incq %rbx
addq $0x8, %rsi
cmpl %ebx, %ecx
jne 0x3545
movl %ecx, %r9d
movl %ecx, %esi
movq 0x18(%rsp), %rbx
movq %r14, %rdi
jmp 0x3594
xorl %ecx, %ecx
movq 0x18(%rsp), %rbx
movl %esi, %edx
subl %ecx, %edx
movslq %edx, %rcx
movq %r8, (%r12,%rcx,8)
incl %esi
movl %esi, %r9d
xorl %edi, %edi
testl %eax, %eax
js 0x3731
cmpl $0x6e, %eax
jle 0x35d3
cmpl $0x75, %eax
jg 0x3600
cmpl $0x6f, %eax
je 0x3667
movq %r10, %rcx
cmpl $0x74, %eax
jne 0x3253
movq %r9, %rbp
movq %r15, %r14
movq %r10, %r15
callq 0x2340
movq %rax, 0x70(%rsp)
jmp 0x36b5
cmpl $0x61, %eax
jle 0x3624
cmpl $0x62, %eax
je 0x3653
movq %r10, %rcx
cmpl $0x68, %eax
jne 0x3253
movq 0x69e0(%rip), %rax      # 0x9fd0
movq (%rax), %rax
movq %rax, 0x78(%rsp)
movq %r10, %rcx
jmp 0x3253
cmpl $0x76, %eax
je 0x36a1
movq %r10, %rcx
cmpl $0x12d, %eax            # imm = 0x12D
jne 0x3253
movq %r10, %rcx
movq %rdi, 0x58(%rsp)
jmp 0x3253
cmpl $0x55, %eax
jg 0x36c7
movq %rdi, %rcx
cmpl $0x54, %eax
je 0x3253
cmpl $0x3a, %eax
je 0x3984
movq %r10, %rcx
cmpl $0x3f, %eax
jne 0x3253
jmp 0x399f
movq %r9, %rbp
movq %r15, %r14
movq %r10, %r15
callq 0x2340
movl %eax, 0x24(%rsp)
jmp 0x36b5
leaq 0x39ba(%rip), %rsi      # 0x7028
movq %r9, 0x8(%rsp)
movq %r15, %r14
movq %r10, %r15
movq %r13, %rbp
movq %rdi, %r13
callq 0x2200
testl %eax, %eax
cmovneq %r13, %rbx
movq %rbp, %r13
movq %r15, %rcx
movq %r14, %r15
movq 0x8(%rsp), %r9
movq (%rsp), %r11
jmp 0x3253
movq %r9, %rbp
movq %r15, %r14
movq %r10, %r15
callq 0x2340
movl %eax, 0x6b5f(%rip)      # 0xa214
movq %r15, %rcx
movq %r14, %r15
movq %rbp, %r9
movq (%rsp), %r11
jmp 0x3253
movq %r10, %rcx
cmpl $0x56, %eax
jne 0x3253
jmp 0x3966
movq 0x30(%rsp), %rax
cmpl 0x3c(%rsp), %eax
movq 0x8(%rsp), %r9
jge 0x3720
movq 0x30(%rsp), %rax
leal 0x1(%rax), %r9d
cltq
movq 0x8(%r12,%rax,8), %rdi
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %r13d, %eax
jmp 0x34e3
movl %r13d, %eax
jmp 0x3712
movl %r13d, %eax
movq 0x28(%rsp), %r12
movq (%rsp), %r11
movq 0x40(%rsp), %r15
jmp 0x34e3
movl $0x3a, %eax
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %edi, %edi
jmp 0x34e3
subl %r15d, %esi
cmpl %esi, %r13d
movq 0x78(%rsp), %r14
je 0x3837
movq 0x6887(%rip), %rax      # 0x9fd0
cmpq (%rax), %r14
je 0x3837
movl %r13d, %ebp
subl %esi, %ebp
jle 0x3976
movq %r10, 0x48(%rsp)
movq %rbx, %r14
movslq %esi, %rbx
movq (%r12,%rbx,8), %r12
movq %r12, %rdi
callq 0x54b4
testl %eax, %eax
je 0x39cd
cmpl $0x1, %ebp
movq 0x58(%rsp), %r15
jle 0x397d
movq 0x28(%rsp), %rax
leaq (%rax,%rbx,8), %r13
addq $0x8, %r13
decl %ebp
movq %r15, %rdi
callq 0x546e
testq %r14, %r14
je 0x37ba
leaq 0x3b9e(%rip), %rsi      # 0x734b
movq %r14, %rdi
callq 0x2310
movq %rax, 0x60(%rsp)
movq 0x70(%rsp), %r10
leal (%r10,%r10,4), %eax
subq $0x8, %rsp
movq %r13, %rdi
movl %ebp, %esi
movq %r15, %rdx
movq %r12, %rcx
movq 0x68(%rsp), %rbx
movq %rbx, %r8
movl 0x2c(%rsp), %r9d
pushq 0x50(%rsp)
pushq %r10
pushq %rax
callq 0x291c
addq $0x20, %rsp
testq %r14, %r14
je 0x37fc
movq %rbx, %rdi
callq 0x2110
movq 0x67cd(%rip), %rax      # 0x9fd0
movq (%rax), %rdi
callq 0x2290
cmpl $-0x1, %eax
movq 0x28(%rsp), %rsi
movq 0x50(%rsp), %rdi
je 0x39d5
xorl %ebp, %ebp
cmpl $0x0, 0x69ed(%rip)      # 0xa214
js 0x3952
callq 0x24ad
jmp 0x3952
movl $0xa, %edi
movq %r14, %rsi
callq 0x21c0
leaq 0x3866(%rip), %rdi      # 0x70b1
movl $0x43, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2380
leaq 0x3891(%rip), %rdi      # 0x70f5
movl $0x9, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2380
leaq 0x3882(%rip), %rsi      # 0x70ff
movq %r14, %rdi
movl 0x24(%rsp), %edx
xorl %eax, %eax
callq 0x2220
leaq 0x3893(%rip), %rdi      # 0x7125
movl $0x28, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2380
leaq 0x38a3(%rip), %rdi      # 0x714e
movl $0x30, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2380
leaq 0x38bb(%rip), %rdi      # 0x717f
movl $0x35, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2380
leaq 0x38d8(%rip), %rsi      # 0x71b5
movq %r14, %rdi
movq 0x58(%rsp), %rdx
xorl %eax, %eax
callq 0x2220
movl 0x6922(%rip), %edx      # 0xa214
leaq 0x38f0(%rip), %rsi      # 0x71e9
movq %r14, %rdi
xorl %eax, %eax
callq 0x2220
leaq 0x3908(%rip), %rdi      # 0x7212
movl $0x29, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2380
movl $0xa, %edi
movq %r14, %rsi
callq 0x21c0
leaq 0x390c(%rip), %rdi      # 0x723c
movl $0x69, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2380
xorl %ebp, %ebp
movq 0x6685(%rip), %rax      # 0x9fd0
cmpq (%rax), %r14
setne %bpl
movl %ebp, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x36ff(%rip), %rdi      # 0x706c
callq 0x20c0
xorl %ebp, %ebp
jmp 0x3952
callq 0x248e
jmp 0x39c6
callq 0x25c3
jmp 0x39c6
movq 0x6665(%rip), %rax      # 0x9ff0
movq (%rax), %rdi
movslq %r9d, %rax
movq -0x8(%r12,%rax,8), %rcx
leaq 0x36f6(%rip), %rsi      # 0x7093
jmp 0x39b8
movq 0x664a(%rip), %rax      # 0x9ff0
movq (%rax), %rdi
movslq %r9d, %rax
movq -0x8(%r12,%rax,8), %rcx
leaq 0x36b8(%rip), %rsi      # 0x7070
leaq 0x36cf(%rip), %rdx      # 0x708e
xorl %eax, %eax
callq 0x2220
movl $0x1, %ebp
jmp 0x3952
movq %r12, %rdi
callq 0x25e2
callq 0x259b