// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/ltr/pdom_model_set.c
// Function: gt_pdom_model_set_new
GtPdomModelSet* gt_pdom_model_set_new(GtStrArray *hmmfiles, bool force,
                                      GtError *err)
{
  GtStr *concat_dbnames, *cmdline, *indexfilename = NULL;
  GtUword i;
  char *md5_hash, ch;
  const char *tmpdir;
  int had_err = 0, rval;
  FILE *dest;
  GtPdomModelSet *pdom_model_set;
  gt_assert(hmmfiles);
  gt_error_check(err);

  rval = system("hmmpress -h > /dev/null");
  if (WEXITSTATUS(rval) != 0) {
    gt_error_set(err, "Error running hmmpress. "
                      PDOM_MODEL_SET_HMMER_NOT_FOUND);
    return NULL;
  }
  rval = system("hmmconvert -h > /dev/null");
  if (WEXITSTATUS(rval) != 0) {
    gt_error_set(err, "Error running hmmconvert. "
                      PDOM_MODEL_SET_HMMER_NOT_FOUND);
    return NULL;
  }

  pdom_model_set = gt_calloc((size_t) 1, sizeof (GtPdomModelSet));
  concat_dbnames = gt_str_new();
  for (i = 0; !had_err && i < gt_str_array_size(hmmfiles); i++) {
    const char *filename = gt_str_array_get(hmmfiles, i);
    if (!gt_file_exists(filename)) {
      gt_error_set(err, "invalid HMM file: %s", filename);
      gt_str_delete(concat_dbnames);
      gt_free(pdom_model_set);
      return NULL;
    } else {
      FILE *fp;
      char line[BUFSIZ];
      GtUword lineno = 0;
      size_t len = 0;

      fp = fopen(filename, "r");
      if (fp == NULL) {
        gt_error_set(err, "can't open HMM file: %s", filename);
        gt_str_delete(concat_dbnames);
        gt_free(pdom_model_set);
        return NULL;
      }

      while (fgets(line, BUFSIZ, fp) != NULL) {
        len = strlen(line);
        lineno++;
        if (len > 5 && strncmp(line, "ALPH", 4 * sizeof (char)) == 0) {
          if (len > 9 && (strncmp(line, "ALPH  Amino", 11 * sizeof (char)) == 0
                     || strncmp(line, "ALPH  amino", 11 * sizeof (char)) == 0
                     || strncmp(line, "ALPH  AMINO", 11 * sizeof (char)) == 0))
          {
            break;
          } else {
            gt_error_set(err, "invalid (non-protein) alphabet definition "
                              "in %s line "GT_WU, filename, lineno);
            gt_str_delete(concat_dbnames);
            gt_free(pdom_model_set);
            fclose(fp);
            return NULL;
          }
        }
      }
      fclose(fp);
      gt_str_append_cstr(concat_dbnames, filename);
    }
  }
  if (!had_err) {
    pdom_model_set->filename = gt_str_new();
    if (!(tmpdir = getenv("TMPDIR")))
      tmpdir = "/tmp";
    gt_str_append_cstr(pdom_model_set->filename, tmpdir);
    gt_str_append_char(pdom_model_set->filename, GT_PATH_SEPARATOR);
    md5_hash = gt_md5_fingerprint(gt_str_get(concat_dbnames),
                                  gt_str_length(concat_dbnames));
    gt_str_append_cstr(pdom_model_set->filename, md5_hash);
    gt_free(md5_hash);
    indexfilename = gt_str_new_cstr(gt_str_get(pdom_model_set->filename));
    gt_str_append_cstr(indexfilename, GT_HMM_INDEX_SUFFIX);
  }

  if (!gt_file_exists(gt_str_get(indexfilename)) || force) {
    dest = fopen(gt_str_get(pdom_model_set->filename), "w+");
    if (!dest) {
      gt_error_set(err, "could not create file %s",
                 gt_str_get(pdom_model_set->filename));
      had_err = -1;
    }
    if (!had_err) {
      for (i = 0; !had_err && i < gt_str_array_size(hmmfiles); i++) {
        FILE *source;
        char cmd[BUFSIZ];
        (void) snprintf(cmd, BUFSIZ, "hmmconvert %s",
                        gt_str_array_get(hmmfiles, i));
        source = popen(cmd, "r");
        if (!source) {
          gt_error_set(err, "error opening/converting HMM file %s",
                            gt_str_array_get(hmmfiles, i));
          had_err = -1;
          gt_pdom_model_set_delete_index(gt_str_get(pdom_model_set->filename));
        }
        if (!had_err) {
          GtWord len = 0;
          while ((ch = fgetc(source)) != EOF) {
            (void) fputc(ch, dest);
            len++;
          }
          (void) pclose(source);
          if (len == 0) {
            gt_error_set(err, "invalid HMMER format encountered trying to "
                              "convert HMM file %s",
                              gt_str_array_get(hmmfiles, i));
            had_err = -1;
            gt_pdom_model_set_delete_index
                                         (gt_str_get(pdom_model_set->filename));
          }
        }
      }
      (void) fclose(dest);
    }
    if (!had_err) {
      cmdline = gt_str_new_cstr("hmmpress -f ");
      gt_str_append_str(cmdline, pdom_model_set->filename);
      gt_str_append_cstr(cmdline, "> /dev/null");   /* XXX: portability? */

      rval = system(gt_str_get(cmdline));
      gt_str_delete(cmdline);
      if (WEXITSTATUS(rval) != 0) {
        gt_error_set(err, "Error executing hmmpress. "
                          "Please make sure your pHMMs are valid and"
                          "share a common version (e.g. HMMER2 or HMMER3).");
        had_err = -1;
      }
    }
  }

  if (had_err) {
    gt_pdom_model_set_delete(pdom_model_set);
    pdom_model_set = NULL;
  }
  gt_str_delete(indexfilename);
  gt_str_delete(concat_dbnames);
  return pdom_model_set;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2028, %rsp           # imm = 0x2028
testq %rdi, %rdi
je 0x1c73ff
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r12
testq %rdx, %rdx
je 0x1c6f5b
movq %rbx, %rdi
callq 0x89eb7
testb %al, %al
jne 0x1c7429
leaq 0x19aba2(%rip), %rdi    # 0x361b04
callq 0x17670
testw $0xff00, %ax            # imm = 0xFF00
je 0x1c6f76
leaq 0x19aba8(%rip), %rsi    # 0x361b1c
jmp 0x1c6f8f
leaq 0x19abf5(%rip), %rdi    # 0x361b72
callq 0x17670
testw $0xff00, %ax            # imm = 0xFF00
je 0x1c6fb1
leaq 0x19abfd(%rip), %rsi    # 0x361b8c
xorl %r13d, %r13d
movq %rbx, %rdi
xorl %eax, %eax
callq 0x89dbb
movq %r13, %rax
addq $0x2028, %rsp           # imm = 0x2028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebp, 0x10(%rsp)
movq %rbx, (%rsp)
leaq 0x19ab2b(%rip), %rdx    # 0x361aeb
pushq $0x1
popq %rdi
pushq $0x8
popq %rsi
pushq $0x59
popq %rcx
callq 0x9334a
movq %rax, 0x18(%rsp)
xorl %r13d, %r13d
callq 0xacb84
movq %rax, 0x8(%rsp)
leaq 0x20(%rsp), %rbp
movq %r12, %rdi
callq 0xae61c
cmpq %rax, %r13
jae 0x1c70cf
movq %r12, %rdi
movq %r13, %rsi
callq 0xae386
movq %rax, %r15
movq %rax, %rdi
callq 0x8da98
testb %al, %al
je 0x1c729d
movq %r15, %rdi
leaq 0x133e0f(%rip), %rsi    # 0x2fae2d
callq 0x17860
testq %rax, %rax
je 0x1c72c7
movq %rax, %rbx
xorl %r14d, %r14d
movq %rbp, %rdi
movl $0x2000, %esi           # imm = 0x2000
movq %rbx, %rdx
callq 0x17bc0
testq %rax, %rax
je 0x1c70b2
movq %rbp, %rdi
callq 0x172d0
incq %r14
cmpq $0x6, %rax
jb 0x1c7032
cmpl $0x48504c41, 0x20(%rsp) # imm = 0x48504C41
jne 0x1c7032
cmpq $0xa, %rax
jb 0x1c72fc
movq %rbp, %rdi
leaq 0x19ab9b(%rip), %rsi    # 0x361c11
pushq $0xb
popq %rdx
callq 0x177e0
testl %eax, %eax
je 0x1c70b2
movq %rbp, %rdi
leaq 0x19ab91(%rip), %rsi    # 0x361c1d
pushq $0xb
popq %rdx
callq 0x177e0
testl %eax, %eax
je 0x1c70b2
movq %rbp, %rdi
leaq 0x19ab87(%rip), %rsi    # 0x361c29
pushq $0xb
popq %rdx
callq 0x177e0
testl %eax, %eax
jne 0x1c72fc
movq %rbx, %rdi
callq 0x177c0
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0xacbfb
incq %r13
jmp 0x1c6fe5
callq 0xacb84
movq %rax, %rbx
movq 0x18(%rsp), %r13
movq %rax, (%r13)
leaq 0x1aef40(%rip), %rdi    # 0x376027
callq 0x17900
testq %rax, %rax
leaq 0x142e84(%rip), %rsi    # 0x309f7a
cmovneq %rax, %rsi
movq %rbx, %rdi
callq 0xacbfb
movq (%r13), %rdi
pushq $0x2f
popq %rsi
callq 0xaced9
movq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0xad1fa
movq %rax, %rbx
movq %r14, %rdi
callq 0xad289
movq %rbx, %rdi
movq %rax, %rsi
callq 0x96924
movq %rax, %rbx
movq (%r13), %rdi
movq %rax, %rsi
callq 0xacbfb
leaq 0x19a9a4(%rip), %rsi    # 0x361aeb
movq %rbx, %rdi
movl $0x90, %edx
callq 0x936f9
movq (%r13), %rdi
callq 0xad1fa
movq %rax, %rdi
callq 0xacbd1
movq %rax, %rbx
leaq 0x19ac5a(%rip), %rsi    # 0x361dc9
movq %rax, %rdi
callq 0xacbfb
movq %rbx, %rdi
callq 0xad1fa
movq %rax, %rdi
callq 0x8da98
xorb $0x1, %al
orb 0x10(%rsp), %al
cmpb $0x1, %al
jne 0x1c73e1
movq (%r13), %rdi
callq 0xad1fa
leaq 0x11e4c4(%rip), %rsi    # 0x2e5669
movq %rax, %rdi
callq 0x17860
testq %rax, %rax
je 0x1c7342
movq %rax, %rbp
movq %rbx, 0x10(%rsp)
xorl %eax, %eax
xorl %r15d, %r15d
testl %eax, %eax
jne 0x1c7362
movq %r12, %rdi
callq 0xae61c
cmpq %rax, %r15
jae 0x1c736c
movq %r12, %rdi
movq %r15, %rsi
callq 0xae386
movl $0x2000, %esi           # imm = 0x2000
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
leaq 0x19aa8c(%rip), %rdx    # 0x361c87
movq %rax, %rcx
xorl %eax, %eax
callq 0x17bf0
movq %rbx, %rdi
leaq 0x133c1e(%rip), %rsi    # 0x2fae2d
callq 0x171f0
leaq 0x19aa7a(%rip), %r14    # 0x361c95
testq %rax, %rax
je 0x1c7265
movq %rax, %rbx
xorl %r13d, %r13d
movq %rbx, %rdi
callq 0x17bb0
shll $0x18, %eax
cmpl $0xff000000, %eax       # imm = 0xFF000000
je 0x1c724a
sarl $0x18, %eax
movl %eax, %edi
movq %rbp, %rsi
callq 0x17930
decq %r13
jmp 0x1c7226
movq %rbx, %rdi
callq 0x17a10
xorl %eax, %eax
leaq 0x19aa5f(%rip), %r14    # 0x361cba
testq %r13, %r13
movq 0x18(%rsp), %r13
jne 0x1c7295
movq %r12, %rdi
movq %r15, %rsi
callq 0xae386
movq (%rsp), %rdi
movq %r14, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x89dbb
movq (%r13), %rdi
callq 0xad1fa
movq %rax, %rdi
callq 0x1c745f
pushq $-0x1
popq %rax
incq %r15
jmp 0x1c71c3
leaq 0x19a940(%rip), %rsi    # 0x361be4
movq (%rsp), %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x89dbb
movq 0x8(%rsp), %rdi
callq 0xae103
leaq 0x19a828(%rip), %rsi    # 0x361aeb
pushq $0x60
jmp 0x1c72ef
leaq 0x19a92b(%rip), %rsi    # 0x361bf9
movq (%rsp), %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x89dbb
movq 0x8(%rsp), %rdi
callq 0xae103
leaq 0x19a7fe(%rip), %rsi    # 0x361aeb
pushq $0x6c
popq %rdx
movq 0x18(%rsp), %rdi
callq 0x936f9
jmp 0x1c733a
leaq 0x19a932(%rip), %rsi    # 0x361c35
movq (%rsp), %rdi
movq %r15, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x89dbb
movq 0x8(%rsp), %rdi
callq 0xae103
leaq 0x19a7c6(%rip), %rsi    # 0x361aeb
pushq $0x7d
popq %rdx
movq 0x18(%rsp), %rdi
callq 0x936f9
movq %rbx, %rdi
callq 0x177c0
xorl %r13d, %r13d
jmp 0x1c6f9c
movq (%r13), %rdi
callq 0xad1fa
leaq 0x19a91c(%rip), %rsi    # 0x361c6e
movq (%rsp), %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x89dbb
jmp 0x1c73d6
movq %rbp, %rdi
callq 0x177c0
jmp 0x1c73d1
movq %rbp, %rdi
callq 0x177c0
leaq 0x19a97e(%rip), %rdi    # 0x361cf9
callq 0xacbd1
movq %rax, %rbx
movq (%r13), %rsi
movq %rax, %rdi
callq 0xacd13
leaq 0x199415(%rip), %rsi    # 0x3607ab
movq %rbx, %rdi
callq 0xacbfb
movq %rbx, %rdi
callq 0xad1fa
movq %rax, %rdi
callq 0x17670
movl %eax, %ebp
movq %rbx, %rdi
callq 0xae103
testw $0xff00, %bp            # imm = 0xFF00
je 0x1c73f8
leaq 0x19a940(%rip), %rsi    # 0x361d06
movq (%rsp), %rdi
xorl %eax, %eax
callq 0x89dbb
movq 0x10(%rsp), %rbx
movq %r13, %rdi
callq 0x1c7542
xorl %r13d, %r13d
movq %rbx, %rdi
callq 0xae103
movq 0x8(%rsp), %rdi
callq 0xae103
jmp 0x1c6f9c
movq 0x10(%rsp), %rbx
jmp 0x1c73e1
movq 0x270b62(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x11dc03(%rip), %rsi    # 0x2e5013
leaq 0x19a6b5(%rip), %rdx    # 0x361acc
leaq 0x19a6b7(%rip), %rcx    # 0x361ad5
leaq 0x19a6c6(%rip), %r8     # 0x361aeb
pushq $0x49
jmp 0x1c7451
movq 0x270b38(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x11dbd9(%rip), %rsi    # 0x2e5013
leaq 0x11dd7e(%rip), %rdx    # 0x2e51bf
leaq 0x19a68d(%rip), %rcx    # 0x361ad5
leaq 0x19a69c(%rip), %r8     # 0x361aeb
pushq $0x4a
popq %r9
xorl %eax, %eax
callq 0x17a50
callq 0x17390