// File: /workspace/github_c_makefile_star2_O2/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 0x18aaaa
testq %rax, %rax
je 0x18aaca
movq %rax, %rcx
imulq %r12, %rcx
movq %rcx, %r9
shrq $0x5, %r9
jmp 0x18aabc
xorl %r9d, %r9d
movl $0x0, %ecx
movl $0x0, %edx
testq %rax, %rax
je 0x18aadd
incq %r12
imulq %rax, %r12
decq %r12
xorl %esi, %esi
jmp 0x18aaed
movq 0x38(%rdi), %rax
movq -0x8(%rax,%r12,8), %rdx
incq %rdx
movq %rdx, %r9
shrq $0x5, %r9
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 0x18ab3a
testq %r15, %r15
je 0x18abf2
leal (%r15,%r15), %ecx
movq 0x10(%rdi), %rax
movq (%rax,%r9,8), %rdi
movq (%rbx), %rsi
xorq %rdi, %rsi
negb %cl
shrq %cl, %rsi
shlq %cl, %rsi
xorq %rdi, %rsi
jmp 0x18abfa
jbe 0x18ab76
addq %rax, %rax
pushq $0x40
popq %rsi
testq %r15, %r15
je 0x18ac26
leal (%r15,%r15), %r8d
movq 0x10(%rdi), %rdi
movq (%rdi,%r9,8), %r11
movl %eax, %ecx
shlq %cl, %r11
movq (%rbx), %r10
xorq %r11, %r10
negb %r8b
movl %r8d, %ecx
shrq %cl, %r10
shlq %cl, %r10
xorq %r11, %r10
jmp 0x18ac33
movq %r15, %rax
subq %rcx, %rax
addq %rax, %rax
leal (%r15,%r15), %esi
movq 0x10(%rdi), %rdi
movq (%rdi,%r9,8), %r8
movl %eax, %ecx
shrq %cl, %r8
movq (%rbx), %r10
xorq %r8, %r10
negb %sil
movl %esi, %ecx
shrq %cl, %r10
shlq %cl, %r10
xorq %r8, %r10
movq %r10, (%rbx)
movq (%rdi,%r9,8), %r8
movq %rax, %rcx
negq %rcx
shlq %cl, %r8
pushq $0x40
popq %rsi
subq %rax, %rsi
movq %r8, 0x8(%rbx)
leaq 0x10(%rbx), %r10
cmpq %rdx, %r9
jae 0x18ac69
movq 0x8(%rdi,%r9,8), %r11
movl %eax, %ecx
shrq %cl, %r11
orq %r8, %r11
movq %r11, -0x8(%r10)
movq 0x8(%rdi,%r9,8), %r8
movl %esi, %ecx
shlq %cl, %r8
incq %r9
movq %r8, (%r10)
addq $0x8, %r10
jmp 0x18abc2
movq 0x10(%rdi), %rax
movq (%rax,%r9,8), %rsi
movq %rsi, (%rbx)
subq %r9, %rdx
jbe 0x18ac17
leaq 0x8(%rbx), %rdi
leaq (%rax,%r9,8), %rsi
addq $0x8, %rsi
shlq $0x3, %rdx
callq 0x17630
incl %r12d
andl $0x1f, %r12d
movq %r12, (%r14)
addq %r15, %r13
jmp 0x18ac75
movq 0x10(%rdi), %rdi
movq (%rdi,%r9,8), %r10
movl %eax, %ecx
shlq %cl, %r10
subq %rax, %rsi
movq %r10, (%rbx)
leaq 0x8(%rbx), %r8
cmpq %rdx, %r9
jae 0x18ac69
movq 0x8(%rdi,%r9,8), %r11
movl %esi, %ecx
shrq %cl, %r11
orq %r10, %r11
movq %r11, -0x8(%r8)
movq 0x8(%rdi,%r9,8), %r10
movl %eax, %ecx
shlq %cl, %r10
incq %r9
movq %r10, (%r8)
addq $0x8, %r8
jmp 0x18ac3d
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