#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*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int string_matching(char *, char *);
size_t strlen(char *);
int main(void) {
  char *src = "ababqweababqwababaqweabababbbaa";
  char *target = "ababb";
  int index = string_matching(src, target);
  if (index != -1) {
    size_t length_target = strlen(target);
    printf("the src string contains the target string at index:%d", index);
    printf("\nthe target string is: ");
    int i = 0;
    for (i = 0; i < length_target; i++) {
      printf("%c", src[index + i]);
    }
  } else {
    printf("the src string doesn't contain the target string...");
  }
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xebf(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <string_matching@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
je     11f9 <main+0xb9>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11f4 <main+0xb4>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x2c(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b9 <main+0x79>
jmp    1207 <main+0xc7>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rbx
lea    0xecf(%rip),%rsi
mov    %rbx,%rdi
call   1040 <string_matching@plt>
cmp    $0xffffffff,%eax
je     11b5 <main+0x75>
mov    %eax,%ebp
lea    0xebf(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xee5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movslq %ebp,%rbp
movsbl 0x0(%rbp,%rbx,1),%edi
call   1030 <putchar@plt>
movsbl 0x1(%rbp,%rbx,1),%edi
call   1030 <putchar@plt>
movsbl 0x2(%rbp,%rbx,1),%edi
call   1030 <putchar@plt>
movsbl 0x3(%rbp,%rbx,1),%edi
call   1030 <putchar@plt>
movsbl 0x4(%rbp,%rbx,1),%edi
call   1030 <putchar@plt>
jmp    11c3 <main+0x83>
lea    0xeb8(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"ababqweababqwababaqweabababbbaa\00"
@.str.1 = [6 x i8] c"ababb\00"
@.str.2 = [54 x i8] c"the src string contains the target string at index:%d\00"
@.str.3 = [24 x i8] c"\0Athe target string is: \00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [52 x i8] c"the src string doesn't contain the target string...\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %3
%7 = load i8*, i8** %2
%8 = load i8*, i8** %3
%9 = call i32 @string_matching(i8* %7, i8* %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, -1
br i1 %11, label %12, label %37
12: ; preds = %0
%13 = load i8*, i8** %3
%14 = call i64 @strlen(i8* %13)
store i64 %14, i64* %5
%15 = load i32, i32* %4
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %6
store i32 0, i32* %6
br label %18
18: ; preds = %33, %12
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = load i64, i64* %5
%22 = icmp ult i64 %20, %21
br i1 %22, label %23, label %36
23: ; preds = %18
%24 = load i8*, i8** %2
%25 = load i32, i32* %4
%26 = load i32, i32* %6
%27 = add nsw i32 %25, %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %24, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %23
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
br label %18
36: ; preds = %18
br label %39
37: ; preds = %0
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0))
br label %39
39: ; preds = %37, %36
%40 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"ababqweababqwababaqweabababbbaa\00"
@.str.1 = [6 x i8] c"ababb\00"
@.str.2 = [54 x i8] c"the src string contains the target string at index:%d\00"
@.str.3 = [24 x i8] c"\0Athe target string is: \00"
@.str.5 = [52 x i8] c"the src string doesn't contain the target string...\00"
define i32 @main() {
%1 = tail call i32 @string_matching(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32 %1, -1
br i1 %2, label %31, label %3
3: ; preds = %0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%6 = sext i32 %1 to i64
%7 = getelementptr inbounds [32 x i8], [32 x i8]* @.str, i64 0, i64 %6
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = tail call i32 @putchar(i32 %9)
%11 = add nsw i64 %6, 1
%12 = getelementptr inbounds [32 x i8], [32 x i8]* @.str, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = tail call i32 @putchar(i32 %14)
%16 = add nsw i64 %6, 2
%17 = getelementptr inbounds [32 x i8], [32 x i8]* @.str, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = tail call i32 @putchar(i32 %19)
%21 = add nsw i64 %6, 3
%22 = getelementptr inbounds [32 x i8], [32 x i8]* @.str, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = tail call i32 @putchar(i32 %24)
%26 = add nsw i64 %6, 4
%27 = getelementptr inbounds [32 x i8], [32 x i8]* @.str, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = tail call i32 @putchar(i32 %29)
br label %33
31: ; preds = %0
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0))
br label %33
33: ; preds = %3, %31
%34 = tail call i32 (...) @getchar()
ret i32 0
}