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


x86 assembly (clang, -O0):
<searchOne>:
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)
movl   $0x0,-0x2c(%rbp)
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe94(%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     1222 <searchOne+0x102>
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    11de <searchOne+0xbe>
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     11d9 <searchOne+0xb9>
movl   $0x1,-0x2c(%rbp)
jmp    1222 <searchOne+0x102>
jmp    1209 <searchOne+0xe9>
cmpl   $0x0,-0x28(%rbp)
jle    11fb <searchOne+0xdb>
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x28(%rbp)
jmp    1204 <searchOne+0xe4>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1209 <searchOne+0xe9>
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    117d <searchOne+0x5d>
cmpl   $0x1,-0x2c(%rbp)
jne    124b <searchOne+0x12b>
mov    -0x24(%rbp),%esi
sub    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
sub    $0x1,%edx
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1259 <searchOne+0x139>
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<searchOne>:
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,%r13d
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
cmp    %r13d,%ebx
jle    118e <searchOne+0x5e>
lea    0xeb7(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
xor    %r14d,%r14d
xor    %ebp,%ebp
jmp    11be <searchOne+0x8e>
add    $0x1,%ebp
nopl   0x0(%rax,%rax,1)
lea    0xe59(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    (%rbx,%rbp,1),%eax
sub    %r14d,%eax
cmp    %r13d,%eax
jg     1174 <searchOne+0x44>
movslq %ebp,%rax
movzbl (%r12,%rax,1),%ecx
movslq %r14d,%rax
cmp    (%r15,%rax,1),%cl
jne    11e0 <searchOne+0xb0>
lea    0x1(%rbp),%esi
add    $0x1,%r14d
cmp    %ebx,%r14d
jge    11ef <searchOne+0xbf>
mov    %esi,%ebp
jmp    11a0 <searchOne+0x70>
nop
test   %r14d,%r14d
jle    1195 <searchOne+0x65>
mov    (%rsp),%rcx
mov    (%rcx,%rax,4),%r14d
jmp    11a0 <searchOne+0x70>
sub    %ebx,%esi
lea    0xe12(%rip),%rdi
mov    %ebp,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>

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

LLVM IR (-O2):
@.str.2 = [10 x i8] c" %3d %3d\0A\00"
@.str.3 = [20 x i8] c"Position = %d - %d\0A\00"
@str = [9 x i8] c" i j\00"
@str.5 = [11 x i8] c"----------\00"
@str.6 = [11 x i8] c"Not found.\00"
define void @searchOne(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.5, i64 0, i64 0))
%8 = icmp sgt i32 %5, %4
br i1 %8, label %40, label %9
9: ; preds = %3, %30
%10 = phi i32 [ %32, %30 ], [ 0, %3 ]
%11 = phi i32 [ %31, %30 ], [ 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 %23
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 %30, label %37
23: ; preds = %9
%24 = icmp sgt i32 %10, 0
br i1 %24, label %25, label %28
25: ; preds = %23
%26 = getelementptr inbounds i32, i32* %2, i64 %15
%27 = load i32, i32* %26
br label %30
28: ; preds = %23
%29 = add nsw i32 %11, 1
br label %30
30: ; preds = %25, %28, %19
%31 = phi i32 [ %20, %19 ], [ %11, %25 ], [ %29, %28 ]
%32 = phi i32 [ %21, %19 ], [ %27, %25 ], [ %10, %28 ]
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %31, i32 %32)
%34 = add nsw i32 %31, %5
%35 = sub i32 %34, %32
%36 = icmp sgt i32 %35, %4
br i1 %36, label %40, label %9
37: ; preds = %19
%38 = sub nsw i32 %20, %5
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %38, i32 %11)
br label %42
40: ; preds = %30, %3
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.6, i64 0, i64 0))
br label %42
42: ; preds = %40, %37
ret void
}