#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 /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
void searchAll(char *source, char *key, int *next) {
  int sourceLength = strlen(source);
  int keyLength = strlen(key);
  int i = 0;
  int j = 0;
  printf("   i   j\n");
  printf("----------\n");
  while ((i + keyLength - j) <= sourceLength) {
    if (source[i] == key[j]) {
      i++;
      j++;
      if (j >= keyLength) {
        printf("Position = %d - %d\n", i - keyLength, i - 1);
        j = 0;
      }
    } else if (j > 0) {
      j = next[j];
    } else {
      i++;
    }
    printf(" %3d %3d\n", i, j);
  }
}


x86 assembly (clang, -O0):
<searchAll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    -0x20(%rbp),%eax
sub    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     1230 <searchAll+0x110>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x10(%rbp),%rcx
movslq -0x28(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    11ec <searchAll+0xcc>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jl     11e7 <searchAll+0xc7>
mov    -0x24(%rbp),%esi
sub    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
sub    $0x1,%edx
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x28(%rbp)
jmp    1217 <searchAll+0xf7>
cmpl   $0x0,-0x28(%rbp)
jle    1209 <searchAll+0xe9>
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x28(%rbp)
jmp    1212 <searchAll+0xf2>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1217 <searchAll+0xf7>
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1176 <searchAll+0x56>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<searchAll>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,(%rsp)
mov    %rsi,%r15
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
lea    0xebe(%rip),%rdi
call   1030 <puts@plt>
cmp    %ebp,%ebx
jle    1181 <searchAll+0x51>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r14d,%r14d
xor    %edx,%edx
jmp    11b0 <searchAll+0x80>
add    $0x1,%edx
mov    %edx,%r13d
lea    0xe7f(%rip),%rdi
mov    %r13d,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    (%rbx,%r13,1),%eax
sub    %r14d,%eax
mov    %r13d,%edx
cmp    %ebp,%eax
jg     1172 <searchAll+0x42>
movslq %edx,%rax
movzbl (%r12,%rax,1),%ecx
movslq %r14d,%rax
cmp    (%r15,%rax,1),%cl
jne    11f0 <searchAll+0xc0>
lea    0x1(%rdx),%r13d
add    $0x1,%r14d
cmp    %ebx,%r14d
jl     118e <searchAll+0x5e>
mov    %r13d,%esi
sub    %ebx,%esi
xor    %r14d,%r14d
lea    0xe23(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    118e <searchAll+0x5e>
cs nopw 0x0(%rax,%rax,1)
test   %r14d,%r14d
jle    1188 <searchAll+0x58>
mov    (%rsp),%rcx
mov    (%rcx,%rax,4),%r14d
jmp    118b <searchAll+0x5b>

LLVM IR (-O0):
@.str = [10 x i8] c" i j\0A\00"
@.str.1 = [12 x i8] c"----------\0A\00"
@.str.2 = [20 x i8] c"Position = %d - %d\0A\00"
@.str.3 = [10 x i8] c" %3d %3d\0A\00"
define void @searchAll(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %7
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %68, %3
%18 = load i32, i32* %9
%19 = load i32, i32* %8
%20 = add nsw i32 %18, %19
%21 = load i32, i32* %10
%22 = sub nsw i32 %20, %21
%23 = load i32, i32* %7
%24 = icmp sle i32 %22, %23
br i1 %24, label %25, label %72
25: ; preds = %17
%26 = load i8*, i8** %4
%27 = load i32, i32* %9
%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** %5
%33 = load i32, i32* %10
%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 %55
39: ; preds = %25
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
%44 = load i32, i32* %10
%45 = load i32, i32* %8
%46 = icmp sge i32 %44, %45
br i1 %46, label %47, label %54
47: ; preds = %39
%48 = load i32, i32* %9
%49 = load i32, i32* %8
%50 = sub nsw i32 %48, %49
%51 = load i32, i32* %9
%52 = sub nsw i32 %51, 1
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %50, i32 %52)
store i32 0, i32* %10
br label %54
54: ; preds = %47, %39
br label %68
55: ; preds = %25
%56 = load i32, i32* %10
%57 = icmp sgt i32 %56, 0
br i1 %57, label %58, label %64
58: ; preds = %55
%59 = load i32*, i32** %6
%60 = load i32, i32* %10
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %59, i64 %61
%63 = load i32, i32* %62
store i32 %63, i32* %10
br label %67
64: ; preds = %55
%65 = load i32, i32* %9
%66 = add nsw i32 %65, 1
store i32 %66, i32* %9
br label %67
67: ; preds = %64, %58
br label %68
68: ; preds = %67, %54
%69 = load i32, i32* %9
%70 = load i32, i32* %10
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %69, i32 %70)
br label %17
72: ; preds = %17
ret void
}

LLVM IR (-O2):
@.str.2 = [20 x i8] c"Position = %d - %d\0A\00"
@.str.3 = [10 x i8] c" %3d %3d\0A\00"
@str = [9 x i8] c" i j\00"
@str.4 = [11 x i8] c"----------\00"
define void @searchAll(i8* %0, i8* %1, i32* nocapture %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %1)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.4, i64 0, i64 0))
%8 = icmp sgt i32 %5, %4
br i1 %8, label %40, label %9
9: ; preds = %3, %33
%10 = phi i32 [ %35, %33 ], [ 0, %3 ]
%11 = phi i32 [ %34, %33 ], [ 0, %3 ]
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = sext i32 %10 to i64
%16 = getelementptr inbounds i8, i8* %1, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %14, %17
br i1 %18, label %19, label %26
19: ; preds = %9
%20 = add nsw i32 %11, 1
%21 = add nsw i32 %10, 1
%22 = icmp slt i32 %21, %5
br i1 %22, label %33, label %23
23: ; preds = %19
%24 = sub nsw i32 %20, %5
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %24, i32 %11)
br label %33
26: ; preds = %9
%27 = icmp sgt i32 %10, 0
br i1 %27, label %28, label %31
28: ; preds = %26
%29 = getelementptr inbounds i32, i32* %2, i64 %15
%30 = load i32, i32* %29
br label %33
31: ; preds = %26
%32 = add nsw i32 %11, 1
br label %33
33: ; preds = %28, %31, %19, %23
%34 = phi i32 [ %20, %23 ], [ %20, %19 ], [ %11, %28 ], [ %32, %31 ]
%35 = phi i32 [ 0, %23 ], [ %21, %19 ], [ %30, %28 ], [ %10, %31 ]
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %34, i32 %35)
%37 = add nsw i32 %34, %5
%38 = sub i32 %37, %35
%39 = icmp sgt i32 %38, %4
br i1 %39, label %40, label %9
40: ; preds = %33, %3
ret void
}