// File: /workspace/github_c_makefile_star2_O3/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)
movups %xmm0, 0x20(%rsp)
movq $0x0, 0x40(%rsp)
movl %r9d, 0x8(%rsp)
movl %eax, 0xc(%rsp)
testq %rdx, %rdx
leaq 0x46ee(%rip), %rax      # 0x7010
cmovneq %rdx, %rax
movq %rax, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
movq %r8, 0x30(%rsp)
movl %esi, 0x40(%rsp)
testq %r15, %r15
je 0x297d
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 0x2976
movq %r15, %rdi
movl $0x1c0, %esi            # imm = 0x1C0
callq 0x20b0
movq %r15, 0x38(%rsp)
jmp 0x29af
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)
testl %r14d, %r14d
jle 0x2aa3
movl %r14d, %r12d
xorl %r14d, %r14d
leaq 0x8(%rsp), %r13
movq (%rbx,%r14,8), %rdi
testq %rdi, %rdi
je 0x29e5
cmpb $0x2d, (%rdi)
jne 0x29d7
cmpb $0x0, 0x1(%rdi)
je 0x29e5
leaq 0x4b54(%rip), %rsi      # 0x7532
callq 0x22f0
jmp 0x29f3
xorl %edi, %edi
leaq 0x4b44(%rip), %rsi      # 0x7532
callq 0x20f0
movq %rax, %rbp
testq %rax, %rax
je 0x2ac8
movl $0x1, %edi
movl $0x20, %esi
callq 0x21f0
movq %rax, %r15
movq %rbp, 0x10(%rax)
movl $0x40000, 0x8(%rax)     # imm = 0x40000
movl $0x10000, %edi          # imm = 0x10000
callq 0x2280
movq %rax, 0x18(%r15)
movq %r15, 0x20(%rsp)
movl $0x1, %edi
movl $0x18, %esi
callq 0x21f0
movq %rax, 0x28(%rsp)
movl 0x118(%rsp), %edi
leaq 0x82(%rip), %rsi        # 0x2ad3
movq %r13, %rdx
movl $0x3, %ecx
callq 0x63d5
movq 0x18(%r15), %rdi
callq 0x2050
movq %r15, %rdi
callq 0x2050
movq 0x28(%rsp), %rdi
movq 0x10(%rdi), %rax
testq %rax, %rax
je 0x2a8a
movq %rax, %rdi
callq 0x2050
movq 0x28(%rsp), %rdi
callq 0x2050
movq %rbp, %rdi
callq 0x2040
incq %r14
cmpq %r14, %r12
jne 0x29c3
cmpb $0x0, 0x4(%rsp)
jne 0x2ab4
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 %rbx, %rdi
movq %r14, %rsi
callq 0x2410