// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/match/reads2twobit.c
// Function: gt_reads2twobit_write_encoded
GtTwobitencoding* gt_reads2twobit_write_encoded(GtReads2Twobit *r2t,
    GtUword seqnum, GtTwobitencoding *outputbuffer,
    GtTwobitencoding outputoffset, GtTwobitencoding *lastcodeoffsetptr)
{
  GtUword firstpos, firstcodeidx, lastpos, lastcodeidx, seqlen;
  GtTwobitencoding  inputoffset;

  firstpos = (seqnum == 0)
    ? 0
    : (r2t->seqlen_eqlen > 0)
        ? r2t->seqlen_eqlen * seqnum
        : r2t->seppos[seqnum - 1UL] + 1UL;
  firstcodeidx = GT_DIVBYUNITSIN2BITENC(firstpos);

  lastpos = (r2t->seqlen_eqlen > 0)
    ? r2t->seqlen_eqlen * (seqnum + 1UL) - 1UL
    : r2t->seppos[seqnum];
  lastcodeidx = GT_DIVBYUNITSIN2BITENC(lastpos);

  seqlen = (r2t->seqlen_eqlen > 0)
    ? r2t->seqlen_eqlen
    : lastpos - firstpos + 1UL;

  inputoffset = (GtTwobitencoding)GT_MODBYUNITSIN2BITENC(firstpos);

  if (inputoffset == outputoffset)
  {
    gt_reads2twobit_write_encoded_nocodesshift(r2t, outputbuffer, inputoffset,
        firstcodeidx, lastcodeidx);
    *lastcodeoffsetptr = (GtTwobitencoding)GT_MODBYUNITSIN2BITENC(lastpos + 1);
  }
  else if (inputoffset > outputoffset)
  {
    gt_reads2twobit_write_encoded_leftcodesshift(r2t,
        outputbuffer, inputoffset, outputoffset, firstcodeidx, lastcodeidx);
    *lastcodeoffsetptr = GT_MODBYUNITSIN2BITENC(outputoffset + seqlen);
  }
  else
  {
    gt_reads2twobit_write_encoded_rightcodesshift(r2t,
        outputbuffer, inputoffset, outputoffset, firstcodeidx, lastcodeidx);
    *lastcodeoffsetptr = GT_MODBYUNITSIN2BITENC(outputoffset + seqlen);
  }
  return outputbuffer + GT_DIVBYUNITSIN2BITENC(outputoffset + seqlen);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %r8, %r15
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %r12
testq %rsi, %rsi
je 0x1e6a63
movq 0x48(%rdi), %rcx
testq %rcx, %rcx
je 0x1e6a67
imulq %r12, %rcx
jmp 0x1e6a73
xorl %ecx, %ecx
jmp 0x1e6a73
movq 0x38(%rdi), %rax
movq -0x8(%rax,%r12,8), %rcx
incq %rcx
movq 0x48(%rdi), %rax
testq %rax, %rax
je 0x1e6a88
incq %r12
imulq %rax, %r12
decq %r12
jmp 0x1e6a90
movq 0x38(%rdi), %rdx
movq (%rdx,%r12,8), %r12
movq %rcx, %r8
shrq $0x5, %r8
movq %r12, %rdx
shrq $0x5, %rdx
movq %r12, %r13
subq %rcx, %r13
incq %r13
testq %rax, %rax
cmovneq %rax, %r13
andl $0x1f, %ecx
movq %rcx, %rax
subq %r14, %rax
jne 0x1e6ae2
testq %rcx, %rcx
je 0x1e6ba8
addl %ecx, %ecx
movq 0x10(%rdi), %rax
movq (%rax,%r8,8), %rsi
movq (%rbx), %rax
xorq %rsi, %rax
negb %cl
shrq %cl, %rax
shlq %cl, %rax
xorq %rsi, %rax
jmp 0x1e6bb0
jbe 0x1e6b1a
addq %rax, %rax
testq %r14, %r14
je 0x1e6bd9
leal (%r14,%r14), %esi
movq 0x10(%rdi), %rcx
movq (%rcx,%r8,8), %r10
movl %eax, %ecx
shlq %cl, %r10
movq (%rbx), %r9
xorq %r10, %r9
negb %sil
movl %esi, %ecx
shrq %cl, %r9
shlq %cl, %r9
xorq %r10, %r9
jmp 0x1e6be6
movq %r14, %rax
subq %rcx, %rax
addq %rax, %rax
leal (%r14,%r14), %esi
movq 0x10(%rdi), %rdi
movq (%rdi,%r8,8), %r9
movl %eax, %ecx
shrq %cl, %r9
movq (%rbx), %r10
xorq %r9, %r10
negb %sil
movl %esi, %ecx
shrq %cl, %r10
shlq %cl, %r10
xorq %r9, %r10
movq %r10, (%rbx)
movq (%rdi,%r8,8), %rsi
movq %rax, %rcx
negq %rcx
shlq %cl, %rsi
movq %rsi, 0x8(%rbx)
subq %r8, %rdx
jbe 0x1e6c2e
movl $0x40, %esi
subq %rax, %rsi
movq 0x8(%rbx), %r9
leaq (%rdi,%r8,8), %rdi
addq $0x8, %rdi
xorl %r8d, %r8d
movq (%rdi,%r8,8), %r10
movl %eax, %ecx
shrq %cl, %r10
orq %r9, %r10
movq %r10, 0x8(%rbx,%r8,8)
movq (%rdi,%r8,8), %r9
movl %esi, %ecx
shlq %cl, %r9
movq %r9, 0x10(%rbx,%r8,8)
incq %r8
cmpq %r8, %rdx
jne 0x1e6b7c
jmp 0x1e6c2e
movq 0x10(%rdi), %rax
movq (%rax,%r8,8), %rax
movq %rax, (%rbx)
subq %r8, %rdx
jbe 0x1e6bd4
leaq 0x8(%rbx), %rax
movq 0x10(%rdi), %rcx
leaq (%rcx,%r8,8), %rsi
addq $0x8, %rsi
shlq $0x3, %rdx
movq %rax, %rdi
callq 0x17660
incq %r12
jmp 0x1e6c32
movq 0x10(%rdi), %rcx
movq (%rcx,%r8,8), %r9
movl %eax, %ecx
shlq %cl, %r9
movq %r9, (%rbx)
subq %r8, %rdx
jbe 0x1e6c2e
movl $0x40, %esi
subq %rax, %rsi
movq 0x10(%rdi), %rcx
movq (%rbx), %r9
leaq (%rcx,%r8,8), %rdi
addq $0x8, %rdi
xorl %r8d, %r8d
movq (%rdi,%r8,8), %r10
movl %esi, %ecx
shrq %cl, %r10
orq %r9, %r10
movq %r10, (%rbx,%r8,8)
movq (%rdi,%r8,8), %r9
movl %eax, %ecx
shlq %cl, %r9
movq %r9, 0x8(%rbx,%r8,8)
incq %r8
cmpq %r8, %rdx
jne 0x1e6c08
leaq (%r14,%r13), %r12
andl $0x1f, %r12d
movq %r12, (%r15)
addq %r14, %r13
shrq $0x5, %r13
leaq (%rbx,%r13,8), %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq