// File: /workspace/github_c_makefile_star2_O1/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 $0x2038, %rsp           # imm = 0x2038
testq %rdi, %rdi
je 0x21c3e5
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r12
testq %rdx, %rdx
je 0x21be87
movq %rbx, %rdi
callq 0x101a9a
testb %al, %al
jne 0x21c3ea
leaq 0x1aef92(%rip), %rdi    # 0x3cae20
callq 0x176a0
testl $0xff00, %eax           # imm = 0xFF00
je 0x21bea3
leaq 0x1aef97(%rip), %rsi    # 0x3cae38
jmp 0x21bebd
leaq 0x1aefe4(%rip), %rdi    # 0x3cae8e
callq 0x176a0
testl $0xff00, %eax           # imm = 0xFF00
je 0x21bedf
leaq 0x1aefeb(%rip), %rsi    # 0x3caea8
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1019cf
movq %r14, %rax
addq $0x2038, %rsp           # imm = 0x2038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebp, 0x2c(%rsp)
movq %rbx, 0x10(%rsp)
leaq 0x1aef18(%rip), %rdx    # 0x3cae07
movl $0x1, %edi
movl $0x8, %esi
movl $0x59, %ecx
callq 0x1093ef
movq %rax, 0x8(%rsp)
callq 0x1208f8
movq %rax, 0x18(%rsp)
movq %r12, %rdi
callq 0x121e78
testq %rax, %rax
je 0x21c05a
movabsq $0x6f6e696d41202048, %rax # imm = 0x6F6E696D41202048
xorl %r13d, %r13d
leaq 0x30(%rsp), %r15
addq $0x20000000, %rax       # imm = 0x20000000
movq %rax, 0x20(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x121cfa
movq %rax, %rbp
movq %rax, %rdi
callq 0x10415c
testb %al, %al
je 0x21c275
movq %rbp, %rdi
leaq 0x147f61(%rip), %rsi    # 0x363ec9
callq 0x178b0
testq %rax, %rax
je 0x21c2a8
movq %rax, %rbx
xorl %r14d, %r14d
movq %r15, %rdi
movl $0x2000, %esi           # imm = 0x2000
movq %rbx, %rdx
callq 0x17c30
testq %rax, %rax
je 0x21c031
movq %r15, %rdi
callq 0x172f0
incq %r14
cmpq $0x6, %rax
jb 0x21bf7c
cmpl $0x48504c41, 0x30(%rsp) # imm = 0x48504C41
jne 0x21bf7c
cmpq $0xa, %rax
jb 0x21c2e0
movq 0x30(%rsp), %rax
movabsq $0x6d41202048504c41, %rcx # imm = 0x6D41202048504C41
xorq %rcx, %rax
movq 0x33(%rsp), %rcx
movabsq $0x6f6e696d41202048, %rdx # imm = 0x6F6E696D41202048
xorq %rdx, %rcx
orq %rax, %rcx
je 0x21c031
movq 0x30(%rsp), %rax
movabsq $0x6d61202048504c41, %rcx # imm = 0x6D61202048504C41
xorq %rcx, %rax
movq 0x33(%rsp), %rcx
xorq 0x20(%rsp), %rcx
orq %rax, %rcx
je 0x21c031
movq 0x30(%rsp), %rax
movabsq $0x4d41202048504c41, %rcx # imm = 0x4D41202048504C41
xorq %rcx, %rax
movq 0x33(%rsp), %rcx
movabsq $0x4f4e494d41202048, %rdx # imm = 0x4F4E494D41202048
xorq %rdx, %rcx
orq %rax, %rcx
jne 0x21c2e0
movq %rbx, %rdi
callq 0x17800
movq 0x18(%rsp), %rdi
movq %rbp, %rsi
callq 0x12097f
incq %r13
movq %r12, %rdi
callq 0x121e78
cmpq %rax, %r13
jb 0x21bf40
callq 0x1208f8
movq %rax, %rbx
movq 0x8(%rsp), %r14
movq %rax, (%r14)
leaq 0x1c32ea(%rip), %rdi    # 0x3df35b
callq 0x17950
testq %rax, %rax
leaq 0x1571f2(%rip), %rsi    # 0x373272
cmovneq %rax, %rsi
movq %rbx, %rdi
callq 0x12097f
movq (%r14), %rdi
movl $0x2f, %esi
callq 0x120ba5
movq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x120d23
movq %rax, %rbx
movq %r15, %rdi
callq 0x120d4c
movq %rbx, %rdi
movq %rax, %rsi
callq 0x10b95c
movq %rax, %rbx
movq (%r14), %rdi
movq %rax, %rsi
callq 0x12097f
leaq 0x1aed36(%rip), %rsi    # 0x3cae07
movq %rbx, %rdi
movl $0x90, %edx
callq 0x109670
movq (%r14), %rdi
callq 0x120d23
movq %rax, %rdi
callq 0x120955
movq %rax, %r15
leaq 0x1aefed(%rip), %rsi    # 0x3cb0e5
movq %rax, %rdi
callq 0x12097f
movq %r15, %rdi
callq 0x120d23
movq %rax, %rdi
callq 0x10415c
xorb $0x1, %al
orb 0x2c(%rsp), %al
cmpb $0x1, %al
jne 0x21c3ce
movq (%r14), %rdi
callq 0x120d23
leaq 0x13253c(%rip), %rsi    # 0x34e669
movq %rax, %rdi
callq 0x178b0
testq %rax, %rax
je 0x21c329
movq %rax, %rbp
movq %r12, %rdi
callq 0x121e78
testq %rax, %rax
je 0x21c349
movq %r15, 0x20(%rsp)
xorl %r15d, %r15d
movq %r12, %rdi
movq %r15, %rsi
callq 0x121cfa
movl $0x2000, %esi           # imm = 0x2000
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
leaq 0x1aee2a(%rip), %rdx    # 0x3cafa3
movq %rax, %rcx
xorl %eax, %eax
callq 0x17c60
movq %rbx, %rdi
leaq 0x147d3c(%rip), %rsi    # 0x363ec9
callq 0x17210
leaq 0x1aee18(%rip), %r13    # 0x3cafb1
testq %rax, %rax
je 0x21c206
movq %rax, %rbx
movq %rax, %rdi
callq 0x17c20
movl %eax, %r14d
shll $0x18, %r14d
cmpl $0xff000000, %r14d      # imm = 0xFF000000
jne 0x21c1ca
movq %rbx, %rdi
callq 0x17a70
leaq 0x1aee0e(%rip), %r13    # 0x3cafd6
jmp 0x21c206
movl %r14d, %eax
sarl $0x18, %eax
movl %eax, %edi
movq %rbp, %rsi
callq 0x17980
movq %rbx, %rdi
callq 0x17c20
shll $0x18, %eax
cmpl $0xff000000, %eax       # imm = 0xFF000000
jne 0x21c1cd
movq %rbx, %rdi
callq 0x17a70
movb $0x1, %bl
leaq 0x1aedd9(%rip), %r13    # 0x3cafd6
cmpl $0xff000000, %r14d      # imm = 0xFF000000
jne 0x21c23a
movq %r12, %rdi
movq %r15, %rsi
callq 0x121cfa
xorl %ebx, %ebx
movq 0x10(%rsp), %rdi
movq %r13, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1019cf
movq 0x8(%rsp), %rax
movq (%rax), %rdi
callq 0x120d23
movq %rax, %rdi
callq 0x21c3ef
testb %bl, %bl
je 0x21c3b1
incq %r15
movq %r12, %rdi
callq 0x121e78
cmpq %rax, %r15
jb 0x21c15a
movq %rbp, %rdi
callq 0x17800
testb %bl, %bl
movq 0x8(%rsp), %r14
movq 0x20(%rsp), %r15
jne 0x21c351
jmp 0x21c3c3
leaq 0x1aec84(%rip), %rsi    # 0x3caf00
movq 0x10(%rsp), %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x1019cf
movq 0x18(%rsp), %rdi
callq 0x121b03
leaq 0x1aeb6b(%rip), %rsi    # 0x3cae07
movq 0x8(%rsp), %rdi
movl $0x60, %edx
jmp 0x21c2d9
leaq 0x1aec66(%rip), %rsi    # 0x3caf15
movq 0x10(%rsp), %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x1019cf
movq 0x18(%rsp), %rdi
callq 0x121b03
leaq 0x1aeb38(%rip), %rsi    # 0x3cae07
movq 0x8(%rsp), %rdi
movl $0x6c, %edx
callq 0x109670
jmp 0x21c321
leaq 0x1aec6a(%rip), %rsi    # 0x3caf51
movq 0x10(%rsp), %rdi
movq %rbp, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x1019cf
movq 0x18(%rsp), %rdi
callq 0x121b03
leaq 0x1aeafd(%rip), %rsi    # 0x3cae07
movq 0x8(%rsp), %rdi
movl $0x7d, %edx
callq 0x109670
movq %rbx, %rdi
callq 0x17800
xorl %r14d, %r14d
jmp 0x21beca
movq (%r14), %rdi
callq 0x120d23
leaq 0x1aec52(%rip), %rsi    # 0x3caf8a
movq 0x10(%rsp), %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1019cf
jmp 0x21c3c3
movq %rbp, %rdi
callq 0x17800
leaq 0x1aecbd(%rip), %rdi    # 0x3cb015
callq 0x120955
movq %rax, %rbx
movq (%r14), %rsi
movq %rax, %rdi
callq 0x120a43
leaq 0x1ad6b3(%rip), %rsi    # 0x3c9a25
movq %rbx, %rdi
callq 0x12097f
movq %rbx, %rdi
callq 0x120d23
movq %rax, %rdi
callq 0x176a0
movl %eax, %ebp
movq %rbx, %rdi
callq 0x121b03
testl $0xff00, %ebp           # imm = 0xFF00
je 0x21c3ce
leaq 0x1aec7f(%rip), %rsi    # 0x3cb022
movq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0x1019cf
jmp 0x21c3c3
movq %rbp, %rdi
callq 0x17800
movq 0x8(%rsp), %r14
movq 0x20(%rsp), %r15
movq %r14, %rdi
callq 0x21c4a1
xorl %r14d, %r14d
movq %r15, %rdi
callq 0x121b03
movq 0x18(%rsp), %rdi
callq 0x121b03
jmp 0x21beca
callq 0x84187
callq 0x84150