// File: /workspace/github_c_makefile_star2_O1/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, %r14
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %rbx
movq 0xb8(%rsp), %r12
testq %r12, %r12
je 0xc071a
movq %r12, %rdi
callq 0x3566a
testb %al, %al
jne 0xc0a5f
leaq 0x41373(%rip), %rsi     # 0x101a94
leaq 0x40b0a(%rip), %rdx     # 0x101232
leaq 0x422fb(%rip), %rcx     # 0x102a2a
movq %rbx, %rdi
movl $0x5e6, %r8d            # imm = 0x5E6
movq %r12, %r9
callq 0x73e9b
movq %rax, %rbx
testq %rax, %rax
sete %r12b
je 0xc077f
callq 0xb93b3
movq %rax, 0x8(%rsp)
testq %r14, %r14
movq %rbx, 0x30(%rsp)
movl %r12d, 0x4(%rsp)
je 0xc0786
movb $0x1, 0x20(%rsp)
movq %r14, 0x28(%rsp)
cmpl $0x2, %ebp
jne 0xc0a69
leaq 0x20(%rsp), %rbx
jmp 0xc07a2
xorl %ebp, %ebp
jmp 0xc0a2c
movb $0x0, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
leal -0x4(%rbp), %eax
cmpl $0x3, %eax
jae 0xc0a6e
xorl %ebx, %ebx
movq 0xa8(%rsp), %r12
movq 0x98(%rsp), %r13
movq 0x90(%rsp), %r14
movq %r12, %rdi
callq 0xc0f2f
subq $0x8, %rsp
xorl %r10d, %r10d
movl %ebp, %edi
movq %r15, %rsi
movq %r14, %rdx
movq %r13, %rcx
movq %rax, %r8
xorl %r9d, %r9d
pushq %r10
pushq %r10
pushq 0x20(%rsp)
pushq %rbx
pushq %r10
pushq %r10
pushq 0x50(%rsp)
pushq 0x50(%rsp)
pushq %r10
callq 0xc0a73
addq $0x50, %rsp
movq %rax, %rbp
movq 0x88(%rsp), %rax
movq %rax, 0x280(%rbp)
leaq -0x1(%r15), %rax
shrq $0x5, %rax
addq $0x2, %rax
cmpq $0x20, %r15
movl $0x2, %ecx
cmovaeq %rax, %rcx
movq %rcx, 0x288(%rbp)
movl $0x4, 0x2a8(%rbp)
movb $0x1, 0x360(%rbp)
testq %r14, %r14
je 0xc0a64
callq 0x3d23c
movq %rax, 0x1f8(%rbp)
movq %r12, %rdi
callq 0x3d560
testq %rax, %rax
je 0xc088f
xorl %r15d, %r15d
movq 0x1f8(%rbp), %rbx
movq %r12, %rdi
movq %r15, %rsi
callq 0x3d41d
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3d3a8
incq %r15
movq %r12, %rdi
callq 0x3d560
cmpq %rax, %r15
jb 0xc0862
movq %r13, %rdi
shlq $0x4, %rdi
leaq 0x4218d(%rip), %rsi     # 0x102a2a
movl $0x617, %edx            # imm = 0x617
callq 0x35ee2
movq %rax, 0xf0(%rbp)
testq %r13, %r13
je 0xc08d5
movq 0xa0(%rsp), %rax
xorl %ecx, %ecx
movq 0xf0(%rbp), %rdx
movups (%rax,%rcx), %xmm0
movups %xmm0, (%rdx,%rcx)
addq $0x10, %rcx
decq %r13
jne 0xc08bd
movq 0x80(%rsp), %rbx
movq 0x78(%rsp), %r15
movq 0x70(%rsp), %r12
movl 0x2a8(%rbp), %edi
shlq $0x3, %rdi
leaq 0x42132(%rip), %rsi     # 0x102a2a
movl $0x61d, %edx            # imm = 0x61D
callq 0x35ee2
movq %rax, 0xf8(%rbp)
movq $0x0, 0x340(%rbp)
movl 0x2a8(%rbp), %ecx
testq %rcx, %rcx
movq 0xb8(%rsp), %r13
je 0xc094d
movq 0xb0(%rsp), %rdx
xorl %esi, %esi
movq (%rdx,%rsi,8), %rdi
movq %rdi, (%rax,%rsi,8)
testq %rdi, %rdi
je 0xc0945
incq 0x340(%rbp)
incq %rsi
cmpq %rsi, %rcx
jne 0xc0931
decq %r14
movq %r14, 0x178(%rbp)
movq %r14, 0x180(%rbp)
movq %r14, 0x188(%rbp)
movq %r12, 0x190(%rbp)
movq %r15, 0x198(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x1a0(%rbp)
movups %xmm0, 0x1b0(%rbp)
xorl %r14d, %r14d
movq %r14, 0x1c0(%rbp)
movq %rbx, 0x1c8(%rbp)
movups %xmm0, 0x1d0(%rbp)
movq %r14, 0x1e0(%rbp)
movq 0x10(%rsp), %rax
movq %rax, 0x3b0(%rbp)
movq 0x18(%rsp), %rax
movq %rax, 0x3b8(%rbp)
leaq 0x238(%rbp), %rsi
leaq 0x230(%rbp), %rdx
movq %rbp, %rcx
addq $0x228, %rcx            # imm = 0x228
movq 0x8(%rsp), %rdi
xorl %r8d, %r8d
callq 0xc0f79
movq 0x1f8(%rbp), %rdi
callq 0xc0f2f
movq %rax, 0x58(%rbp)
movq 0x60(%rbp), %rcx
leaq 0x66e(%rip), %rdi       # 0xc1069
movq 0x30(%rsp), %rbx
movq %rbx, %rsi
movq %rbp, %rdx
movq %r13, %r8
callq 0xd60e5
testl %eax, %eax
movl 0x4(%rsp), %eax
movl $0x0, %ecx
movb %al, %cl
movl $0x1, %r12d
cmovel %ecx, %r12d
movq %r14, 0x280(%rbp)
testq %rbp, %rbp
je 0xc0a3a
leaq 0x70(%rbp), %rdi
callq 0xc152a
movq %rbp, %rdi
callq 0xc1690
movq %rbx, %rdi
callq 0x73f9e
movzbl %r12b, %eax
negl %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2ace3
callq 0x2ad8e
callq 0x2ad1c
callq 0x2ad55