#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
char *strstr(char *, char *);
int main() {
  char s1[30];
  char s2[30];
  char *searchPtr = NULL;
  char *sPtr;
  int i = 0;
  printf("Please input the text:\n\t");
  fgets(s1, 30, stdin);
  sPtr = strchr(s1, '\n');
  *sPtr = '\0';
  printf("Please input the string you are finding:\n\t");
  fgets(s2, 30, stdin);
  sPtr = strchr(s2, '\n');
  *sPtr = '\0';
  searchPtr = strstr(s1, s2);
  if (searchPtr != NULL) {
    printf("\t%s\n", searchPtr);
    searchPtr = strstr(searchPtr + 1, s2);
    printf("\t%s\n", searchPtr);
  } else
    printf("Not Found!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x58(%rbp)
movl   $0x0,-0x64(%rbp)
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%edx
mov    $0x1e,%esi
call   1050 <fgets@plt>
lea    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
movb   $0x0,(%rax)
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    0x2e33(%rip),%rax
mov    (%rax),%edx
mov    $0x1e,%esi
call   1050 <fgets@plt>
lea    -0x50(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     1234 <main+0xf4>
mov    -0x58(%rbp),%rsi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x58(%rbp),%rdi
add    $0x1,%rdi
lea    -0x50(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rsi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1242 <main+0x102>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
lea    0xea2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e7c(%rip),%rbx
mov    (%rbx),%edx
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    $0x1e,%esi
call   1060 <fgets@plt>
mov    %r14,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
movb   $0x0,(%rax)
lea    0xe82(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1e,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
movb   $0x0,(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     1205 <main+0xb5>
mov    %rax,%rbx
lea    0xe6a(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1070 <strstr@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1211 <main+0xc1>
lea    0xe3d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Please input the text:\0A\09\00"
@stdin = global i32 0
@.str.1 = [43 x i8] c"Please input the string you are finding:\0A\09\00"
@.str.2 = [5 x i8] c"\09%s\0A\00"
@.str.3 = [12 x i8] c"Not Found!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [30 x i8]
%3 = alloca [30 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i32 0, i32* %1
store i8* null, i8** %4
store i32 0, i32* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %8, i32 30, i32 %9)
%11 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%12 = call i8* @strchr(i8* %11, i8 signext 10)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
store i8 0, i8* %13
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%16 = load i32, i32* @stdin
%17 = call i32 @fgets(i8* %15, i32 30, i32 %16)
%18 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%19 = call i8* @strchr(i8* %18, i8 signext 10)
store i8* %19, i8** %5
%20 = load i8*, i8** %5
store i8 0, i8* %20
%21 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%22 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%23 = call i8* @strstr(i8* %21, i8* %22)
store i8* %23, i8** %4
%24 = load i8*, i8** %4
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %35
26: ; preds = %0
%27 = load i8*, i8** %4
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%32 = call i8* @strstr(i8* %30, i8* %31)
store i8* %32, i8** %4
%33 = load i8*, i8** %4
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %33)
br label %37
35: ; preds = %0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %37
37: ; preds = %35, %26
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"Please input the text:\0A\09\00"
@stdin = global i32 0
@.str.1 = [43 x i8] c"Please input the string you are finding:\0A\09\00"
@.str.2 = [5 x i8] c"\09%s\0A\00"
@str = [11 x i8] c"Not Found!\00"
define i32 @main() {
%1 = alloca [30 x i8]
%2 = alloca [30 x i8]
%3 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %3, i32 30, i32 %6)
%8 = call i8* @strchr(i8* %3, i8 signext 10)
store i8 0, i8* %8
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %4, i32 30, i32 %10)
%12 = call i8* @strchr(i8* %4, i8 signext 10)
store i8 0, i8* %12
%13 = call i8* @strstr(i8* %3, i8* %4)
%14 = icmp eq i8* %13, null
br i1 %14, label %20, label %15
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%17 = getelementptr inbounds i8, i8* %13, i64 1
%18 = call i8* @strstr(i8* %17, i8* %4)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %18)
br label %22
20: ; preds = %0
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
ret i32 0
}