// File: /workspace/github_c_makefile_star2_O3/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, %r14
movq %rcx, %r15
movq %rdx, %rbx
movq %rsi, %r12
movq 0x48(%rdi), %rax
testq %rsi, %rsi
je 0x1dd221
testq %rax, %rax
je 0x1dd241
movq %rax, %rcx
imulq %r12, %rcx
movq %rcx, %r8
shrq $0x5, %r8
jmp 0x1dd233
xorl %r8d, %r8d
movl $0x0, %ecx
movl $0x0, %edx
testq %rax, %rax
je 0x1dd254
incq %r12
imulq %rax, %r12
decq %r12
xorl %esi, %esi
jmp 0x1dd264
movq 0x38(%rdi), %rax
movq -0x8(%rax,%r12,8), %rdx
incq %rdx
movq %rdx, %r8
shrq $0x5, %r8
movq 0x38(%rdi), %rax
movq (%rax,%r12,8), %r12
movb $0x1, %sil
xorl %eax, %eax
movq %rdx, %rcx
movq %r12, %rdx
shrq $0x5, %rdx
movq %r12, %r13
subq %rcx, %r13
incq %r13
testb %sil, %sil
cmoveq %rax, %r13
andl $0x1f, %ecx
movq %rcx, %rax
subq %r15, %rax
jne 0x1dd2b1
testq %r15, %r15
je 0x1dd373
leal (%r15,%r15), %ecx
movq 0x10(%rdi), %rax
movq (%rax,%r8,8), %rdi
movq (%rbx), %rsi
xorq %rdi, %rsi
negb %cl
shrq %cl, %rsi
shlq %cl, %rsi
xorq %rdi, %rsi
jmp 0x1dd37b
jbe 0x1dd2e9
addq %rax, %rax
testq %r15, %r15
je 0x1dd3a7
leal (%r15,%r15), %esi
movq 0x10(%rdi), %r9
movq (%r9,%r8,8), %r10
movl %eax, %ecx
shlq %cl, %r10
movq (%rbx), %rdi
xorq %r10, %rdi
negb %sil
movl %esi, %ecx
shrq %cl, %rdi
shlq %cl, %rdi
xorq %r10, %rdi
jmp 0x1dd3b4
movq 0x10(%rdi), %rdi
movq %r15, %rax
subq %rcx, %rax
addq %rax, %rax
leal (%r15,%r15), %esi
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), %r9
movq %rax, %rcx
negq %rcx
shlq %cl, %r9
movq %r9, 0x8(%rbx)
subq %r8, %rdx
jbe 0x1dd3f5
movl $0x40, %esi
subq %rax, %rsi
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 0x1dd347
jmp 0x1dd3f5
movq 0x10(%rdi), %rax
movq (%rax,%r8,8), %rsi
movq %rsi, (%rbx)
subq %r8, %rdx
jbe 0x1dd398
leaq 0x8(%rbx), %rdi
leaq (%rax,%r8,8), %rsi
addq $0x8, %rsi
shlq $0x3, %rdx
callq 0x17660
incl %r12d
andl $0x1f, %r12d
movq %r12, (%r14)
addq %r15, %r13
jmp 0x1dd401
movq 0x10(%rdi), %r9
movq (%r9,%r8,8), %rdi
movl %eax, %ecx
shlq %cl, %rdi
movq %rdi, (%rbx)
subq %r8, %rdx
jbe 0x1dd3f5
movl $0x40, %esi
subq %rax, %rsi
leaq (%r9,%r8,8), %r8
addq $0x8, %r8
xorl %r9d, %r9d
movq (%r8,%r9,8), %r10
movl %esi, %ecx
shrq %cl, %r10
orq %rdi, %r10
movq %r10, (%rbx,%r9,8)
movq (%r8,%r9,8), %rdi
movl %eax, %ecx
shlq %cl, %rdi
movq %rdi, 0x8(%rbx,%r9,8)
incq %r9
cmpq %r9, %rdx
jne 0x1dd3cf
addq %r15, %r13
movl %r13d, %eax
andl $0x1f, %eax
movq %rax, (%r14)
shrq $0x5, %r13
leaq (%rbx,%r13,8), %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq