// File: /workspace/github_c_makefile_star2_O2/c-zhou[P]oatk/run_hmmannot.c
// Function: hmm_annotate
int hmm_annotate(char **file_in, int n_file, char *nhmmscan, char *nhmmdb, FILE *fo, uint32_t max_batch_size, uint32_t max_batch_num, int n_threads, char *tmpdir)
{
    annot_pipeline_t pl;
    MYBZERO(&pl, 1);

    pl.max_batch_size = max_batch_size;
    pl.max_batch_num = max_batch_num;
    pl.nhmmscan = nhmmscan? nhmmscan : "nhmmscan";
    pl.nhmmdb = nhmmdb;
    pl.fo = fo;
    pl.n_threads = n_threads;

    int rm_tmpdir = 0;
    if (tmpdir) {
        struct stat st = {0};
        if (stat(tmpdir, &st) == -1) {
            mkdir(tmpdir, 0700);
            rm_tmpdir = 1;
        }
        pl.tmpdir = tmpdir;
    } else {
        char file_template[] = "tmp_XXXXXXXXXX";
        pl.tmpdir = mkdtemp(file_template); // no need to free
        rm_tmpdir = 1;
    }

    int i;
    gzFile fp;
    kstream_t *ks;
    for (i = 0; i < n_file; ++i) {
        fp = file_in[i] && strcmp(file_in[i], "-")? gzopen(file_in[i], "r") : gzdopen(0, "r");
        if (fp == 0) {
            fprintf(stderr, "[E::%s] failed to open file %s to read\n", __func__, file_in[i]);
            exit(EXIT_FAILURE);
        }
        ks = ks_init(fp);
        pl.ks = ks;
        MYCALLOC(pl.s, 1);
        kt_pipeline(n_threads, annot_worker_pipeline, &pl, 3);
        ks_destroy(ks);
        if (pl.s->s) free(pl.s->s);
        free(pl.s);
        gzclose(fp);
    }

    if (rm_tmpdir) rmdir(pl.tmpdir); // should be empty

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movl %esi, %r14d
movq %rdi, %rbx
movq 0x120(%rsp), %r15
movl 0x118(%rsp), %esi
movl 0x110(%rsp), %eax
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
movups %xmm0, 0x20(%rsp)
movl %r9d, 0x8(%rsp)
movl %eax, 0xc(%rsp)
testq %rdx, %rdx
leaq 0x3ac1(%rip), %rax      # 0x6010
cmovneq %rdx, %rax
movq %rax, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
movq %r8, 0x30(%rsp)
movl %esi, 0x40(%rsp)
testq %r15, %r15
je 0x25aa
leaq 0x48(%rsp), %r12
movl $0x90, %edx
movq %r12, %rdi
xorl %esi, %esi
callq 0x2190
movq %r15, %rdi
movq %r12, %rsi
callq 0x2230
cmpl $-0x1, %eax
setne %al
movl %eax, 0x4(%rsp)
jne 0x25a3
movq %r15, %rdi
movl $0x1c0, %esi            # imm = 0x1C0
callq 0x20b0
movq %r15, 0x38(%rsp)
jmp 0x25dc
movabsq $0x58585858585858, %rax # imm = 0x58585858585858
leaq 0x48(%rsp), %rdi
movq %rax, 0x7(%rdi)
movabsq $0x585858585f706d74, %rax # imm = 0x585858585F706D74
movq %rax, (%rdi)
callq 0x22d0
movq %rax, 0x38(%rsp)
movl $0x0, 0x4(%rsp)
xorl %ebp, %ebp
testl %r14d, %r14d
cmovlel %ebp, %r14d
pushq $0x1
popq %r12
cmpq %rbp, %r14
je 0x26be
movq (%rbx,%rbp,8), %rdi
testq %rdi, %rdi
je 0x2614
cmpb $0x2d, (%rdi)
jne 0x2606
cmpb $0x0, 0x1(%rdi)
je 0x2614
leaq 0x3f25(%rip), %rsi      # 0x6532
callq 0x22f0
jmp 0x2622
xorl %edi, %edi
leaq 0x3f15(%rip), %rsi      # 0x6532
callq 0x20f0
movq %rax, %r15
testq %rax, %rax
je 0x26e3
movq %r12, %rdi
pushq $0x20
popq %rsi
callq 0x21f0
movq %rax, %r13
movq %r15, 0x10(%rax)
movl $0x40000, 0x8(%rax)     # imm = 0x40000
movl $0x10000, %edi          # imm = 0x10000
callq 0x2280
movq %rax, 0x18(%r13)
movq %r13, 0x20(%rsp)
movq %r12, %rdi
pushq $0x18
popq %rsi
callq 0x21f0
movq %rax, 0x28(%rsp)
movl 0x118(%rsp), %edi
leaq 0x96(%rip), %rsi        # 0x270e
leaq 0x8(%rsp), %rdx
pushq $0x3
popq %rcx
callq 0x5ad6
movq 0x18(%r13), %rdi
callq 0x2050
movq %r13, %rdi
callq 0x2050
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x2050
movq 0x28(%rsp), %rdi
callq 0x2050
movq %r15, %rdi
callq 0x2040
incq %rbp
jmp 0x25e9
cmpb $0x0, 0x4(%rsp)
jne 0x26cf
movq 0x38(%rsp), %rdi
callq 0x2120
xorl %eax, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x6906(%rip), %rax      # 0x8ff0
movq (%rax), %rdi
movq (%rbx,%rbp,8), %rcx
leaq 0x3930(%rip), %rsi      # 0x6028
leaq 0x3951(%rip), %rdx      # 0x6050
xorl %eax, %eax
callq 0x2220
pushq $0x1
popq %rdi
callq 0x2370