// File: /workspace/github_c_makefile_star2_O1/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, %r14
movl %esi, %ebx
movq %rdi, %r13
leaq 0x196931(%rip), %rsi    # 0x34fa25
leaq 0x1f5bc4(%rip), %rdx    # 0x3aecbf
leaq 0x1f75fc(%rip), %rcx    # 0x3b06fe
movl $0x1da, %r8d            # imm = 0x1DA
movq %r9, 0x10(%rsp)
callq 0x101dff
movq %rax, 0x58(%rsp)
testq %rax, %rax
je 0x1b912e
testb %bl, %bl
je 0x1b9138
xorl %r12d, %r12d
movq $0x0, 0x40(%rsp)
jmp 0x1b916c
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x1b95dd
leaq 0x1f75d5(%rip), %rsi    # 0x3b0714
leaq 0x1a59c7(%rip), %rdx    # 0x35eb0d
leaq 0x1f75b1(%rip), %rcx    # 0x3b06fe
movq %r13, %rdi
movl $0x1e1, %r8d            # imm = 0x1E1
movq 0x10(%rsp), %r9
callq 0x101dff
movq %rax, 0x40(%rsp)
testq %rax, %rax
sete %r12b
testb %r12b, %r12b
movl %ebx, 0x1c(%rsp)
movq %r14, 0x60(%rsp)
je 0x1b917f
xorl %r14d, %r14d
jmp 0x1b9187
callq 0x1208f8
movq %rax, %r14
xorl %r15d, %r15d
testb %r12b, %r12b
je 0x1b91c3
xorl %ebp, %ebp
movq $0x0, 0x20(%rsp)
movq $0x0, 0x48(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x0, 0x50(%rsp)
jmp 0x1b9495
movq %r13, 0x68(%rsp)
movb $0x1, %al
movl %eax, 0x2c(%rsp)
movq $0x0, 0x50(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x48(%rsp)
movq $0x0, 0x20(%rsp)
xorl %r15d, %r15d
xorl %ebp, %ebp
movq %r14, %rdi
movq 0x58(%rsp), %rsi
callq 0x120e88
cmpl $-0x1, %eax
je 0x1b9495
movq %r14, %rdi
callq 0x120d23
leaq 0x70(%rsp), %rdi
movq %rax, %rsi
movq 0x10(%rsp), %rdx
callq 0x1b963b
testq %rax, %rax
je 0x1b9457
movq %r14, %r13
movq %r12, %r14
movq 0x70(%rsp), %r12
testq %r12, %r12
je 0x1b9436
movq %rax, %rbx
testb $0x1, 0x2c(%rsp)
je 0x1b92bc
cmpq $0x80, %r12
jae 0x1b945c
leaq 0x1(%r12), %rdi
leaq 0x1f748e(%rip), %rsi    # 0x3b06fe
movl $0x206, %edx            # imm = 0x206
callq 0x1092b2
movq %rax, 0x20(%rsp)
cmpb $0x0, 0x1c(%rsp)
je 0x1b92f9
cmpq $0xc, %r12
jb 0x1b930b
movl $0xb, (%rsp)
xorl %ebp, %ebp
movq 0x10(%rsp), %rdi
leaq 0x1f749d(%rip), %rsi    # 0x3b073e
movl %r12d, %edx
movl %r12d, %ecx
movq %rbx, %r8
movq %r12, %r9
xorl %eax, %eax
callq 0x1019cf
movb $0x1, %r14b
jmp 0x1b9393
cmpq %r12, %rbp
jne 0x1b946c
cmpq $0x0, 0x20(%rsp)
je 0x1b961d
cmpb $0x0, 0x1c(%rsp)
jne 0x1b93a7
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x17330
testl %eax, %eax
js 0x1b93a7
jmp 0x1b95f7
movl %r12d, %edi
movq 0x40(%rsp), %rsi
callq 0x1255d6
jmp 0x1b939c
callq 0xf36ef
movq %rax, %rbp
movq %rax, %rdi
movq 0x60(%rsp), %rsi
callq 0xf6add
movq %rbp, %rdi
movq 0x68(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0xf374b
movq %rbp, %rdi
movq %rax, %rbp
callq 0xf424d
testq %rbp, %rbp
je 0x1b9385
movq %rbp, 0x38(%rsp)
movq %rbp, %rdi
callq 0xec1e8
testq %rax, %rax
je 0x1b9636
movq %rax, 0x50(%rsp)
shlq $0x3, %rax
leaq (%rax,%rax,2), %rdi
leaq 0x1f7392(%rip), %rsi    # 0x3b06fe
movl $0x222, %edx            # imm = 0x222
callq 0x1092b2
movb $0x1, %bpl
movq %rax, 0x48(%rsp)
movq %rax, 0x30(%rsp)
jmp 0x1b9393
movb $0x1, %r14b
movq $0x0, 0x38(%rsp)
xorl %ebp, %ebp
testb %bpl, %bpl
je 0x1b95ec
movl $0x0, 0x2c(%rsp)
movq %r12, %rbp
cmpb $0x0, 0x1c(%rsp)
je 0x1b93df
movq 0x30(%rsp), %r12
testq %r12, %r12
je 0x1b9622
movq %r12, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x17370
movb $0x0, (%r12,%rbp)
movq %r15, 0x10(%r12)
addq $0x18, %r12
movq %r12, 0x30(%rsp)
jmp 0x1b9401
movl $0x1, %esi
movq %rbx, %rdi
movq %r12, %rdx
movq 0x40(%rsp), %r12
movq %r12, %rcx
callq 0x125658
xorl %edi, %edi
movq %r12, %rsi
callq 0x1255d6
movq %r14, %r12
movq 0x20(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x17370
movb $0x0, (%r14,%rbp)
movq %r13, %r14
movq %r13, %rdi
callq 0x120db4
incq %r15
testb $0x1, %r12b
je 0x1b9200
jmp 0x1b9495
movq %r13, %r14
movq %r13, %rdi
callq 0x120d23
leaq 0x1f72d1(%rip), %rsi    # 0x3b0719
movq 0x10(%rsp), %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1019cf
movb $0x1, %r12b
jmp 0x1b9495
movl $0x7f, (%rsp)
leaq 0x1f72d4(%rip), %rsi    # 0x3b073e
jmp 0x1b9477
movq %rbp, (%rsp)
leaq 0x1f7337(%rip), %rsi    # 0x3b07ae
movq 0x10(%rsp), %rdi
movl %r12d, %edx
movl %r12d, %ecx
movq %rbx, %r8
movq %r12, %r9
xorl %eax, %eax
callq 0x1019cf
movb $0x1, %r12b
movq %r13, %r14
movq %r12, 0x10(%rsp)
testb $0x1, %r12b
je 0x1b94e1
movq %r14, %rdi
callq 0x121b03
movq 0x58(%rsp), %rdi
callq 0x101e80
movq 0x40(%rsp), %rdi
callq 0x101e80
leaq 0x1f723b(%rip), %rsi    # 0x3b06fe
movq 0x20(%rsp), %rdi
movl $0x25d, %edx            # imm = 0x25D
callq 0x109670
movq 0x48(%rsp), %r12
movq 0x38(%rsp), %r13
jmp 0x1b95b0
leaq 0x1f73a4(%rip), %rsi    # 0x3b088c
movq 0x60(%rsp), %rdi
movq %rbp, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x10906e
movq %r14, %rdi
callq 0x121b03
movq 0x58(%rsp), %rdi
callq 0x101e80
movq 0x40(%rsp), %rdi
callq 0x101e80
leaq 0x1f71e1(%rip), %rsi    # 0x3b06fe
movq 0x20(%rsp), %rdi
movl $0x25d, %edx            # imm = 0x25D
callq 0x109670
cmpb $0x0, 0x1c(%rsp)
movq 0x48(%rsp), %r12
movq 0x38(%rsp), %r13
je 0x1b95b0
cmpq $0x0, 0x30(%rsp)
je 0x1b9627
movq 0x50(%rsp), %r14
testq %r14, %r14
je 0x1b962c
leaq (%r14,%r14,2), %rax
leaq (%r12,%rax,8), %rbx
cmpq %rbx, 0x30(%rsp)
jne 0x1b9631
leaq 0x181(%rip), %rcx       # 0x1b96f2
movl $0x18, %edx
movq %r12, %rdi
movq %r14, %rsi
callq 0x17f60
testq %r14, %r14
jle 0x1b95b0
movq 0x30a95b(%rip), %r14    # 0x4c3ee8
movq %r12, %r15
movq (%r14), %rdi
movq 0x10(%r15), %rdx
movl $0x3c, %r8d
movq %r13, %rsi
xorl %ecx, %ecx
callq 0x1b96f7
addq $0x18, %r15
cmpq %rbx, %r15
jb 0x1b9590
testq %r13, %r13
je 0x1b95bd
movq %r13, %rdi
callq 0xee90c
leaq 0x1f713a(%rip), %rsi    # 0x3b06fe
movq %r12, %rdi
movl $0x279, %edx            # imm = 0x279
callq 0x109670
movq 0x10(%rsp), %rax
andb $0x1, %al
movzbl %al, %eax
negl %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rbp
movq %r14, %r12
jmp 0x1b9492
leaq 0x1f7230(%rip), %rsi    # 0x3b082e
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %rdx
movl %r12d, %ecx
movl %r12d, %r8d
movq %rbx, %r9
xorl %eax, %eax
callq 0x1019cf
jmp 0x1b948f
callq 0x66595
callq 0x66607
callq 0x666b2
callq 0x66679
callq 0x66640
callq 0x665ce