// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/match/giextract.c
// Function: gt_extractkeysfromdesfile
int gt_extractkeysfromdesfile(const char *indexname,
                              bool sortkeys,
                              GtLogger *logger,
                              GtError *err)
{
  FILE *fpin, *fpout = NULL;
  GtStr *line = NULL;
  const char *keyptr;
  GtUword keylen, constantkeylen = 0, linenum;/* incorrectorder = 0;*/
  bool haserr = false, firstdesc = true;
  char *previouskey = NULL;
  Fixedsizekey *keytab = NULL, *keytabptr = NULL;
  GtEncseq *encseq = NULL;
  GtUword numofentries = 0;
  const GtUword linewidth = 60UL;

  fpin = gt_fa_fopen_with_suffix(indexname,GT_DESTABFILESUFFIX,"rb",err);
  if (fpin == NULL)
  {
    return -1;
  }
  if (!sortkeys)
  {
    fpout = gt_fa_fopen_with_suffix(indexname,GT_KEYSTABFILESUFFIX,"wb",err);
    if (fpout == NULL)
    {
      haserr = true;
    }
  }
  if (!haserr)
  {
    line = gt_str_new();
  }
  for (linenum = 0; !haserr && gt_str_read_next_line(line, fpin) != EOF;
       linenum++)
  {
    keyptr = desc2key(&keylen,gt_str_get(line),err);
    if (keyptr == NULL)
    {
      haserr = true;
      break;
    }
    if (keylen == 0)
    {
      gt_error_set(err,"key of length 0 in \"%s\" not expected",
                   gt_str_get(line));
      haserr = true;
      break;
    }
    if (firstdesc)
    {
      if (keylen > (GtUword) CHAR_MAX)
      {
        gt_error_set(err,"key \"%*.*s\" of length "GT_WU" not allowed; "
                         "no key must be larger than %d",
                          (int) keylen,(int) keylen,keyptr,keylen,CHAR_MAX);
        haserr = true;
        break;
      }
      constantkeylen = keylen;
      previouskey = gt_malloc(sizeof (char) * (constantkeylen+1));
      firstdesc = false;
      if (!sortkeys)
      {
        gt_xfputc((char) constantkeylen,fpout);
      } else
      {
        GtEncseqLoader *el;
        if (constantkeylen > (GtUword) MAXFIXEDKEYSIZE)
        {
          gt_error_set(err,"key \"%*.*s\" of length "GT_WU" not allowed; "
                           "no key must be larger than %d",
                            (int) keylen,(int) keylen,keyptr,keylen,
                            MAXFIXEDKEYSIZE);
          haserr = true;
          break;
        }
        el = gt_encseq_loader_new();
        gt_encseq_loader_set_logger(el, logger);
        encseq = gt_encseq_loader_load(el, indexname, err);
        gt_encseq_loader_delete(el);
        if (encseq == NULL)
        {
          haserr = true;
          break;
        }
        numofentries = gt_encseq_num_of_sequences(encseq);
        gt_assert(numofentries > 0);
        keytab = gt_malloc(sizeof (*keytab) * numofentries);
        keytabptr = keytab;
      }
    } else
    {
      if (constantkeylen != keylen)
      {
        gt_error_set(err,"key \"%*.*s\" of length "GT_WU": all keys must be of "
                         "the same length which for all previously seen "
                         "headers is "GT_WU"",
                         (int) keylen,(int) keylen,keyptr,keylen,
                         constantkeylen);
        haserr = true;
        break;
      }
      gt_assert(previouskey != NULL);
      if (!sortkeys && strncmp(previouskey,keyptr,(size_t) constantkeylen) >= 0)
      {
        gt_error_set(err,"previous key \"%s\" is not lexicographically smaller "
                         "than current key \"%*.*s\"",
                         previouskey,(int) keylen,(int) keylen,keyptr);
        haserr = true;
        break;
        /*
        printf("previous key \"%s\" (no "GT_WU") is lexicographically larger "
               "than current key \"%*.*s\"\n",
               previouskey,linenum,(int) keylen,(int) keylen,keyptr);
        incorrectorder++;
        */
      }
    }
    if (!sortkeys)
    {
      gt_xfwrite(keyptr,sizeof *keyptr,(size_t) keylen,fpout);
      gt_xfputc('\0',fpout);
    } else
    {
      gt_assert(keytabptr != NULL);
      strncpy(keytabptr->key,keyptr,(size_t) constantkeylen);
      keytabptr->key[constantkeylen] = '\0';
      keytabptr->seqnum = linenum;
      keytabptr++;
    }
    strncpy(previouskey,keyptr,(size_t) constantkeylen);
    previouskey[constantkeylen] = '\0';
    gt_str_reset(line);
  }
  if (!haserr)
  {
    gt_logger_log(logger,"number of keys of length "GT_WU" = "GT_WU"",
                constantkeylen,linenum);
    /*
    gt_logger_log(logger,"number of incorrectly ordered keys = "GT_WU"",
                incorrectorder);
    */
  }
  gt_str_delete(line);
  gt_fa_fclose(fpin);
  gt_fa_fclose(fpout);
  gt_free(previouskey);
  if (!haserr && sortkeys)
  {
    gt_assert(keytabptr != NULL);
    gt_assert(numofentries > 0);
    gt_assert(keytabptr == keytab + numofentries);
    qsort(keytab,(size_t) numofentries,sizeof (*keytab),compareFixedkeys);
    gt_assert(keytabptr != NULL);
    for (keytabptr = keytab; !haserr && keytabptr < keytab + numofentries;
         keytabptr++)
    {
      if (giextract_encodedseq2fasta(stdout,
                                     encseq,
                                     keytabptr->seqnum,
                                     NULL,
                                     linewidth,
                                     err) != 0)
      {
        haserr = true;
        break;
      }
    }
  }
  if (encseq != NULL)
  {
    gt_encseq_delete(encseq);
    encseq = NULL;
  }
  gt_free(keytab);
  return haserr ? -1 : 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rcx, %r9
movq %rdx, 0x58(%rsp)
movl %esi, %ebx
movq %rdi, %r14
leaq 0x196477(%rip), %rsi    # 0x346a25
leaq 0x1f5168(%rip), %rdx    # 0x3a571d
leaq 0x1f6b86(%rip), %rcx    # 0x3a7142
movl $0x1da, %r8d            # imm = 0x1DA
movq %r9, 0x30(%rsp)
callq 0xfcf97
movq %rax, 0x48(%rsp)
testq %rax, %rax
je 0x1b05de
testb %bl, %bl
je 0x1b05e8
xorl %eax, %eax
jmp 0x1b0619
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x1b0ab9
leaq 0x1f6b69(%rip), %rsi    # 0x3a7158
leaq 0x1a54eb(%rip), %rdx    # 0x355ae1
leaq 0x1f6b45(%rip), %rcx    # 0x3a7142
movq %r14, %rdi
movl $0x1e1, %r8d            # imm = 0x1E1
movq 0x30(%rsp), %r9
callq 0xfcf97
testq %rax, %rax
je 0x1b097a
movl %ebx, 0x3c(%rsp)
movq %rax, 0x20(%rsp)
callq 0x11ac6c
movq %rax, %r13
movq %rax, %rdi
movq 0x48(%rsp), %rsi
callq 0x11b1ff
cmpl $-0x1, %eax
je 0x1b0867
movq %r14, 0x68(%rsp)
movb $0x1, %bl
movq $0x0, 0x40(%rsp)
xorl %r14d, %r14d
xorl %ebp, %ebp
movq $0x0, 0x10(%rsp)
xorl %r15d, %r15d
movq $0x0, 0x18(%rsp)
movq $0x0, 0x50(%rsp)
movq %r13, 0x28(%rsp)
movq %r13, %rdi
callq 0x11b0a1
leaq 0x70(%rsp), %rdi
movq %rax, %rsi
movq 0x30(%rsp), %rdx
callq 0x1b0ae8
testq %rax, %rax
je 0x1b0a17
movq 0x70(%rsp), %r12
testq %r12, %r12
je 0x1b098c
movq %rax, %r13
testb $0x1, %bl
je 0x1b076c
cmpq $0x80, %r12
jae 0x1b09e8
leaq 0x1(%r12), %rdi
leaq 0x1f6a74(%rip), %rsi    # 0x3a7142
movl $0x206, %edx            # imm = 0x206
callq 0x104226
cmpb $0x0, 0x3c(%rsp)
je 0x1b07bb
movq %rax, %rbp
cmpq $0xc, %r12
jae 0x1b09f1
callq 0xef0cd
movq %rax, %r15
movq %rax, %rdi
movq 0x58(%rsp), %rsi
callq 0xf249c
movq %r15, %rdi
movq 0x68(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0xef129
movq %rax, %rbx
movq %r15, %rdi
callq 0xefbe3
testq %rbx, %rbx
je 0x1b0a53
movq %rbx, 0x18(%rsp)
movq %rbx, %rdi
callq 0xe7bac
testq %rax, %rax
je 0x1b0ad4
movq %rax, 0x50(%rsp)
shlq $0x3, %rax
leaq (%rax,%rax,2), %rdi
leaq 0x1f69ed(%rip), %rsi    # 0x3a7142
movl $0x222, %edx            # imm = 0x222
callq 0x104226
movq %rax, %r15
movq %rax, 0x10(%rsp)
movq %rbp, %rbx
jmp 0x1b0790
movq 0x40(%rsp), %rdx
cmpq %r12, %rdx
movq %rbp, %rbx
jne 0x1b09c3
testq %rbx, %rbx
je 0x1b0aca
cmpb $0x0, 0x3c(%rsp)
je 0x1b07d8
movq %rdx, %r12
testq %r15, %r15
je 0x1b0acf
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x17370
movb $0x0, (%r15,%r12)
movq %r14, 0x10(%r15)
addq $0x18, %r15
movq %r12, 0x40(%rsp)
jmp 0x1b0827
movq %r15, 0x60(%rsp)
movq %rax, %rbp
movl %r12d, %edi
movq 0x20(%rsp), %rbx
movq %rbx, %rsi
callq 0x11f81a
movq %r12, %r15
jmp 0x1b07fa
movq %rbx, %rdi
movq %r13, %rsi
callq 0x17330
testl %eax, %eax
jns 0x1b0a23
movq %r15, 0x60(%rsp)
movq 0x20(%rsp), %rbx
movq 0x40(%rsp), %r15
movl $0x1, %esi
movq %r13, %rdi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x11f89c
xorl %edi, %edi
movq %rbx, %rsi
callq 0x11f81a
movq %r15, 0x40(%rsp)
movq %r15, %r12
movq %rbp, %rbx
movq 0x60(%rsp), %r15
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x17370
movq %rbx, %rbp
movb $0x0, (%rbx,%r12)
movq 0x28(%rsp), %r13
movq %r13, %rdi
callq 0x11b132
incq %r14
movq %r13, %rdi
movq 0x48(%rsp), %rsi
callq 0x11b1ff
xorl %ebx, %ebx
cmpl $-0x1, %eax
jne 0x1b0678
jmp 0x1b088d
movq $0x0, 0x50(%rsp)
movq $0x0, 0x18(%rsp)
xorl %r15d, %r15d
movq $0x0, 0x10(%rsp)
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %r12d, %r12d
leaq 0x1f6a3c(%rip), %rsi    # 0x3a72d0
movq 0x58(%rsp), %rdi
movq %r12, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x103fe1
movq %r13, %rdi
callq 0x11bdbf
movq 0x48(%rsp), %rdi
callq 0xfd018
movq 0x20(%rsp), %rdi
callq 0xfd018
leaq 0x1f6879(%rip), %rsi    # 0x3a7142
movq %rbp, %rdi
movl $0x25d, %edx            # imm = 0x25D
callq 0x1045eb
cmpb $0x0, 0x3c(%rsp)
je 0x1b0969
testq %r15, %r15
movl $0x0, %ebp
je 0x1b0ad9
movq 0x50(%rsp), %rbx
testq %rbx, %rbx
movq 0x10(%rsp), %r12
je 0x1b0ade
leaq (%rbx,%rbx,2), %rax
leaq (%r12,%rax,8), %rax
cmpq %rax, %r15
movq 0x18(%rsp), %r13
jne 0x1b0ae3
leaq 0x266(%rip), %rcx       # 0x1b0b85
movl $0x18, %edx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x17f60
testq %rbx, %rbx
jle 0x1b0a98
movq 0x308599(%rip), %rbx    # 0x4b8ed8
movq %r12, %r14
movq (%rbx), %rdi
movq 0x10(%r14), %rdx
xorl %ebp, %ebp
movl $0x3c, %r8d
movq %r13, %rsi
xorl %ecx, %ecx
callq 0x1b0b8a
addq $0x18, %r14
cmpq %r15, %r14
jb 0x1b0942
jmp 0x1b0a98
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %r13
xorl %ebp, %ebp
jmp 0x1b0a98
xorl %r14d, %r14d
xorl %ebx, %ebx
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %ebp, %ebp
jmp 0x1b0a65
movq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x11b0a1
leaq 0x1f67bd(%rip), %rsi    # 0x3a715d
movq 0x30(%rsp), %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xfcb67
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %r13
movq 0x20(%rsp), %rbx
jmp 0x1b0a65
movq %rdx, (%rsp)
leaq 0x1f6824(%rip), %rsi    # 0x3a71f2
movq 0x30(%rsp), %rdi
movl %r12d, %edx
movl %r12d, %ecx
movq %r13, %r8
movq %r12, %r9
xorl %eax, %eax
callq 0xfcb67
jmp 0x1b0a44
movl $0x7f, (%rsp)
jmp 0x1b09f8
movl $0xb, (%rsp)
leaq 0x1f6783(%rip), %rsi    # 0x3a7182
movq 0x30(%rsp), %rdi
movl %r12d, %edx
movl %r12d, %ecx
movq %r13, %r8
movq %r12, %r9
xorl %eax, %eax
callq 0xfcb67
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %r13
jmp 0x1b0a5b
leaq 0x1f6848(%rip), %rsi    # 0x3a7272
movq 0x30(%rsp), %rdi
movq %rbx, %rdx
movq 0x40(%rsp), %rcx
movl %ecx, %r8d
movq %r13, %r9
xorl %eax, %eax
callq 0xfcb67
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %r13
movq %rbx, %rbp
jmp 0x1b0a5b
xorl %r13d, %r13d
movq 0x10(%rsp), %r12
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x11bdbf
movq 0x48(%rsp), %rdi
callq 0xfd018
movq %rbx, %rdi
callq 0xfd018
leaq 0x1f66bc(%rip), %rsi    # 0x3a7142
movq %rbp, %rdi
movl $0x25d, %edx            # imm = 0x25D
callq 0x1045eb
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %r13, %r13
je 0x1b0aa5
movq %r13, %rdi
callq 0xea375
leaq 0x1f6696(%rip), %rsi    # 0x3a7142
movq %r12, %rdi
movl $0x279, %edx            # imm = 0x279
callq 0x1045eb
movl %ebp, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x64dd6
callq 0x64e0f
callq 0x64e48
callq 0x64ef3
callq 0x64eba
callq 0x64e81