// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/core/encseq.c
// Function: gt_encseq_generic_write_twobitencoding_to_file
int gt_encseq_generic_write_twobitencoding_to_file(const char *indexname,
                                     GtUword totallength,
                                     GtEncseqAccessType sat,
                                     GtUword lengthofsinglesequence,
                                     GtUword minseqlen,
                                     GtUword maxseqlen,
                                     GtUword lengthofspecialprefix,
                                     GtUword lengthofspecialsuffix,
                                     GtUword lengthoflongestnonspecial,
                                     GtTwobitencoding *twobitencoding,
                                     GtUword numofsequences,
                                     GtUword numoffiles,
                                     const GtFilelengthvalues *filelengthtab,
                                     const GtStrArray *filenametab,
                                     const GtUword *characterdistribution,
                                     GtError *err)
{
  FILE *fp;
  bool haserr = false;
  GtEncseq *encseq = NULL;

  gt_error_check(err);
  fp = gt_fa_fopen_with_suffix(indexname, GT_ENCSEQFILESUFFIX, "wb", err);
  if (fp == NULL)
    haserr = true;
  if (!haserr) {
    GtUword idx;
    Definedunsignedlong equallength;
    GtAlphabet *alphabet = gt_alphabet_new_dna();

    if (lengthofsinglesequence > 0) {
      equallength.defined = true;
      equallength.valueunsignedlong = lengthofsinglesequence;
      gt_assert(sat == GT_ACCESS_TYPE_EQUALLENGTH);
    }
    else {
      equallength.defined = false;
      equallength.valueunsignedlong = 0;
      gt_assert(sat == GT_ACCESS_TYPE_UCHARTABLES ||
                sat == GT_ACCESS_TYPE_USHORTTABLES ||
                sat == GT_ACCESS_TYPE_UINT32TABLES);
    }
    encseq = determineencseqkeyvalues(sat,
                                      totallength,
                                      numofsequences,
                                      numoffiles,
                                      determinelengthofdbfilenames(filenametab),
                                      0, /* wildcardranges */
                                      0, /* exceptionranges */
                                      minseqlen,
                                      maxseqlen,
                                      false, /* oistab */
                                      false,
                                      lengthofsinglesequence > 0
                                        ? &equallength
                                        : NULL,
                                      alphabet,
                                      false,
                                      NULL);
    encseq->twobitencoding = twobitencoding;
    encseq->unitsoftwobitencoding = gt_unitsoftwobitencoding(totallength);
    encseq->numofchars = 4U;
    encseq->maxsubalphasize = 1U;
    gt_assert(numofsequences > 0);
    encseq->filenametab = gt_str_array_new();
    for (idx = 0; idx < gt_str_array_size(filenametab); idx++) {
      gt_str_array_add(encseq->filenametab,
                       gt_str_array_get_str(filenametab, idx));
    }
    encseq->headerptr.filelengthtab
      = gt_malloc((size_t) numoffiles *
                  sizeof (*encseq->headerptr.filelengthtab));
    for (idx = 0; idx < numoffiles; idx++) {
      encseq->headerptr.filelengthtab[idx] = filelengthtab[idx];
    }
    encseq->headerptr.characterdistribution
      = gt_malloc(encseq->numofchars *
                  sizeof (*encseq->headerptr.characterdistribution));
    encseq->numofallchars = 0;
    for (idx = 0; idx < (GtUword) encseq->numofchars; idx++) {
      encseq->headerptr.characterdistribution[idx] = characterdistribution[idx];
      if (encseq->headerptr.characterdistribution[idx] > 0)
        encseq->numofallchars++;
    }
    encseq->specialcharinfo.specialcharacters = numofsequences - 1;
    encseq->specialcharinfo.specialranges = numofsequences - 1;
    encseq->specialcharinfo.realspecialranges = numofsequences - 1;
    encseq->specialcharinfo.lengthofspecialprefix = lengthofspecialprefix;
    encseq->specialcharinfo.lengthofspecialsuffix = lengthofspecialsuffix;
    encseq->specialcharinfo.wildcards = 0UL;
    encseq->specialcharinfo.wildcardranges = 0UL;
    encseq->specialcharinfo.realwildcardranges = 0UL;
    encseq->specialcharinfo.lengthofwildcardprefix = 0UL;
    encseq->specialcharinfo.lengthofwildcardsuffix = 0UL;
    encseq->specialcharinfo.lengthoflongestnonspecial
      = lengthoflongestnonspecial;
    encseq->specialcharinfo.exceptioncharacters = 0UL;
    encseq->specialcharinfo.exceptionranges = 0UL;
    encseq->specialcharinfo.realexceptionranges = 0UL;
    encseq->minseqlen = minseqlen;
    encseq->maxseqlen = maxseqlen;
    alphabet_to_key_values(alphabet, &encseq->alphatype,
                           &encseq->lengthofalphadef,
                           &encseq->alphadef, false);
    encseq->lengthofdbfilenames
      = determinelengthofdbfilenames(encseq->filenametab);
    if (gt_mapspec_write(gt_encseq_assign_mapspec, fp, encseq,
                         encseq->sizeofrep, err) != 0) {
      haserr = true;
    }
    encseq->twobitencoding = NULL;
  }
  if (encseq != NULL)
    gt_encseq_headerptr_delete(&encseq->headerptr);
  gt_encseq_delete(encseq);
  gt_fa_xfclose(fp);
  return haserr ? -1 : 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, 0x18(%rsp)
movq %r8, 0x10(%rsp)
movq %rcx, %rbx
movl %edx, %r14d
movq %rsi, %r12
movq %rdi, %r15
movq 0xb8(%rsp), %r13
testq %r13, %r13
je 0xc17a0
movq %r13, %rdi
callq 0x34fea
testb %al, %al
jne 0xc1b06
leaq 0x40261(%rip), %rsi     # 0x101a08
leaq 0x3f9f8(%rip), %rdx     # 0x1011a6
leaq 0x41165(%rip), %rcx     # 0x10291a
movq %r15, %rdi
movl $0x5e6, %r8d            # imm = 0x5E6
movq %r13, %r9
callq 0x7442f
movq %rax, %r13
testq %rax, %rax
je 0xc1842
movq %r13, 0x30(%rsp)
movq 0xa8(%rsp), %r15
movq 0x98(%rsp), %r13
movq 0x90(%rsp), %rbp
callq 0xba4b2
movq %rax, 0x8(%rsp)
testq %rbx, %rbx
je 0xc184c
movb $0x1, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
cmpl $0x2, %r14d
jne 0xc1b10
movq %r15, %rdi
callq 0xc1ff8
subq $0x8, %rsp
xorl %r10d, %r10d
leaq 0x28(%rsp), %r11
movl $0x2, %edi
movq %r12, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movq %rax, %r8
xorl %r9d, %r9d
pushq %r10
pushq %r10
pushq 0x20(%rsp)
pushq %r11
jmp 0xc1892
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0xc1aed
movb $0x0, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
leal -0x4(%r14), %eax
cmpl $0x2, %eax
ja 0xc1b15
movq %r15, %rdi
callq 0xc1ff8
subq $0x8, %rsp
xorl %r10d, %r10d
movl %r14d, %edi
movq %r12, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movq %rax, %r8
xorl %r9d, %r9d
pushq %r10
pushq %r10
pushq 0x20(%rsp)
pushq %r10
pushq %r10
pushq %r10
pushq 0x50(%rsp)
pushq 0x50(%rsp)
pushq %r10
callq 0xc1b1a
addq $0x50, %rsp
movq %rax, %r14
movq 0x88(%rsp), %rax
movq %rax, 0x280(%r14)
leaq -0x1(%r12), %rax
shrq $0x5, %rax
addq $0x2, %rax
cmpq $0x20, %r12
movl $0x2, %ecx
cmovaeq %rax, %rcx
movq %rcx, 0x288(%r14)
movl $0x4, 0x2a8(%r14)
movb $0x1, 0x360(%r14)
testq %rbp, %rbp
je 0xc1b0b
callq 0x3c8cc
movq %rax, 0x1f8(%r14)
movq %r15, %rdi
callq 0x3cbed
testq %rax, %rax
je 0xc1940
xorl %ebx, %ebx
movq 0x1f8(%r14), %r12
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3caaa
movq %r12, %rdi
movq %rax, %rsi
callq 0x3ca35
incq %rbx
movq %r15, %rdi
callq 0x3cbed
cmpq %rax, %rbx
jb 0xc1913
movq %r13, %rdi
shlq $0x4, %rdi
leaq 0x40fcc(%rip), %rsi     # 0x10291a
movl $0x617, %edx            # imm = 0x617
callq 0x35862
movq %rax, 0xf0(%r14)
testq %r13, %r13
je 0xc1986
movq 0xa0(%rsp), %rax
xorl %ecx, %ecx
movq 0xf0(%r14), %rdx
movups (%rax,%rcx), %xmm0
movups %xmm0, (%rdx,%rcx)
addq $0x10, %rcx
decq %r13
jne 0xc196e
movq 0x80(%rsp), %rbx
movq 0x78(%rsp), %r15
movq 0x70(%rsp), %r13
movl 0x2a8(%r14), %edi
shlq $0x3, %rdi
leaq 0x40f70(%rip), %rsi     # 0x10291a
movl $0x61d, %edx            # imm = 0x61D
callq 0x35862
movq %rax, 0xf8(%r14)
movq $0x0, 0x340(%r14)
movl 0x2a8(%r14), %ecx
testq %rcx, %rcx
je 0xc19f8
movq 0xb0(%rsp), %rdx
xorl %esi, %esi
movq (%rdx,%rsi,8), %rdi
movq %rdi, (%rax,%rsi,8)
testq %rdi, %rdi
je 0xc19f0
incq 0x340(%r14)
incq %rsi
cmpq %rsi, %rcx
jne 0xc19dc
movq 0x30(%rsp), %rax
testq %rax, %rax
sete %r12b
decq %rbp
movq %rbp, 0x178(%r14)
movq %rbp, 0x180(%r14)
movq %rbp, 0x188(%r14)
movq %r13, 0x190(%r14)
movq %rax, %r13
movq %r15, 0x198(%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x1a0(%r14)
movups %xmm0, 0x1b0(%r14)
xorl %r15d, %r15d
movq %r15, 0x1c0(%r14)
movq %rbx, 0x1c8(%r14)
movups %xmm0, 0x1d0(%r14)
movq %r15, 0x1e0(%r14)
movq 0x10(%rsp), %rax
movq %rax, 0x3b0(%r14)
movq 0x18(%rsp), %rax
movq %rax, 0x3b8(%r14)
leaq 0x238(%r14), %rsi
leaq 0x230(%r14), %rdx
leaq 0x228(%r14), %rcx
movq 0x8(%rsp), %rdi
xorl %r8d, %r8d
callq 0xc2042
movq 0x1f8(%r14), %rdi
callq 0xc1ff8
movq %rax, 0x58(%r14)
movq 0x60(%r14), %rcx
leaq 0x661(%rip), %rdi       # 0xc2116
movq %r13, %rsi
movq %r14, %rdx
movq 0xb8(%rsp), %r8
callq 0xd67cb
testl %eax, %eax
setne %bl
orb %r12b, %bl
movq %r15, 0x280(%r14)
leaq 0x70(%r14), %rdi
callq 0xc25d7
movq %r14, %rdi
callq 0xc273d
movzbl %bl, %ebx
negl %ebx
movq %r13, %rdi
callq 0x74532
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2aaaf
callq 0x2ab5a
callq 0x2aae8
callq 0x2ab21