// File: /workspace/github_c_makefile_star2_O1/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 $0xe8, %rsp
movl %esi, %ebp
movq %rdi, %rbx
movq 0x130(%rsp), %r14
movl 0x128(%rsp), %esi
movl 0x120(%rsp), %eax
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
movl %r9d, 0x10(%rsp)
movl %eax, 0x14(%rsp)
testq %rdx, %rdx
leaq 0x469e(%rip), %rax      # 0x7010
cmovneq %rdx, %rax
movq %rax, 0x18(%rsp)
movq %rcx, 0x20(%rsp)
movq %r8, 0x38(%rsp)
movl %esi, 0x48(%rsp)
testq %r14, %r14
je 0x29cd
leaq 0x58(%rsp), %r15
movl $0x90, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x2190
movq %r14, %rdi
movq %r15, %rsi
callq 0x2230
cmpl $-0x1, %eax
setne %al
movl %eax, 0xc(%rsp)
jne 0x29c6
movq %r14, %rdi
movl $0x1c0, %esi            # imm = 0x1C0
callq 0x20b0
movq %r14, 0x40(%rsp)
jmp 0x29ff
movabsq $0x58585858585858, %rax # imm = 0x58585858585858
leaq 0x58(%rsp), %rdi
movq %rax, 0x7(%rdi)
movabsq $0x585858585f706d74, %rax # imm = 0x585858585F706D74
movq %rax, (%rdi)
callq 0x22d0
movq %rax, 0x40(%rsp)
movl $0x0, 0xc(%rsp)
testl %ebp, %ebp
jle 0x2b07
movl %ebp, %r12d
xorl %r14d, %r14d
leaq 0x10(%rsp), %r13
movq (%rbx,%r14,8), %r15
testq %r15, %r15
je 0x2a3f
movq %r15, %rdi
leaq 0x4603(%rip), %rsi      # 0x7028
callq 0x2200
testl %eax, %eax
je 0x2a3f
movq %r15, %rdi
leaq 0x4afc(%rip), %rsi      # 0x7534
callq 0x22f0
jmp 0x2a4d
xorl %edi, %edi
leaq 0x4aec(%rip), %rsi      # 0x7534
callq 0x20f0
movq %rax, %rbp
testq %rax, %rax
je 0x2b2c
movl $0x1, %edi
movl $0x20, %esi
callq 0x21f0
movq %rax, %r15
movq %rbp, 0x10(%rax)
movl 0x8(%rax), %eax
andl $0x3, %eax
orl $0x40000, %eax          # imm = 0x40000
movl %eax, 0x8(%r15)
movl $0x10000, %edi          # imm = 0x10000
callq 0x2280
movq %rax, 0x18(%r15)
movq %r15, 0x28(%rsp)
movl $0x1, %edi
movl $0x18, %esi
callq 0x21f0
movq %rax, 0x30(%rsp)
movl 0x128(%rsp), %edi
leaq 0x84(%rip), %rsi        # 0x2b37
movq %r13, %rdx
movl $0x3, %ecx
callq 0x6109
testq %r15, %r15
je 0x2ad6
movq 0x18(%r15), %rdi
callq 0x2050
movq %r15, %rdi
callq 0x2050
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
testq %rdi, %rdi
je 0x2ae9
callq 0x2050
movq 0x30(%rsp), %rdi
callq 0x2050
movq %rbp, %rdi
callq 0x2040
incq %r14
cmpq %r14, %r12
jne 0x2a12
cmpb $0x0, 0xc(%rsp)
jne 0x2b18
movq 0x40(%rsp), %rdi
callq 0x2120
xorl %eax, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2410