#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 bfStrstr(char *, int, char *, int, int);
int bmStrstr(char *, int, char *, int, int);
int formalBMStrstr(char *, int, char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int main(void) {
  char text[500000];
  char pattern[500000];
  int idx;
  scanf("%s", text);
  do {
    scanf("%s", pattern);
  } while (strlen(pattern) < 30);
  printf("%s\n", pattern);
  printf("bfStrstr\n");
  for (idx = 0;
       (idx = bfStrstr(text, strlen(text), pattern, strlen(pattern), idx)) >= 0;
       idx++)
    printf("* idx = %d\n", idx);
  printf("\n");
  printf("bmStrstr\n");
  for (idx = 0;
       (idx = bmStrstr(text, strlen(text), pattern, strlen(pattern), idx)) >= 0;
       idx++)
    printf("* idx = %d\n", idx);
  printf("\n");
  printf("formalBMStrstr\n");
  for (idx = 0; (idx = formalBMStrstr(text, strlen(text), pattern,
                                      strlen(pattern), idx)) >= 0;
       idx++)
    printf("* idx = %d\n", idx);
  printf("\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf42a0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x7a130(%rbp),%rsi
lea    0xe80(%rip),%rdi
call   1080 <scanf@plt>
lea    -0xf4250(%rbp),%rsi
lea    0xe6d(%rip),%rdi
call   1080 <scanf@plt>
lea    -0xf4250(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1e,%eax
jl     1185 <main+0x25>
lea    -0xf4250(%rbp),%rsi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xf4254(%rbp)
lea    -0x7a130(%rbp),%rax
mov    %rax,-0xf4270(%rbp)
lea    -0x7a130(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xf4264(%rbp)
lea    -0xf4250(%rbp),%rax
mov    %rax,-0xf4260(%rbp)
lea    -0xf4250(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xf4270(%rbp),%rdi
mov    -0xf4264(%rbp),%esi
mov    -0xf4260(%rbp),%rdx
mov    %eax,%ecx
mov    -0xf4254(%rbp),%r8d
call   1070 <bfStrstr@plt>
mov    %eax,-0xf4254(%rbp)
cmp    $0x0,%eax
jl     126d <main+0x10d>
mov    -0xf4254(%rbp),%esi
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xf4254(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf4254(%rbp)
jmp    11da <main+0x7a>
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xf4254(%rbp)
lea    -0x7a130(%rbp),%rax
mov    %rax,-0xf4288(%rbp)
lea    -0x7a130(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xf427c(%rbp)
lea    -0xf4250(%rbp),%rax
mov    %rax,-0xf4278(%rbp)
lea    -0xf4250(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xf4288(%rbp),%rdi
mov    -0xf427c(%rbp),%esi
mov    -0xf4278(%rbp),%rdx
mov    %eax,%ecx
mov    -0xf4254(%rbp),%r8d
call   1060 <bmStrstr@plt>
mov    %eax,-0xf4254(%rbp)
cmp    $0x0,%eax
jl     1326 <main+0x1c6>
mov    -0xf4254(%rbp),%esi
lea    0xd06(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xf4254(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf4254(%rbp)
jmp    1293 <main+0x133>
lea    0xcee(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xcec(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xf4254(%rbp)
lea    -0x7a130(%rbp),%rax
mov    %rax,-0xf42a0(%rbp)
lea    -0x7a130(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xf4294(%rbp)
lea    -0xf4250(%rbp),%rax
mov    %rax,-0xf4290(%rbp)
lea    -0xf4250(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xf42a0(%rbp),%rdi
mov    -0xf4294(%rbp),%esi
mov    -0xf4290(%rbp),%rdx
mov    %eax,%ecx
mov    -0xf4254(%rbp),%r8d
call   1030 <formalBMStrstr@plt>
mov    %eax,-0xf4254(%rbp)
cmp    $0x0,%eax
jl     13df <main+0x27f>
mov    -0xf4254(%rbp),%esi
lea    0xc4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xf4254(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf4254(%rbp)
jmp    134c <main+0x1ec>
lea    0xc35(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xf42a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xf4240,%rsp
lea    0xe6a(%rip),%r14
lea    0x7a120(%rsp),%rsi
mov    %r14,%rdi
call   10a0 <scanf@plt>
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   10a0 <scanf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmp    $0x1e,%eax
jl     11b0 <main+0x30>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <puts@plt>
lea    0xe35(%rip),%rdi
call   1050 <puts@plt>
lea    0x7a120(%rsp),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1090 <bfStrstr@plt>
test   %eax,%eax
js     1269 <main+0xe9>
mov    %eax,%ebx
lea    0xdeb(%rip),%r14
lea    0x7a120(%rsp),%r15
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%ebx
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r12,%rdx
mov    %eax,%ecx
mov    %ebx,%r8d
call   1090 <bfStrstr@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1230 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xd9e(%rip),%rdi
call   1050 <puts@plt>
lea    0x7a120(%rsp),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1080 <bmStrstr@plt>
test   %eax,%eax
js     1309 <main+0x189>
mov    %eax,%ebx
lea    0xd48(%rip),%r14
lea    0x7a120(%rsp),%r15
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%ebx
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r12,%rdx
mov    %eax,%ecx
mov    %ebx,%r8d
call   1080 <bmStrstr@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    12d0 <main+0x150>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xd07(%rip),%rdi
call   1050 <puts@plt>
lea    0x7a120(%rsp),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1040 <formalBMStrstr@plt>
test   %eax,%eax
js     13a9 <main+0x229>
mov    %eax,%ebx
lea    0xca8(%rip),%r14
lea    0x7a120(%rsp),%r15
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%ebx
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r12,%rdx
mov    %eax,%ecx
mov    %ebx,%r8d
call   1040 <formalBMStrstr@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1370 <main+0x1f0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0xf4240,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [10 x i8] c"bfStrstr\0A\00"
@.str.3 = [12 x i8] c"* idx = %d\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [10 x i8] c"bmStrstr\0A\00"
@.str.6 = [16 x i8] c"formalBMStrstr\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [500000 x i8]
%3 = alloca [500000 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = getelementptr inbounds [500000 x i8], [500000 x i8]* %2, i64 0, i64 0
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %7
7: ; preds = %10, %0
%8 = getelementptr inbounds [500000 x i8], [500000 x i8]* %3, i64 0, i64 0
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %7
%11 = getelementptr inbounds [500000 x i8], [500000 x i8]* %3, i64 0, i64 0
%12 = call i32 @strlen(i8* %11)
%13 = icmp slt i32 %12, 30
br i1 %13, label %7, label %14
14: ; preds = %10
%15 = getelementptr inbounds [500000 x i8], [500000 x i8]* %3, i64 0, i64 0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %18
18: ; preds = %31, %14
%19 = getelementptr inbounds [500000 x i8], [500000 x i8]* %2, i64 0, i64 0
%20 = getelementptr inbounds [500000 x i8], [500000 x i8]* %2, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = getelementptr inbounds [500000 x i8], [500000 x i8]* %3, i64 0, i64 0
%23 = getelementptr inbounds [500000 x i8], [500000 x i8]* %3, i64 0, i64 0
%24 = call i32 @strlen(i8* %23)
%25 = load i32, i32* %4
%26 = call i32 @bfStrstr(i8* %19, i32 %21, i8* %22, i32 %24, i32 %25)
store i32 %26, i32* %4
%27 = icmp sge i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %18
%29 = load i32, i32* %4
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %28
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %18
34: ; preds = %18
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %4
br label %37
37: ; preds = %50, %34
%38 = getelementptr inbounds [500000 x i8], [500000 x i8]* %2, i64 0, i64 0
%39 = getelementptr inbounds [500000 x i8], [500000 x i8]* %2, i64 0, i64 0
%40 = call i32 @strlen(i8* %39)
%41 = getelementptr inbounds [500000 x i8], [500000 x i8]* %3, i64 0, i64 0
%42 = getelementptr inbounds [500000 x i8], [500000 x i8]* %3, i64 0, i64 0
%43 = call i32 @strlen(i8* %42)
%44 = load i32, i32* %4
%45 = call i32 @bmStrstr(i8* %38, i32 %40, i8* %41, i32 %43, i32 %44)
store i32 %45, i32* %4
%46 = icmp sge i32 %45, 0
br i1 %46, label %47, label %53
47: ; preds = %37
%48 = load i32, i32* %4
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %47
%51 = load i32, i32* %4
%52 = add nsw i32 %51, 1
store i32 %52, i32* %4
br label %37
53: ; preds = %37
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %4
br label %56
56: ; preds = %69, %53
%57 = getelementptr inbounds [500000 x i8], [500000 x i8]* %2, i64 0, i64 0
%58 = getelementptr inbounds [500000 x i8], [500000 x i8]* %2, i64 0, i64 0
%59 = call i32 @strlen(i8* %58)
%60 = getelementptr inbounds [500000 x i8], [500000 x i8]* %3, i64 0, i64 0
%61 = getelementptr inbounds [500000 x i8], [500000 x i8]* %3, i64 0, i64 0
%62 = call i32 @strlen(i8* %61)
%63 = load i32, i32* %4
%64 = call i32 @formalBMStrstr(i8* %57, i32 %59, i8* %60, i32 %62, i32 %63)
store i32 %64, i32* %4
%65 = icmp sge i32 %64, 0
br i1 %65, label %66, label %72
66: ; preds = %56
%67 = load i32, i32* %4
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %67)
br label %69
69: ; preds = %66
%70 = load i32, i32* %4
%71 = add nsw i32 %70, 1
store i32 %71, i32* %4
br label %56
72: ; preds = %56
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%74 = load i32, i32* %1
ret i32 %74
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.3 = [12 x i8] c"* idx = %d\0A\00"
@str = [9 x i8] c"bfStrstr\00"
@str.7 = [9 x i8] c"bmStrstr\00"
@str.8 = [15 x i8] c"formalBMStrstr\00"
define i32 @main() {
%1 = alloca [500000 x i8]
%2 = alloca [500000 x i8]
%3 = getelementptr inbounds [500000 x i8], [500000 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [500000 x i8], [500000 x i8]* %2, i64 0, i64 0
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %6
6: ; preds = %6, %0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%8 = call i32 @strlen(i8* %4)
%9 = icmp slt i32 %8, 30
br i1 %9, label %6, label %10
10: ; preds = %6
%11 = call i32 @puts(i8* %4)
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%13 = call i32 @strlen(i8* %3)
%14 = call i32 @strlen(i8* %4)
%15 = call i32 @bfStrstr(i8* %3, i32 %13, i8* %4, i32 %14, i32 0)
%16 = icmp sgt i32 %15, -1
br i1 %16, label %17, label %25
17: ; preds = %10, %17
%18 = phi i32 [ %23, %17 ], [ %15, %10 ]
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = add nuw nsw i32 %18, 1
%21 = call i32 @strlen(i8* %3)
%22 = call i32 @strlen(i8* %4)
%23 = call i32 @bfStrstr(i8* %3, i32 %21, i8* %4, i32 %22, i32 %20)
%24 = icmp sgt i32 %23, -1
br i1 %24, label %17, label %25
25: ; preds = %17, %10
%26 = call i32 @putchar(i32 10)
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.7, i64 0, i64 0))
%28 = call i32 @strlen(i8* %3)
%29 = call i32 @strlen(i8* %4)
%30 = call i32 @bmStrstr(i8* %3, i32 %28, i8* %4, i32 %29, i32 0)
%31 = icmp sgt i32 %30, -1
br i1 %31, label %32, label %40
32: ; preds = %25, %32
%33 = phi i32 [ %38, %32 ], [ %30, %25 ]
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %33)
%35 = add nuw nsw i32 %33, 1
%36 = call i32 @strlen(i8* %3)
%37 = call i32 @strlen(i8* %4)
%38 = call i32 @bmStrstr(i8* %3, i32 %36, i8* %4, i32 %37, i32 %35)
%39 = icmp sgt i32 %38, -1
br i1 %39, label %32, label %40
40: ; preds = %32, %25
%41 = call i32 @putchar(i32 10)
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.8, i64 0, i64 0))
%43 = call i32 @strlen(i8* %3)
%44 = call i32 @strlen(i8* %4)
%45 = call i32 @formalBMStrstr(i8* %3, i32 %43, i8* %4, i32 %44, i32 0)
%46 = icmp sgt i32 %45, -1
br i1 %46, label %47, label %55
47: ; preds = %40, %47
%48 = phi i32 [ %53, %47 ], [ %45, %40 ]
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %48)
%50 = add nuw nsw i32 %48, 1
%51 = call i32 @strlen(i8* %3)
%52 = call i32 @strlen(i8* %4)
%53 = call i32 @formalBMStrstr(i8* %3, i32 %51, i8* %4, i32 %52, i32 %50)
%54 = icmp sgt i32 %53, -1
br i1 %54, label %47, label %55
55: ; preds = %47, %40
%56 = call i32 @putchar(i32 10)
ret i32 0
}