// File: /workspace/github_c_makefile_star2_O3/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 0x2126e4
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r12
testq %rdx, %rdx
je 0x21219f
movq %rbx, %rdi
callq 0xfcc32
testb %al, %al
jne 0x2126e9
leaq 0x1af54e(%rip), %rdi    # 0x3c16f4
callq 0x176a0
testl $0xff00, %eax           # imm = 0xFF00
je 0x2121bb
leaq 0x1af553(%rip), %rsi    # 0x3c170c
jmp 0x2121d5
leaq 0x1af5a0(%rip), %rdi    # 0x3c1762
callq 0x176a0
testl $0xff00, %eax           # imm = 0xFF00
je 0x2121f7
leaq 0x1af5a7(%rip), %rsi    # 0x3c177c
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xfcb67
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, 0x8(%rsp)
leaq 0x1af4d4(%rip), %rdx    # 0x3c16db
movl $0x1, %edi
movl $0x8, %esi
movl $0x59, %ecx
callq 0x10436a
movq %rax, 0x10(%rsp)
callq 0x11ac6c
movq %rax, 0x18(%rsp)
movq %r12, %rdi
callq 0x11c131
testq %rax, %rax
je 0x212372
movabsq $0x6f6e696d41202048, %rax # imm = 0x6F6E696D41202048
xorl %r13d, %r13d
leaq 0x30(%rsp), %r14
addq $0x20000000, %rax       # imm = 0x20000000
movq %rax, 0x20(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x11bfb3
movq %rax, %rbp
movq %rax, %rdi
callq 0xff28c
testb %al, %al
je 0x212590
movq %rbp, %rdi
leaq 0x148bd5(%rip), %rsi    # 0x35ae55
callq 0x178b0
testq %rax, %rax
je 0x2125c3
movq %rax, %rbx
xorl %r15d, %r15d
movq %r14, %rdi
movl $0x2000, %esi           # imm = 0x2000
movq %rbx, %rdx
callq 0x17c30
testq %rax, %rax
je 0x212349
movq %r14, %rdi
callq 0x172f0
incq %r15
cmpq $0x6, %rax
jb 0x212294
cmpl $0x48504c41, 0x30(%rsp) # imm = 0x48504C41
jne 0x212294
cmpq $0xa, %rax
jb 0x2125fb
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 0x212349
movq 0x30(%rsp), %rax
movabsq $0x6d61202048504c41, %rcx # imm = 0x6D61202048504C41
xorq %rcx, %rax
movq 0x33(%rsp), %rcx
xorq 0x20(%rsp), %rcx
orq %rax, %rcx
je 0x212349
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 0x2125fb
movq %rbx, %rdi
callq 0x17800
movq 0x18(%rsp), %rdi
movq %rbp, %rsi
callq 0x11acf3
incq %r13
movq %r12, %rdi
callq 0x11c131
cmpq %rax, %r13
jb 0x212258
callq 0x11ac6c
movq %rax, %rbx
movq 0x10(%rsp), %r14
movq %rax, (%r14)
leaq 0x1c387e(%rip), %rdi    # 0x3d5c07
callq 0x17950
testq %rax, %rax
leaq 0x157c82(%rip), %rsi    # 0x36a01a
cmovneq %rax, %rsi
movq %rbx, %rdi
callq 0x11acf3
movq (%r14), %rdi
movl $0x2f, %esi
callq 0x11af23
movq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x11b0a1
movq %rax, %rbx
movq %r15, %rdi
callq 0x11b0ca
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1068d0
movq %rax, %rbx
movq (%r14), %rdi
movq %rax, %rsi
callq 0x11acf3
leaq 0x1af2f2(%rip), %rsi    # 0x3c16db
movq %rbx, %rdi
movl $0x90, %edx
callq 0x1045eb
movq (%r14), %rdi
callq 0x11b0a1
movq %rax, %rdi
callq 0x11acc9
movq %rax, %rbx
leaq 0x1af5a9(%rip), %rsi    # 0x3c19b9
movq %rax, %rdi
callq 0x11acf3
movq %rbx, %rdi
callq 0x11b0a1
movq %rax, %rdi
callq 0xff28c
xorb $0x1, %al
orb 0x2c(%rsp), %al
cmpb $0x1, %al
jne 0x2126cd
movq (%r14), %rdi
callq 0x11b0a1
leaq 0x133224(%rip), %rsi    # 0x345669
movq %rax, %rdi
callq 0x178b0
testq %rax, %rax
je 0x212644
movq %rax, %rbp
movq %rbx, 0x20(%rsp)
movq %r12, %rdi
callq 0x11c131
testq %rax, %rax
je 0x21251c
leaq 0x30(%rsp), %r14
xorl %ebx, %ebx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x11bfb3
movl $0x2000, %esi           # imm = 0x2000
movq %r14, %rdi
leaq 0x1af3e7(%rip), %rdx    # 0x3c1877
movq %rax, %rcx
xorl %eax, %eax
callq 0x17c60
movq %r14, %rdi
leaq 0x1489b1(%rip), %rsi    # 0x35ae55
callq 0x17210
testq %rax, %rax
je 0x21266b
movq %rax, %r15
movq %rax, %rdi
callq 0x17c20
movl %eax, %r13d
shll $0x18, %r13d
movl %r13d, %eax
cmpl $0xff000000, %r13d      # imm = 0xFF000000
je 0x212674
sarl $0x18, %eax
movl %eax, %edi
movq %rbp, %rsi
callq 0x17980
movq %r15, %rdi
callq 0x17c20
shll $0x18, %eax
cmpl $0xff000000, %eax       # imm = 0xFF000000
jne 0x2124d4
movq %r15, %rdi
callq 0x17a70
cmpl $0xff000000, %r13d      # imm = 0xFF000000
je 0x21267c
incq %rbx
movq %r12, %rdi
callq 0x11c131
cmpq %rax, %rbx
jb 0x212476
movq %rbp, %rdi
callq 0x17800
leaq 0x1af3be(%rip), %rdi    # 0x3c18e9
callq 0x11acc9
movq %rax, %rbx
movq 0x10(%rsp), %r14
movq (%r14), %rsi
movq %rax, %rdi
callq 0x11adc1
leaq 0x1ade4b(%rip), %rsi    # 0x3c0395
movq %rbx, %rdi
callq 0x11acf3
movq %rbx, %rdi
callq 0x11b0a1
movq %rax, %rdi
callq 0x176a0
movl %eax, %ebp
movq %rbx, %rdi
callq 0x11bdbf
testl $0xff00, %ebp           # imm = 0xFF00
je 0x212664
leaq 0x1af377(%rip), %rsi    # 0x3c18f6
movq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0xfcb67
jmp 0x2126bd
leaq 0x1af23d(%rip), %rsi    # 0x3c17d4
movq 0x8(%rsp), %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xfcb67
movq 0x18(%rsp), %rdi
callq 0x11bdbf
leaq 0x1af124(%rip), %rsi    # 0x3c16db
movq 0x10(%rsp), %rdi
movl $0x60, %edx
jmp 0x2125f4
leaq 0x1af21f(%rip), %rsi    # 0x3c17e9
movq 0x8(%rsp), %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xfcb67
movq 0x18(%rsp), %rdi
callq 0x11bdbf
leaq 0x1af0f1(%rip), %rsi    # 0x3c16db
movq 0x10(%rsp), %rdi
movl $0x6c, %edx
callq 0x1045eb
jmp 0x21263c
leaq 0x1af223(%rip), %rsi    # 0x3c1825
movq 0x8(%rsp), %rdi
movq %rbp, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0xfcb67
movq 0x18(%rsp), %rdi
callq 0x11bdbf
leaq 0x1af0b6(%rip), %rsi    # 0x3c16db
movq 0x10(%rsp), %rdi
movl $0x7d, %edx
callq 0x1045eb
movq %rbx, %rdi
callq 0x17800
xorl %r14d, %r14d
jmp 0x2121e2
movq (%r14), %rdi
callq 0x11b0a1
leaq 0x1af20b(%rip), %rsi    # 0x3c185e
movq 0x8(%rsp), %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xfcb67
jmp 0x2126c2
movq 0x20(%rsp), %rbx
jmp 0x2126cd
leaq 0x1af213(%rip), %r14    # 0x3c1885
jmp 0x212683
movq %r15, %rdi
callq 0x17a70
leaq 0x1af227(%rip), %r14    # 0x3c18aa
movq %r12, %rdi
movq %rbx, %rsi
callq 0x11bfb3
movq 0x8(%rsp), %rdi
movq %r14, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0xfcb67
movq 0x10(%rsp), %r14
movq (%r14), %rdi
callq 0x11b0a1
movq %rax, %rdi
callq 0x2126ee
movq %rbp, %rdi
callq 0x17800
movq 0x20(%rsp), %rbx
movq %r14, %rdi
callq 0x2127a0
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x11bdbf
movq 0x18(%rsp), %rdi
callq 0x11bdbf
jmp 0x2121e2
callq 0x8209a
callq 0x82063