// File: maxgodfrey2004[P]gss/src/kmp.cc
// Function: gss::kmp::ComputePrefix(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
std::vector<int> ComputePrefix(std::string search) {
  std::vector<int> prefix_vals(search.length());
  prefix_vals[0] = 0;
  int current_prefix = 0;

  for (int i = 1; i < static_cast<int>(search.length()); ++i) {
    // Jump by prefix values to try smaller prefixes. This process stops when
    // we either find a match, or reach zero.
    while (current_prefix > 0 && search[i] != search[current_prefix]) {
      current_prefix = prefix_vals[current_prefix - 1];
    }
    if (search[i] == search[current_prefix]) {
      ++current_prefix;
    }
    prefix_vals[i] = current_prefix;
  }

  return prefix_vals;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rsi, -0x58(%rbp)
movq %rdi, %rax
movq -0x58(%rbp), %rdi
movq %rax, -0x48(%rbp)
movq %rax, %rcx
movq %rcx, -0x50(%rbp)
movq %rax, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movb $0x0, -0x11(%rbp)
callq 0x2260
movq %rax, -0x40(%rbp)
leaq -0x12(%rbp), %rdi
movq %rdi, -0x38(%rbp)
callq 0x3800
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x4230
jmp 0x3dc6
leaq -0x12(%rbp), %rdi
callq 0x3ad0
movq -0x48(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x42a0
movl $0x0, (%rax)
movl $0x0, -0x28(%rbp)
movl $0x1, -0x2c(%rbp)
movq -0x58(%rbp), %rdi
movl -0x2c(%rbp), %eax
movl %eax, -0x5c(%rbp)
callq 0x2260
movq %rax, %rcx
movl -0x5c(%rbp), %eax
cmpl %ecx, %eax
jge 0x3f31
jmp 0x3e0f
xorl %eax, %eax
cmpl $0x0, -0x28(%rbp)
movb %al, -0x5d(%rbp)
jle 0x3e5c
movq -0x58(%rbp), %rdi
movslq -0x2c(%rbp), %rsi
callq 0x22f0
movq %rax, -0x68(%rbp)
jmp 0x3e2d
movq -0x58(%rbp), %rdi
movq -0x68(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x74(%rbp)
movslq -0x28(%rbp), %rsi
callq 0x22f0
movq %rax, -0x70(%rbp)
jmp 0x3e4a
movl -0x74(%rbp), %eax
movq -0x70(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
setne %al
movb %al, -0x5d(%rbp)
movb -0x5d(%rbp), %al
testb $0x1, %al
jne 0x3e65
jmp 0x3eb2
movq -0x48(%rbp), %rdi
movl -0x28(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x42a0
movl (%rax), %eax
movl %eax, -0x28(%rbp)
jmp 0x3e0f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x12(%rbp), %rdi
callq 0x3ad0
jmp 0x3f51
movq -0x48(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
callq 0x3630
jmp 0x3f51
movq -0x58(%rbp), %rdi
movslq -0x2c(%rbp), %rsi
callq 0x22f0
movq %rax, -0x80(%rbp)
jmp 0x3ec5
movq -0x58(%rbp), %rdi
movq -0x80(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x8c(%rbp)
movslq -0x28(%rbp), %rsi
callq 0x22f0
movq %rax, -0x88(%rbp)
jmp 0x3ee8
movl -0x8c(%rbp), %eax
movq -0x88(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x3f05
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movq -0x48(%rbp), %rdi
movl -0x28(%rbp), %eax
movl %eax, -0x90(%rbp)
movslq -0x2c(%rbp), %rsi
callq 0x42a0
movl -0x90(%rbp), %ecx
movl %ecx, (%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3df0
movb $0x1, -0x11(%rbp)
testb $0x1, -0x11(%rbp)
jne 0x3f44
movq -0x48(%rbp), %rdi
callq 0x3630
movq -0x50(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
movq -0x20(%rbp), %rdi
callq 0x22b0
nopw (%rax,%rax)