#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int strlen(char const *);
void compute_prefix_function(const char *pattern, int *next) {
  int i = 0;
  int j = -1;
  next[0] = -1;
  while (i < strlen(pattern) - 1) {
    if (-1 == j || pattern[i] == pattern[j]) {
      ++i;
      ++j;
      next[i] = j;
    } else {
      j = next[j];
    }
  }
}


x86 assembly (clang, -O0):
<compute_prefix_function>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11bd <compute_prefix_function+0xad>
mov    $0xffffffff,%eax
cmp    -0x18(%rbp),%eax
je     1185 <compute_prefix_function+0x75>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x8(%rbp),%rcx
movslq -0x18(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    11aa <compute_prefix_function+0x9a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    11b8 <compute_prefix_function+0xa8>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
jmp    1138 <compute_prefix_function+0x28>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_prefix_function>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
movl   $0xffffffff,(%rsi)
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     1176 <compute_prefix_function+0x66>
xor    %ebx,%ebx
mov    $0xffffffff,%ebp
jmp    115a <compute_prefix_function+0x4a>
cs nopw 0x0(%rax,%rax,1)
lea    0x1(%rax),%ebx
add    $0x1,%ebp
mov    %ebp,0x4(%r14,%rax,4)
mov    %r15,%rdi
call   1030 <strlen@plt>
add    $0xffffffff,%eax
cmp    %eax,%ebx
jge    1176 <compute_prefix_function+0x66>
movslq %ebx,%rax
cmp    $0xffffffff,%ebp
je     1140 <compute_prefix_function+0x30>
movzbl (%r15,%rax,1),%edx
movslq %ebp,%rcx
cmp    (%r15,%rcx,1),%dl
je     1140 <compute_prefix_function+0x30>
mov    (%r14,%rcx,4),%ebp
jmp    114b <compute_prefix_function+0x3b>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @compute_prefix_function(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 0, i32* %5
store i32 -1, i32* %6
%7 = load i32*, i32** %4
%8 = getelementptr inbounds i32, i32* %7, i64 0
store i32 -1, i32* %8
br label %9
9: ; preds = %48, %2
%10 = load i32, i32* %5
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = sub nsw i32 %12, 1
%14 = icmp slt i32 %10, %13
br i1 %14, label %15, label %49
15: ; preds = %9
%16 = load i32, i32* %6
%17 = icmp eq i32 -1, %16
br i1 %17, label %32, label %18
18: ; preds = %15
%19 = load i8*, i8** %3
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = load i8*, i8** %3
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %24, %30
br i1 %31, label %32, label %42
32: ; preds = %18, %15
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
%37 = load i32, i32* %6
%38 = load i32*, i32** %4
%39 = load i32, i32* %5
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
store i32 %37, i32* %41
br label %48
42: ; preds = %18
%43 = load i32*, i32** %4
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
%47 = load i32, i32* %46
store i32 %47, i32* %6
br label %48
48: ; preds = %42, %32
br label %9
49: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @compute_prefix_function(i8* %0, i32* nocapture %1) {
store i32 -1, i32* %1
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 1
br i1 %4, label %5, label %31
5: ; preds = %2, %25
%6 = phi i32 [ %27, %25 ], [ -1, %2 ]
%7 = phi i32 [ %26, %25 ], [ 0, %2 ]
%8 = icmp eq i32 %6, -1
br i1 %8, label %17, label %9
9: ; preds = %5
%10 = sext i32 %7 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = sext i32 %6 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %12, %15
br i1 %16, label %17, label %22
17: ; preds = %9, %5
%18 = add nsw i32 %7, 1
%19 = add nsw i32 %6, 1
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds i32, i32* %1, i64 %20
store i32 %19, i32* %21
br label %25
22: ; preds = %9
%23 = getelementptr inbounds i32, i32* %1, i64 %13
%24 = load i32, i32* %23
br label %25
25: ; preds = %22, %17
%26 = phi i32 [ %18, %17 ], [ %7, %22 ]
%27 = phi i32 [ %19, %17 ], [ %24, %22 ]
%28 = tail call i32 @strlen(i8* %0)
%29 = add nsw i32 %28, -1
%30 = icmp slt i32 %26, %29
br i1 %30, label %5, label %31
31: ; preds = %25, %2
ret void
}