#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 */
scalar_t__ malloc(int);
int strlen(char *);
int *buildNext(char *tar) {
  int m = strlen(tar);
  int j = 0;
  int *next = (int *)malloc(sizeof(int) * m);
  int t = next[0] = -1;
  while (j < m - 1) {
    if (t < 0 || tar[j] == tar[t]) {
      next[++j] = ++t;
    } else {
      t = next[t];
    }
  }
  return next;
}


x86 assembly (clang, -O0):
<buildNext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11d2 <buildNext+0xb2>
cmpl   $0x0,-0x1c(%rbp)
jl     119e <buildNext+0x7e>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x8(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    11bf <buildNext+0x9f>
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    11cd <buildNext+0xad>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
jmp    1163 <buildNext+0x43>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buildNext>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%r14d
lea    0x0(,%r14,4),%edi
call   1040 <malloc@plt>
movl   $0xffffffff,(%rax)
cmp    $0x2,%r14d
jl     118b <buildNext+0x6b>
add    $0xffffffff,%r14d
xor    %edx,%edx
mov    $0xffffffff,%ecx
jmp    116f <buildNext+0x4f>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ecx
lea    0x1(%rsi),%edx
mov    %ecx,0x4(%rax,%rsi,4)
cmp    %r14d,%edx
jge    118b <buildNext+0x6b>
movslq %edx,%rsi
test   %ecx,%ecx
js     1160 <buildNext+0x40>
movzbl (%r15,%rsi,1),%ebx
mov    %ecx,%edi
cmp    (%r15,%rdi,1),%bl
je     1160 <buildNext+0x40>
mov    (%rax,%rdi,4),%ecx
cmp    %r14d,%edx
jl     116f <buildNext+0x4f>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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