#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*/ getLine(char *, int);
int /*<<< orphan*/ printf(char *, ...);
char *strstr(char *, char *);
int main() {
  char text[80];
  char searchStr[80];
  char *searchPtr;
  printf("Enter text: ");
  getLine(text, 80);
  printf("Enter search string: ");
  getLine(searchStr, 80);
  searchPtr = strstr(text, searchStr);
  while (searchPtr != NULL) {
    printf("%s\n", searchPtr);
    searchPtr = strstr(searchPtr + 1, searchStr);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    $0x50,%esi
call   1040 <getLine@plt>
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xb0(%rbp),%rdi
mov    $0x50,%esi
call   1040 <getLine@plt>
lea    -0x60(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0xb8(%rbp)
cmpq   $0x0,-0xb8(%rbp)
je     11da <main+0xaa>
mov    -0xb8(%rbp),%rsi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xb8(%rbp),%rdi
add    $0x1,%rdi
lea    -0xb0(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0xb8(%rbp)
jmp    1194 <main+0x64>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xa8,%rsp
lea    0xeaf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x50(%rsp),%r14
mov    %r14,%rdi
mov    $0x50,%esi
call   1050 <getLine@plt>
lea    0xe9c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x50,%esi
call   1050 <getLine@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     11bf <main+0x7f>
mov    %rax,%rbx
mov    %rsp,%r14
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <puts@plt>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a0 <main+0x60>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Enter text: \00"
@.str.1 = [22 x i8] c"Enter search string: \00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca [80 x i8]
%4 = alloca i8*
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%7 = call i32 @getLine(i8* %6, i32 80)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%10 = call i32 @getLine(i8* %9, i32 80)
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%13 = call i8* @strstr(i8* %11, i8* %12)
store i8* %13, i8** %4
br label %14
14: ; preds = %17, %0
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = load i8*, i8** %4
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%23 = call i8* @strstr(i8* %21, i8* %22)
store i8* %23, i8** %4
br label %14
24: ; preds = %14
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"Enter text: \00"
@.str.1 = [22 x i8] c"Enter search string: \00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @getLine(i8* %3, i32 80)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @getLine(i8* %4, i32 80)
%9 = call i8* @strstr(i8* %3, i8* %4)
%10 = icmp eq i8* %9, null
br i1 %10, label %17, label %11
11: ; preds = %0, %11
%12 = phi i8* [ %15, %11 ], [ %9, %0 ]
%13 = call i32 @puts(i8* %12)
%14 = getelementptr inbounds i8, i8* %12, i64 1
%15 = call i8* @strstr(i8* %14, i8* %4)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %11
17: ; preds = %11, %0
ret i32 0
}