// File: IHorvalds[P]RomAna/./processing/InflexEngineCore.cpp
// Function: InflexEngine::search(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int&)
int32_t InflexEngine::search(std::string str, int32_t& lastPos) {
// Good for tests: if str is a rootWord returns the pointer where it was saved. Otherwise, the pointer of its rootword.
  int32_t ptr, pos, encoding;
  bool toCheck;
  ptr = 0;
  for (pos = 0; pos < str.size();) {
    // Get the encoding
    encoding = (pos == str.size() - 1) ? romanian::encode(str[pos]) : romanian::diacriticEncode(str[pos], str[pos + 1]);
    
    toCheck = (staticTrieAccess(ptr)->configuration != fullBits) ? bitOp::getBit(staticTrieAccess(ptr)->configuration, encoding) : staticTrieAccess(ptr)->sons[encoding];
    if (!toCheck) {
      lastPos = pos;
      return -ptr;
    }
    ptr = staticTrieAccess(ptr)->sons[staticTrieAccess(ptr)->configuration != fullBits ? bitOp::orderOfBit(staticTrieAccess(ptr)->configuration, encoding) : encoding];
    pos += 1 + romanian::isDiacritic(str[pos]);
  }
  return (staticTrieAccess(ptr)->code & 1) ? ptr : (staticTrieAccess(ptr)->code / 2);
}

// Assembly:
subq $0x78, %rsp
movq %rsi, 0x38(%rsp)
movq %rdi, 0x68(%rsp)
movq %rsi, 0x60(%rsp)
movq %rdx, 0x58(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x40(%rsp)
movl $0x0, 0x54(%rsp)
movl $0x0, 0x50(%rsp)
movq 0x38(%rsp), %rdi
movslq 0x50(%rsp), %rax
movq %rax, 0x30(%rsp)
callq 0x4260
movq %rax, %rcx
movq 0x30(%rsp), %rax
cmpq %rcx, %rax
jae 0x5124
movq 0x38(%rsp), %rdi
movslq 0x50(%rsp), %rax
movq %rax, 0x28(%rsp)
callq 0x4260
movq %rax, %rcx
movq 0x28(%rsp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x4fb9
movq 0x38(%rsp), %rdi
movslq 0x50(%rsp), %rsi
callq 0x46c0
movsbl (%rax), %edi
callq 0x5c80
movl %eax, 0x24(%rsp)
jmp 0x4ff5
movq 0x38(%rsp), %rdi
movslq 0x50(%rsp), %rsi
callq 0x46c0
movq 0x38(%rsp), %rdi
movb (%rax), %al
movb %al, 0x23(%rsp)
movl 0x50(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x46c0
movb 0x23(%rsp), %cl
movzbl %cl, %edi
movzbl (%rax), %esi
callq 0x5cd0
movl %eax, 0x24(%rsp)
movq 0x40(%rsp), %rdi
movl 0x24(%rsp), %eax
movl %eax, 0x4c(%rsp)
movl 0x54(%rsp), %esi
callq 0x4bd0
movq 0x40(%rsp), %rcx
movl 0x8(%rax), %eax
cmpl 0x24(%rcx), %eax
je 0x503d
movq 0x40(%rsp), %rdi
movl 0x54(%rsp), %esi
callq 0x4bd0
movl 0x8(%rax), %edi
movl 0x4c(%rsp), %esi
callq 0x5c00
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x1c(%rsp)
jmp 0x505b
movq 0x40(%rsp), %rdi
movl 0x54(%rsp), %esi
callq 0x4bd0
movq 0xc(%rax), %rax
movslq 0x4c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, 0x4b(%rsp)
testb $0x1, 0x4b(%rsp)
jne 0x508c
movl 0x50(%rsp), %ecx
movq 0x58(%rsp), %rax
movl %ecx, (%rax)
xorl %eax, %eax
subl 0x54(%rsp), %eax
movl %eax, 0x74(%rsp)
jmp 0x5164
movq 0x40(%rsp), %rdi
movl 0x54(%rsp), %esi
callq 0x4bd0
movq 0x40(%rsp), %rdi
movq 0xc(%rax), %rax
movq %rax, 0x10(%rsp)
movl 0x54(%rsp), %esi
callq 0x4bd0
movq 0x40(%rsp), %rcx
movl 0x8(%rax), %eax
cmpl 0x24(%rcx), %eax
je 0x50de
movq 0x40(%rsp), %rdi
movl 0x54(%rsp), %esi
callq 0x4bd0
movl 0x8(%rax), %edi
movl 0x4c(%rsp), %esi
callq 0x5c20
movl %eax, 0xc(%rsp)
jmp 0x50e6
movl 0x4c(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rax
movl 0xc(%rsp), %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, 0x54(%rsp)
movslq 0x50(%rsp), %rsi
callq 0x46c0
movzbl (%rax), %edi
callq 0x5d60
andb $0x1, %al
movzbl %al, %eax
addl $0x1, %eax
addl 0x50(%rsp), %eax
movl %eax, 0x50(%rsp)
jmp 0x4f52
movq 0x40(%rsp), %rdi
movl 0x54(%rsp), %esi
callq 0x4bd0
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x5146
movl 0x54(%rsp), %eax
movl %eax, 0x8(%rsp)
jmp 0x515c
movq 0x40(%rsp), %rdi
movl 0x54(%rsp), %esi
callq 0x4bd0
movl (%rax), %eax
shrl %eax
movl %eax, 0x8(%rsp)
movl 0x8(%rsp), %eax
movl %eax, 0x74(%rsp)
movl 0x74(%rsp), %eax
addq $0x78, %rsp
retq
nopl (%rax)