// File: /workspace/github_c_makefile_star2_O0/fukunagatsu[P]RIblast/db_construction.cpp
// Function: DbConstruction::Search(std::vector<unsigned char, std::allocator<unsigned char>>&, std::vector<int, std::allocator<int>>&, int*, int*, unsigned char, int)
void DbConstruction::Search(vector<unsigned char> &encoded_sequences, vector<int> &suffix_array, int* start, int* end, unsigned char c, int offset){
  int s = *start;
  int e = *end;
  int m;

  if (suffix_array[s] + offset >= encoded_sequences.size()) {
    ++(*start);
  }
  
  if(s>e){
    *start = 1;
    *end = 0;
    return;
  }else if (s == e) {
    if (encoded_sequences[suffix_array[s]+offset] == c) {
      return;
    } else {
      *start = 1;
      *end = 0;
      return;
    }
  }
  
  if (encoded_sequences[suffix_array[s]+offset] != c) {
    while (s < e - 1) {
      m = (s + e) / 2;
      if (encoded_sequences[suffix_array[m]+offset] < c) {
        s = m;
      } else {
        e = m;
      }
    }
    if (encoded_sequences[suffix_array[e]+offset] != c) {
      *start = 1;
      *end = 0;
      return;
    }
    *start = e;
    s = e;
    e = *end;
  }

  if (encoded_sequences[suffix_array[e]+offset] != c) {
    while (s < e - 1) {
      m = (s + e) / 2;
      if (encoded_sequences[suffix_array[m]+offset] > c) {
        e = m;
      } else {
        s = m;
      }
    }
    if (encoded_sequences[suffix_array[s]+offset] != c) {
      *start = 1;
      *end = 0;
      return;
    }
    *end = s;
  }
  return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movb %r9b, %al
movl 0x10(%rbp), %r9d
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movb %al, -0x29(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x30(%rbp), %rsi
callq 0xbac0
movl (%rax), %eax
addl 0x10(%rbp), %eax
cltq
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
callq 0xba80
movq %rax, %rcx
movq -0x40(%rbp), %rax
cmpq %rcx, %rax
jb 0xae03
movq -0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
jle 0xae24
movq -0x20(%rbp), %rax
movl $0x1, (%rax)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
jmp 0xb05d
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
jne 0xae7b
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x30(%rbp), %rsi
callq 0xbac0
movq -0x48(%rbp), %rdi
movl (%rax), %eax
addl 0x10(%rbp), %eax
movslq %eax, %rsi
callq 0xbaa0
movzbl (%rax), %eax
movzbl -0x29(%rbp), %ecx
cmpl %ecx, %eax
jne 0xae62
jmp 0xb05d
movq -0x20(%rbp), %rax
movl $0x1, (%rax)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
jmp 0xb05d
jmp 0xae7d
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x30(%rbp), %rsi
callq 0xbac0
movq -0x50(%rbp), %rdi
movl (%rax), %eax
addl 0x10(%rbp), %eax
movslq %eax, %rsi
callq 0xbaa0
movzbl (%rax), %eax
movzbl -0x29(%rbp), %ecx
cmpl %ecx, %eax
je 0xaf75
jmp 0xaeb4
movl -0x30(%rbp), %eax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xaf13
movl -0x30(%rbp), %eax
addl -0x34(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x38(%rbp), %rsi
callq 0xbac0
movq -0x58(%rbp), %rdi
movl (%rax), %eax
addl 0x10(%rbp), %eax
movslq %eax, %rsi
callq 0xbaa0
movzbl (%rax), %eax
movzbl -0x29(%rbp), %ecx
cmpl %ecx, %eax
jge 0xaf0b
movl -0x38(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0xaf11
movl -0x38(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0xaeb4
movq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0xbac0
movq -0x60(%rbp), %rdi
movl (%rax), %eax
addl 0x10(%rbp), %eax
movslq %eax, %rsi
callq 0xbaa0
movzbl (%rax), %eax
movzbl -0x29(%rbp), %ecx
cmpl %ecx, %eax
je 0xaf5d
movq -0x20(%rbp), %rax
movl $0x1, (%rax)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
jmp 0xb05d
movl -0x34(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x34(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0xbac0
movq -0x68(%rbp), %rdi
movl (%rax), %eax
addl 0x10(%rbp), %eax
movslq %eax, %rsi
callq 0xbaa0
movzbl (%rax), %eax
movzbl -0x29(%rbp), %ecx
cmpl %ecx, %eax
je 0xb05b
jmp 0xafac
movl -0x30(%rbp), %eax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xb00b
movl -0x30(%rbp), %eax
addl -0x34(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x38(%rbp), %rsi
callq 0xbac0
movq -0x70(%rbp), %rdi
movl (%rax), %eax
addl 0x10(%rbp), %eax
movslq %eax, %rsi
callq 0xbaa0
movzbl (%rax), %eax
movzbl -0x29(%rbp), %ecx
cmpl %ecx, %eax
jle 0xb003
movl -0x38(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0xb009
movl -0x38(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0xafac
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x30(%rbp), %rsi
callq 0xbac0
movq -0x78(%rbp), %rdi
movl (%rax), %eax
addl 0x10(%rbp), %eax
movslq %eax, %rsi
callq 0xbaa0
movzbl (%rax), %eax
movzbl -0x29(%rbp), %ecx
cmpl %ecx, %eax
je 0xb052
movq -0x20(%rbp), %rax
movl $0x1, (%rax)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
jmp 0xb05d
movl -0x30(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
jmp 0xb05d
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)