// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq 0x20(%rbp), %rax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x21a0
movl -0x2c(%rbp), %eax
movl %eax, -0x70(%rbp)
movl 0x10(%rbp), %eax
movl %eax, -0x6c(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x254c
movq -0x18(%rbp), %rax
movq %rax, -0x138(%rbp)
jmp 0x255c
leaq 0x6abd(%rip), %rax      # 0x9010
movq %rax, -0x138(%rbp)
jmp 0x255c
movq -0x138(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x48(%rbp)
movl 0x18(%rbp), %eax
movl %eax, -0x38(%rbp)
movl $0x0, -0x74(%rbp)
cmpq $0x0, 0x20(%rbp)
je 0x25d2
leaq -0x108(%rbp), %rdi
xorl %esi, %esi
movl $0x90, %edx
callq 0x21a0
movq 0x20(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x2230
cmpl $-0x1, %eax
jne 0x25c8
movq 0x20(%rbp), %rdi
movl $0x1c0, %esi            # imm = 0x1C0
callq 0x20b0
movl $0x1, -0x74(%rbp)
movq 0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x261d
movq 0x6a40(%rip), %rax      # 0x9019
movq %rax, -0x117(%rbp)
movl 0x6a3b(%rip), %eax      # 0x9021
movl %eax, -0x10f(%rbp)
movw 0x6a32(%rip), %ax       # 0x9025
movw %ax, -0x10b(%rbp)
movb 0x6a27(%rip), %al       # 0x9027
movb %al, -0x109(%rbp)
leaq -0x117(%rbp), %rdi
callq 0x22d0
movq %rax, -0x40(%rbp)
movl $0x1, -0x74(%rbp)
movl $0x0, -0x11c(%rbp)
movl -0x11c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x2787
movq -0x8(%rbp), %rax
movslq -0x11c(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x268c
movq -0x8(%rbp), %rax
movslq -0x11c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x69ca(%rip), %rsi      # 0x9028
callq 0x2200
cmpl $0x0, %eax
je 0x268c
movq -0x8(%rbp), %rax
movslq -0x11c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x6ed1(%rip), %rsi      # 0x954f
callq 0x22f0
movq %rax, -0x140(%rbp)
jmp 0x26a1
xorl %edi, %edi
leaq 0x6eba(%rip), %rsi      # 0x954f
callq 0x20f0
movq %rax, -0x140(%rbp)
movq -0x140(%rbp), %rax
movq %rax, -0x128(%rbp)
cmpq $0x0, -0x128(%rbp)
jne 0x26f1
movq 0x9938(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movslq -0x11c(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
leaq 0x6951(%rip), %rsi      # 0x902a
leaq 0x6972(%rip), %rdx      # 0x9052
movb $0x0, %al
callq 0x2220
movl $0x1, %edi
callq 0x2370
movq -0x128(%rbp), %rdi
callq 0x27b0
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x1, %edi
movl $0x18, %esi
callq 0x21f0
movq %rax, -0x50(%rbp)
movl 0x18(%rbp), %edi
leaq 0xe4(%rip), %rsi        # 0x2810
leaq -0x70(%rbp), %rdx
movl $0x3, %ecx
callq 0x8430
movq -0x130(%rbp), %rdi
callq 0x30a0
movq -0x50(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x275e
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2050
movq -0x50(%rbp), %rdi
callq 0x2050
movq -0x128(%rbp), %rdi
callq 0x2040
movl -0x11c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x11c(%rbp)
jmp 0x2627
cmpl $0x0, -0x74(%rbp)
je 0x2796
movq -0x40(%rbp), %rdi
callq 0x2120
xorl %eax, %eax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopw %cs:(%rax,%rax)