// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xc8, %rsp
movb %sil, %al
movq %rdi, 0xb8(%rsp)
andb $0x1, %al
movb %al, 0xb7(%rsp)
movq %rdx, 0xa8(%rsp)
movq %rcx, 0xa0(%rsp)
movq $0x0, 0x90(%rsp)
movq $0x0, 0x88(%rsp)
movq $0x0, 0x70(%rsp)
movb $0x0, 0x67(%rsp)
movb $0x1, 0x66(%rsp)
movq $0x0, 0x58(%rsp)
movq $0x0, 0x50(%rsp)
movq $0x0, 0x48(%rsp)
movq $0x0, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x3c, 0x30(%rsp)
movq 0xb8(%rsp), %rdi
movq 0xa0(%rsp), %r9
leaq 0x2c665a(%rip), %rsi    # 0x517a3d
leaq 0x326afb(%rip), %rdx    # 0x577ee5
leaq 0x328582(%rip), %rcx    # 0x579973
movl $0x1da, %r8d            # imm = 0x1DA
callq 0xd92c0
movq %rax, 0x98(%rsp)
cmpq $0x0, 0x98(%rsp)
jne 0x25141f
movl $0xffffffff, 0xc4(%rsp) # imm = 0xFFFFFFFF
jmp 0x251ba0
testb $0x1, 0xb7(%rsp)
jne 0x251473
movq 0xb8(%rsp), %rdi
movq 0xa0(%rsp), %r9
leaq 0x328549(%rip), %rsi    # 0x579989
leaq 0x2d5756(%rip), %rdx    # 0x526b9d
leaq 0x328525(%rip), %rcx    # 0x579973
movl $0x1e1, %r8d            # imm = 0x1E1
callq 0xd92c0
movq %rax, 0x90(%rsp)
cmpq $0x0, 0x90(%rsp)
jne 0x251471
movb $0x1, 0x67(%rsp)
jmp 0x251473
testb $0x1, 0x67(%rsp)
jne 0x251487
callq 0x11d4a0
movq %rax, 0x88(%rsp)
movq $0x0, 0x68(%rsp)
xorl %eax, %eax
testb $0x1, 0x67(%rsp)
movb %al, 0x27(%rsp)
jne 0x2514bc
movq 0x88(%rsp), %rdi
movq 0x98(%rsp), %rsi
callq 0x11e3a0
cmpl $-0x1, %eax
setne %al
movb %al, 0x27(%rsp)
movb 0x27(%rsp), %al
testb $0x1, %al
jne 0x2514c9
jmp 0x251911
movq 0x88(%rsp), %rdi
callq 0x11dee0
movq %rax, %rsi
movq 0xa0(%rsp), %rdx
leaq 0x78(%rsp), %rdi
callq 0x251bb0
movq %rax, 0x80(%rsp)
cmpq $0x0, 0x80(%rsp)
jne 0x251508
movb $0x1, 0x67(%rsp)
jmp 0x251911
cmpq $0x0, 0x78(%rsp)
jne 0x25154a
movq 0xa0(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x88(%rsp), %rdi
callq 0x11dee0
movq 0x18(%rsp), %rdi
movq %rax, %rdx
leaq 0x328455(%rip), %rsi    # 0x57998e
movb $0x0, %al
callq 0xd88c0
movb $0x1, 0x67(%rsp)
jmp 0x251911
testb $0x1, 0x66(%rsp)
je 0x251712
cmpq $0x7f, 0x78(%rsp)
jbe 0x25159f
movq 0xa0(%rsp), %rdi
movq 0x78(%rsp), %rax
movl %eax, %edx
movq 0x78(%rsp), %rax
movl %eax, %ecx
movq 0x80(%rsp), %r8
movq 0x78(%rsp), %r9
leaq 0x32842c(%rip), %rsi    # 0x5799b3
movl $0x7f, (%rsp)
movb $0x0, %al
callq 0xd88c0
movb $0x1, 0x67(%rsp)
jmp 0x251911
movq 0x78(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rdi
addq $0x1, %rdi
shlq $0x0, %rdi
leaq 0x3283b6(%rip), %rsi    # 0x579973
movl $0x206, %edx            # imm = 0x206
callq 0xe80f0
movq %rax, 0x58(%rsp)
movb $0x0, 0x66(%rsp)
testb $0x1, 0xb7(%rsp)
jne 0x2515f5
movq 0x70(%rsp), %rax
movsbl %al, %edi
movq 0x90(%rsp), %rsi
callq 0x126b70
jmp 0x25170d
cmpq $0xb, 0x70(%rsp)
jbe 0x25163f
movq 0xa0(%rsp), %rdi
movq 0x78(%rsp), %rax
movl %eax, %edx
movq 0x78(%rsp), %rax
movl %eax, %ecx
movq 0x80(%rsp), %r8
movq 0x78(%rsp), %r9
leaq 0x32838c(%rip), %rsi    # 0x5799b3
movl $0xb, (%rsp)
movb $0x0, %al
callq 0xd88c0
movb $0x1, 0x67(%rsp)
jmp 0x251911
callq 0xb7a40
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
movq 0xa8(%rsp), %rsi
callq 0xbacf0
movq 0x28(%rsp), %rdi
movq 0xb8(%rsp), %rsi
movq 0xa0(%rsp), %rdx
callq 0xb7aa0
movq %rax, 0x40(%rsp)
movq 0x28(%rsp), %rdi
callq 0xb7e50
cmpq $0x0, 0x40(%rsp)
jne 0x251696
movb $0x1, 0x67(%rsp)
jmp 0x251911
movq 0x40(%rsp), %rdi
callq 0xa9d50
movq %rax, 0x38(%rsp)
cmpq $0x0, 0x38(%rsp)
ja 0x2516e5
movq 0x3ea8ec(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x2c4955(%rip), %rsi    # 0x516013
leaq 0x328333(%rip), %rdx    # 0x5799f8
leaq 0x32833d(%rip), %rcx    # 0x579a09
leaq 0x3282a0(%rip), %r8     # 0x579973
movl $0x221, %r9d            # imm = 0x221
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x2516e7
imulq $0x18, 0x38(%rsp), %rdi
leaq 0x32827f(%rip), %rsi    # 0x579973
movl $0x222, %edx            # imm = 0x222
callq 0xe80f0
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x48(%rsp)
jmp 0x25180a
movq 0x70(%rsp), %rax
cmpq 0x78(%rsp), %rax
je 0x251762
movq 0xa0(%rsp), %rdi
movq 0x78(%rsp), %rax
movl %eax, %edx
movq 0x78(%rsp), %rax
movl %eax, %ecx
movq 0x80(%rsp), %r8
movq 0x78(%rsp), %r9
movq 0x70(%rsp), %rax
leaq 0x3282d6(%rip), %rsi    # 0x579a23
movq %rax, (%rsp)
movb $0x0, %al
callq 0xd88c0
movb $0x1, 0x67(%rsp)
jmp 0x251911
jmp 0x251764
cmpq $0x0, 0x58(%rsp)
jne 0x2517a4
movq 0x3ea82d(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x2c4896(%rip), %rsi    # 0x516013
leaq 0x32830b(%rip), %rdx    # 0x579a8f
leaq 0x32827e(%rip), %rcx    # 0x579a09
leaq 0x3281e1(%rip), %r8     # 0x579973
movl $0x231, %r9d            # imm = 0x231
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x2517a6
testb $0x1, 0xb7(%rsp)
jne 0x251808
movq 0x58(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq 0x70(%rsp), %rdx
callq 0x192f0
cmpl $0x0, %eax
jl 0x251808
movq 0xa0(%rsp), %rdi
movq 0x58(%rsp), %rdx
movq 0x78(%rsp), %rax
movl %eax, %ecx
movq 0x78(%rsp), %rax
movl %eax, %r8d
movq 0x80(%rsp), %r9
leaq 0x3282ac(%rip), %rsi    # 0x579aa3
movb $0x0, %al
callq 0xd88c0
movb $0x1, 0x67(%rsp)
jmp 0x251911
jmp 0x25180a
testb $0x1, 0xb7(%rsp)
jne 0x251847
movq 0x80(%rsp), %rdi
movq 0x78(%rsp), %rdx
movq 0x90(%rsp), %rcx
movl $0x1, %esi
callq 0x126d30
movq 0x90(%rsp), %rsi
xorl %edi, %edi
callq 0x126b70
jmp 0x2518cc
jmp 0x251849
cmpq $0x0, 0x48(%rsp)
jne 0x251889
movq 0x3ea748(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x2c47b1(%rip), %rsi    # 0x516013
leaq 0x328286(%rip), %rdx    # 0x579aef
leaq 0x328199(%rip), %rcx    # 0x579a09
leaq 0x3280fc(%rip), %r8     # 0x579973
movl $0x247, %r9d            # imm = 0x247
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x25188b
movq 0x48(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq 0x70(%rsp), %rdx
callq 0x19330
movq 0x48(%rsp), %rax
movq 0x70(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x68(%rsp), %rcx
movq 0x48(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x48(%rsp), %rax
addq $0x18, %rax
movq %rax, 0x48(%rsp)
movq 0x58(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq 0x70(%rsp), %rdx
callq 0x19330
movq 0x58(%rsp), %rax
movq 0x70(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x88(%rsp), %rdi
callq 0x11e110
movq 0x68(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x68(%rsp)
jmp 0x251490
testb $0x1, 0x67(%rsp)
jne 0x251938
movq 0xa8(%rsp), %rdi
movq 0x70(%rsp), %rdx
movq 0x68(%rsp), %rcx
leaq 0x3281d0(%rip), %rsi    # 0x579b01
movb $0x0, %al
callq 0xe7cd0
movq 0x88(%rsp), %rdi
callq 0x11f560
movq 0x98(%rsp), %rdi
callq 0xd9390
movq 0x90(%rsp), %rdi
callq 0xd9390
movq 0x58(%rsp), %rdi
leaq 0x328008(%rip), %rsi    # 0x579973
movl $0x25d, %edx            # imm = 0x25D
callq 0xe88c0
testb $0x1, 0x67(%rsp)
jne 0x251b57
testb $0x1, 0xb7(%rsp)
je 0x251b57
jmp 0x251990
cmpq $0x0, 0x48(%rsp)
jne 0x2519d0
movq 0x3ea601(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x2c466a(%rip), %rsi    # 0x516013
leaq 0x32813f(%rip), %rdx    # 0x579aef
leaq 0x328052(%rip), %rcx    # 0x579a09
leaq 0x327fb5(%rip), %r8     # 0x579973
movl $0x260, %r9d            # imm = 0x260
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x2519d2
jmp 0x2519d4
cmpq $0x0, 0x38(%rsp)
ja 0x251a14
movq 0x3ea5bd(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x2c4626(%rip), %rsi    # 0x516013
leaq 0x328004(%rip), %rdx    # 0x5799f8
leaq 0x32800e(%rip), %rcx    # 0x579a09
leaq 0x327f71(%rip), %r8     # 0x579973
movl $0x261, %r9d            # imm = 0x261
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x251a16
jmp 0x251a18
movq 0x48(%rsp), %rax
movq 0x50(%rsp), %rcx
imulq $0x18, 0x38(%rsp), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
je 0x251a68
movq 0x3ea569(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x2c45d2(%rip), %rsi    # 0x516013
leaq 0x3280dc(%rip), %rdx    # 0x579b24
leaq 0x327fba(%rip), %rcx    # 0x579a09
leaq 0x327f1d(%rip), %r8     # 0x579973
movl $0x262, %r9d            # imm = 0x262
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x251a6a
movq 0x50(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl $0x18, %edx
leaq 0x350(%rip), %rcx       # 0x251dd0
callq 0x19e70
cmpq $0x0, 0x48(%rsp)
jne 0x251ac5
movq 0x3ea50c(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x2c4575(%rip), %rsi    # 0x516013
leaq 0x32804a(%rip), %rdx    # 0x579aef
leaq 0x327f5d(%rip), %rcx    # 0x579a09
leaq 0x327ec0(%rip), %r8     # 0x579973
movl $0x264, %r9d            # imm = 0x264
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x251ac7
movq 0x50(%rsp), %rax
movq %rax, 0x48(%rsp)
xorl %eax, %eax
testb $0x1, 0x67(%rsp)
movb %al, 0x17(%rsp)
jne 0x251afb
movq 0x48(%rsp), %rax
movq 0x50(%rsp), %rcx
imulq $0x18, 0x38(%rsp), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
setb %al
movb %al, 0x17(%rsp)
movb 0x17(%rsp), %al
testb $0x1, %al
jne 0x251b05
jmp 0x251b55
movq 0x3ea42c(%rip), %rax    # 0x63bf38
movq (%rax), %rdi
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rdx
movq 0xa0(%rsp), %r9
xorl %eax, %eax
movl %eax, %ecx
movl $0x3c, %r8d
callq 0x251e10
cmpl $0x0, %eax
je 0x251b40
movb $0x1, 0x67(%rsp)
jmp 0x251b55
jmp 0x251b42
movq 0x48(%rsp), %rax
addq $0x18, %rax
movq %rax, 0x48(%rsp)
jmp 0x251ad1
jmp 0x251b57
cmpq $0x0, 0x40(%rsp)
je 0x251b72
movq 0x40(%rsp), %rdi
callq 0xae070
movq $0x0, 0x40(%rsp)
movq 0x50(%rsp), %rdi
leaq 0x327df5(%rip), %rsi    # 0x579973
movl $0x279, %edx            # imm = 0x279
callq 0xe88c0
movb 0x67(%rsp), %dl
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, 0xc4(%rsp)
movl 0xc4(%rsp), %eax
addq $0xc8, %rsp
retq
nop