#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 BruteForceMatching(char *, char *);
int KMPMatching(char *, char *);
int /*<<< orphan*/ Print(char *, char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int main(void) {
  char mStr[1000];
  char pStr[1000];
  int i, position;
  printf("main string :");
  scanf("%s", mStr);
  printf("pattern string:");
  scanf("%s", pStr);
  printf("\n\n");
  position = BruteForceMatching(mStr, pStr);
  printf("BruteForceMatching:\n");
  Print(mStr, pStr, position);
  position = KMPMatching(mStr, pStr);
  printf("KMPMatching:\n");
  Print(mStr, pStr, position);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7f0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
call   1030 <printf@plt>
lea    -0x3f0(%rbp),%rsi
lea    0xe92(%rip),%rdi
call   1050 <scanf@plt>
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
lea    -0x7e0(%rbp),%rsi
lea    0xe73(%rip),%rdi
call   1050 <scanf@plt>
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
lea    -0x3f0(%rbp),%rdi
lea    -0x7e0(%rbp),%rsi
call   1070 <BruteForceMatching@plt>
mov    %eax,-0x7e8(%rbp)
lea    0xe58(%rip),%rdi
call   1030 <printf@plt>
lea    -0x3f0(%rbp),%rdi
lea    -0x7e0(%rbp),%rsi
mov    -0x7e8(%rbp),%edx
call   1060 <Print@plt>
lea    -0x3f0(%rbp),%rdi
lea    -0x7e0(%rbp),%rsi
call   1040 <KMPMatching@plt>
mov    %eax,-0x7e8(%rbp)
lea    0xe2f(%rip),%rdi
call   1030 <printf@plt>
lea    -0x3f0(%rbp),%rdi
lea    -0x7e0(%rbp),%rsi
mov    -0x7e8(%rbp),%edx
call   1060 <Print@plt>
xor    %eax,%eax
add    $0x7f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x7d8,%rsp
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
lea    0xe8e(%rip),%r15
lea    0x3f0(%rsp),%r14
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <scanf@plt>
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
mov    %rsp,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
lea    0xe6d(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <BruteForceMatching@plt>
mov    %eax,%ebp
lea    0xe56(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1070 <Print@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <KMPMatching@plt>
mov    %eax,%ebp
lea    0xe44(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1070 <Print@plt>
xor    %eax,%eax
add    $0x7d8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"main string :\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [16 x i8] c"pattern string:\00"
@.str.3 = [3 x i8] c"\0A\0A\00"
@.str.4 = [21 x i8] c"BruteForceMatching:\0A\00"
@.str.5 = [14 x i8] c"KMPMatching:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i8]
%3 = alloca [1000 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%15 = call i32 @BruteForceMatching(i8* %13, i8* %14)
store i32 %15, i32* %5
%16 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%19 = load i32, i32* %5
%20 = call i32 @Print(i8* %17, i8* %18, i32 %19)
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%23 = call i32 @KMPMatching(i8* %21, i8* %22)
store i32 %23, i32* %5
%24 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%25 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%27 = load i32, i32* %5
%28 = call i32 @Print(i8* %25, i8* %26, i32 %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"main string :\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [16 x i8] c"pattern string:\00"
@str = [2 x i8] c"\0A\00"
@str.6 = [20 x i8] c"BruteForceMatching:\00"
@str.7 = [13 x i8] c"KMPMatching:\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = alloca [1000 x i8]
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%7 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%10 = call i32 @BruteForceMatching(i8* %3, i8* %4)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.6, i64 0, i64 0))
%12 = call i32 @Print(i8* %3, i8* %4, i32 %10)
%13 = call i32 @KMPMatching(i8* %3, i8* %4)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.7, i64 0, i64 0))
%15 = call i32 @Print(i8* %3, i8* %4, i32 %13)
ret i32 0
}