// File: /workspace/github_c_makefile_star2_O2/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, 0x60(%rsp)
movl %esi, %ebx
leaq 0x188c62(%rip), %rsi    # 0x2e6a25
leaq 0x1e7cd3(%rip), %rdx    # 0x345a9d
leaq 0x1e96f1(%rip), %rcx    # 0x3474c2
movq %rdi, 0x68(%rsp)
movl $0x1da, %r8d            # imm = 0x1DA
movq %r9, 0x38(%rsp)
callq 0x8a449
movq %rax, 0x50(%rsp)
testq %rax, %rax
je 0x15ddfc
testb %bl, %bl
movl %ebx, 0x4c(%rsp)
je 0x15de04
xorl %eax, %eax
jmp 0x15de37
pushq $-0x1
popq %rax
jmp 0x15e297
leaq 0x1e96cd(%rip), %rsi    # 0x3474d8
leaq 0x197cdf(%rip), %rdx    # 0x2f5af1
leaq 0x1e96a9(%rip), %rcx    # 0x3474c2
movq 0x68(%rsp), %rdi
movl $0x1e1, %r8d            # imm = 0x1E1
movq 0x38(%rsp), %r9
callq 0x8a449
testq %rax, %rax
je 0x15e06f
movq %rax, 0x18(%rsp)
movl $0x0, 0x14(%rsp)
callq 0xacb84
movq %rax, %r12
movb $0x1, %bpl
xorl %r13d, %r13d
xorl %r14d, %r14d
movq $0x0, 0x40(%rsp)
movq $0x0, 0x20(%rsp)
xorl %r15d, %r15d
movq $0x0, 0x28(%rsp)
movq $0x0, 0x58(%rsp)
movq %r12, 0x30(%rsp)
cmpb $0x0, 0x14(%rsp)
jne 0x15e05c
movq %r12, %rdi
movq 0x50(%rsp), %rsi
callq 0xad4de
cmpl $-0x1, %eax
je 0x15e086
movq %r12, %rdi
callq 0xad1fa
leaq 0x70(%rsp), %rdi
movq %rax, %rsi
movq 0x38(%rsp), %rdx
callq 0x15e3c7
testq %rax, %rax
je 0x15e215
movq 0x70(%rsp), %rbx
testq %rbx, %rbx
je 0x15e14c
movq %rax, %r12
testb $0x1, %bpl
je 0x15df96
cmpq $0x80, %rbx
movq 0x28(%rsp), %r13
jae 0x15e1a2
leaq 0x1(%rbx), %rdi
leaq 0x1e95c5(%rip), %rsi    # 0x3474c2
movl $0x206, %edx            # imm = 0x206
callq 0x93160
movq %rax, 0x40(%rsp)
cmpb $0x0, 0x4c(%rsp)
je 0x15dfde
cmpq $0xc, %rbx
jae 0x15e1ce
callq 0x791cd
movq %rax, %r15
movq %rax, %rdi
movq 0x60(%rsp), %rsi
callq 0x7d487
movq %r15, %rdi
movq 0x68(%rsp), %rsi
movq 0x38(%rsp), %rdx
callq 0x7921d
movq %rax, %r13
movq %r15, %rdi
callq 0x79f01
testq %r13, %r13
je 0x15e227
movq %r13, 0x28(%rsp)
movq %r13, %rdi
callq 0x705a1
testq %rax, %rax
je 0x15e302
movq %rax, 0x58(%rsp)
imulq $0x18, %rax, %rdi
leaq 0x1e9540(%rip), %rsi    # 0x3474c2
movl $0x222, %edx            # imm = 0x222
callq 0x93160
movq %rax, %r15
movq %rax, 0x20(%rsp)
jmp 0x15dfb5
cmpq %rbx, %r13
jne 0x15e1ab
cmpq $0x0, 0x40(%rsp)
je 0x15e2a6
cmpb $0x0, 0x4c(%rsp)
je 0x15dff2
movq %r13, %rbx
testq %r15, %r15
je 0x15e2d4
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x17350
movb $0x0, (%r15,%rbx)
movq %r14, 0x10(%r15)
addq $0x18, %r15
movq %rbx, %r13
jmp 0x15e02d
movl %ebx, %edi
movq 0x18(%rsp), %rbp
movq %rbp, %rsi
callq 0xb2f2e
movq %rbx, %r13
jmp 0x15e00f
movq 0x40(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x17310
testl %eax, %eax
jns 0x15e1f4
movq 0x18(%rsp), %rbp
movq %r12, %rdi
pushq $0x1
popq %rsi
movq %rbx, %rdx
movq %rbp, %rcx
callq 0xb302c
xorl %edi, %edi
movq %rbp, %rsi
callq 0xb2f2e
movq %r13, %rbx
movq 0x40(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x17350
movb $0x0, (%rbp,%rbx)
movq 0x30(%rsp), %r12
movq %r12, %rdi
callq 0xad357
incq %r14
xorl %ebp, %ebp
jmp 0x15de81
xorl %ebx, %ebx
xorl %r13d, %r13d
movq $0x0, 0x40(%rsp)
jmp 0x15e17f
movb $0x1, %al
movl %eax, 0x14(%rsp)
movq $0x0, 0x18(%rsp)
xorl %r12d, %r12d
jmp 0x15de4c
leaq 0x1e95c3(%rip), %rsi    # 0x347650
movq 0x60(%rsp), %rdi
movq %r13, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x92e71
movq %r12, %rdi
callq 0xae103
movq 0x50(%rsp), %rdi
callq 0x8a4fd
movq 0x18(%rsp), %rdi
callq 0x8a4fd
leaq 0x1e9400(%rip), %rsi    # 0x3474c2
movq 0x40(%rsp), %rdi
movl $0x25d, %edx            # imm = 0x25D
callq 0x936f9
cmpb $0x0, 0x4c(%rsp)
je 0x15e189
testq %r15, %r15
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %r13
je 0x15e33a
movq 0x58(%rsp), %rsi
testq %rsi, %rsi
je 0x15e368
imulq $0x18, %rsi, %rax
addq %rbx, %rax
cmpq %rax, %r15
jne 0x15e396
leaq 0x40d(%rip), %rcx       # 0x15e521
pushq $0x18
popq %rdx
movq %rbx, %rdi
callq 0x17ed0
movq %rbx, %r12
movq 0x2d9d87(%rip), %r14    # 0x437eb0
pushq $0x3c
popq %rbx
cmpq %r15, %r12
jae 0x15e198
movq (%r14), %rdi
movq 0x10(%r12), %rdx
movq %r13, %rsi
xorl %ecx, %ecx
movq %rbx, %r8
callq 0x15e526
addq $0x18, %r12
jmp 0x15e12c
movq 0x30(%rsp), %r12
movq %r12, %rdi
callq 0xad1fa
leaq 0x1e937d(%rip), %rsi    # 0x3474dd
movq 0x38(%rsp), %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x89dbb
movb $0x1, %al
movl %eax, 0x14(%rsp)
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %r13
movq 0x18(%rsp), %r14
jmp 0x15e23f
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %r13
jmp 0x15e26f
movq 0x20(%rsp), %rbx
jmp 0x15e26f
movl $0x7f, (%rsp)
jmp 0x15e1d5
movq %r13, (%rsp)
leaq 0x1e93bc(%rip), %rsi    # 0x347572
movq 0x38(%rsp), %rdi
movl %ebx, %edx
movl %ebx, %ecx
movq %r12, %r8
movq %rbx, %r9
xorl %eax, %eax
callq 0x89dbb
jmp 0x15e215
movl $0xb, (%rsp)
leaq 0x1e9326(%rip), %rsi    # 0x347502
movq 0x38(%rsp), %rdi
movl %ebx, %edx
movl %ebx, %ecx
movq %r12, %r8
movq %rbx, %r9
xorl %eax, %eax
callq 0x89dbb
jmp 0x15e22a
leaq 0x1e93f7(%rip), %rsi    # 0x3475f2
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rdx
movl %r13d, %ecx
movl %r13d, %r8d
movq %r12, %r9
xorl %eax, %eax
callq 0x89dbb
movb $0x1, %al
movl %eax, 0x14(%rsp)
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %r13
jmp 0x15e235
xorl %r13d, %r13d
movb $0x1, %al
movl %eax, 0x14(%rsp)
movq 0x20(%rsp), %rbx
movq 0x18(%rsp), %r14
movq 0x30(%rsp), %r12
movq %r12, %rdi
callq 0xae103
movq 0x50(%rsp), %rdi
callq 0x8a4fd
movq %r14, %rdi
callq 0x8a4fd
leaq 0x1e9262(%rip), %rsi    # 0x3474c2
movq 0x40(%rsp), %rdi
movl $0x25d, %edx            # imm = 0x25D
callq 0x936f9
testq %r13, %r13
je 0x15e27c
movq %r13, %rdi
callq 0x735fd
leaq 0x1e923f(%rip), %rsi    # 0x3474c2
movq %rbx, %rdi
movl $0x279, %edx            # imm = 0x279
callq 0x936f9
movzbl 0x14(%rsp), %eax
negl %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2d9cbb(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x186d5c(%rip), %rsi    # 0x2e5013
leaq 0x1e9320(%rip), %rdx    # 0x3475de
leaq 0x1e9293(%rip), %rcx    # 0x347558
leaq 0x1e91f6(%rip), %r8     # 0x3474c2
movl $0x231, %r9d            # imm = 0x231
jmp 0x15e32e
movq 0x2d9c8d(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x186d2e(%rip), %rsi    # 0x2e5013
leaq 0x1e9352(%rip), %rdx    # 0x34763e
leaq 0x1e9265(%rip), %rcx    # 0x347558
leaq 0x1e91c8(%rip), %r8     # 0x3474c2
movl $0x247, %r9d            # imm = 0x247
jmp 0x15e32e
movq 0x2d9c5f(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x186d00(%rip), %rsi    # 0x2e5013
leaq 0x1e922d(%rip), %rdx    # 0x347547
leaq 0x1e9237(%rip), %rcx    # 0x347558
leaq 0x1e919a(%rip), %r8     # 0x3474c2
movl $0x221, %r9d            # imm = 0x221
xorl %eax, %eax
callq 0x17a50
callq 0x17390
movq 0x2d9c27(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x186cc8(%rip), %rsi    # 0x2e5013
leaq 0x1e92ec(%rip), %rdx    # 0x34763e
leaq 0x1e91ff(%rip), %rcx    # 0x347558
leaq 0x1e9162(%rip), %r8     # 0x3474c2
movl $0x260, %r9d            # imm = 0x260
jmp 0x15e32e
movq 0x2d9bf9(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x186c9a(%rip), %rsi    # 0x2e5013
leaq 0x1e91c7(%rip), %rdx    # 0x347547
leaq 0x1e91d1(%rip), %rcx    # 0x347558
leaq 0x1e9134(%rip), %r8     # 0x3474c2
movl $0x261, %r9d            # imm = 0x261
jmp 0x15e32e
movq 0x2d9bcb(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x186c6c(%rip), %rsi    # 0x2e5013
leaq 0x1e92c5(%rip), %rdx    # 0x347673
leaq 0x1e91a3(%rip), %rcx    # 0x347558
leaq 0x1e9106(%rip), %r8     # 0x3474c2
movl $0x262, %r9d            # imm = 0x262
jmp 0x15e32e