// File: adamnovak[P]rlcsa/rlcsa_builder.cpp
// Function: CSA::RLCSABuilder::insertSequence(char*, unsigned int, bool)
void
RLCSABuilder::insertSequence(char* sequence, usint length, bool delete_sequence)
{
  if(sequence == 0 || length == 0 || !this->ok)
  {
    if(delete_sequence) { delete[] sequence; }
    return;
  }

  #ifdef MULTITHREAD_SUPPORT
  omp_set_num_threads(this->threads);
  #endif

  if(this->buffer == 0)
  {
    this->addLongSequence((uchar*)sequence, length, delete_sequence);
    return;
  }

  if(this->buffer_size - this->chars > length)
  {
    memcpy(this->buffer + this->chars, sequence, length);
    if(delete_sequence) { delete[] sequence; }
    this->chars += length;
    this->buffer[this->chars] = 0;
    this->chars++;
  }
  else
  {
    if(this->chars > 0) { this->flush(); }
    if(length >= this->buffer_size - 1)
    {
      this->addLongSequence((uchar*)sequence, length, delete_sequence);
    }
    else
    {
      memcpy(this->buffer + this->chars, sequence, length);
      if(delete_sequence) { delete[] sequence; }
      this->chars += length;
      this->buffer[this->chars] = 0;
      this->chars++;
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
andb $0x1, %al
movb %al, -0x15(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x13b59
cmpl $0x0, -0x14(%rbp)
je 0x13b59
movq -0x20(%rbp), %rax
testb $0x1, 0x24(%rax)
jne 0x13b7d
testb $0x1, -0x15(%rbp)
je 0x13b78
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x13b76
movq -0x28(%rbp), %rdi
callq 0x33d0
jmp 0x13b78
jmp 0x13cb1
movq -0x20(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x13ba5
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movb -0x15(%rbp), %al
andb $0x1, %al
movzbl %al, %ecx
callq 0x13cc0
jmp 0x13cb1
movq -0x20(%rbp), %rcx
movl 0x10(%rcx), %eax
subl 0x20(%rcx), %eax
cmpl -0x14(%rbp), %eax
jbe 0x13c15
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movl 0x20(%rax), %eax
addq %rax, %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %eax
movl %eax, %edx
callq 0x3240
testb $0x1, -0x15(%rbp)
je 0x13bef
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x13bed
movq -0x30(%rbp), %rdi
callq 0x33d0
jmp 0x13bef
movq -0x20(%rbp), %rax
movl -0x14(%rbp), %ecx
addl 0x20(%rax), %ecx
movl %ecx, 0x20(%rax)
movq 0x18(%rax), %rcx
movl 0x20(%rax), %edx
movb $0x0, (%rcx,%rdx)
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
jmp 0x13cb1
movq -0x20(%rbp), %rax
cmpl $0x0, 0x20(%rax)
jbe 0x13c28
movq -0x20(%rbp), %rdi
callq 0x13d90
movq -0x20(%rbp), %rcx
movl -0x14(%rbp), %eax
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jb 0x13c53
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movb -0x15(%rbp), %al
andb $0x1, %al
movzbl %al, %ecx
callq 0x13cc0
jmp 0x13caf
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movl 0x20(%rax), %eax
addq %rax, %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %eax
movl %eax, %edx
callq 0x3240
testb $0x1, -0x15(%rbp)
je 0x13c8e
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x13c8c
movq -0x38(%rbp), %rdi
callq 0x33d0
jmp 0x13c8e
movq -0x20(%rbp), %rax
movl -0x14(%rbp), %ecx
addl 0x20(%rax), %ecx
movl %ecx, 0x20(%rax)
movq 0x18(%rax), %rcx
movl 0x20(%rax), %edx
movb $0x0, (%rcx,%rdx)
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
jmp 0x13cb1
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)