#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 line1[80], line2[80];
  char searchStr[80];
  char *searchPtr;
  int count = 0;
  printf("Enter line 1: ");
  getLine(line1, 80);
  printf("Enter line 2: ");
  getLine(line2, 80);
  printf("Enter search string: ");
  getLine(searchStr, 80);
  searchPtr = strstr(line1, searchStr);
  while (searchPtr != NULL) {
    count++;
    searchPtr = strstr(searchPtr + 1, searchStr);
  }
  searchPtr = strstr(line2, searchStr);
  while (searchPtr != NULL) {
    count++;
    searchPtr = strstr(searchPtr + 1, searchStr);
  }
  printf("%d occurrences of '%s' found in the text\n", count, searchStr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10c(%rbp)
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    $0x50,%esi
call   1040 <getLine@plt>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xb0(%rbp),%rdi
mov    $0x50,%esi
call   1040 <getLine@plt>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x100(%rbp),%rdi
mov    $0x50,%esi
call   1040 <getLine@plt>
lea    -0x60(%rbp),%rdi
lea    -0x100(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x108(%rbp)
cmpq   $0x0,-0x108(%rbp)
je     11fd <main+0xcd>
mov    -0x10c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10c(%rbp)
mov    -0x108(%rbp),%rdi
add    $0x1,%rdi
lea    -0x100(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x108(%rbp)
jmp    11bd <main+0x8d>
lea    -0xb0(%rbp),%rdi
lea    -0x100(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x108(%rbp)
cmpq   $0x0,-0x108(%rbp)
je     1257 <main+0x127>
mov    -0x10c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10c(%rbp)
mov    -0x108(%rbp),%rdi
add    $0x1,%rdi
lea    -0x100(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x108(%rbp)
jmp    1217 <main+0xe7>
mov    -0x10c(%rbp),%esi
lea    -0x100(%rbp),%rdx
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xf0,%rsp
lea    0xebd(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xa0(%rsp),%r14
mov    %r14,%rdi
mov    $0x50,%esi
call   1040 <getLine@plt>
lea    0xea7(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x50(%rsp),%rdi
mov    $0x50,%esi
call   1040 <getLine@plt>
lea    0xe99(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x50,%esi
call   1040 <getLine@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     11d7 <main+0xa7>
xor    %ebx,%ebx
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
add    $0x1,%rax
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
jne    11c0 <main+0x90>
lea    0x50(%rsp),%rdi
mov    %rsp,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1207 <main+0xd7>
mov    %rsp,%r14
nopl   0x0(%rax)
add    $0x1,%ebx
add    $0x1,%rax
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
jne    11f0 <main+0xc0>
lea    0xe26(%rip),%rdi
mov    %rsp,%rdx
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Enter line 1: \00"
@.str.1 = [15 x i8] c"Enter line 2: \00"
@.str.2 = [22 x i8] c"Enter search string: \00"
@.str.3 = [42 x i8] c"%d occurrences of '%s' found in the text\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca [80 x i8]
%4 = alloca [80 x i8]
%5 = alloca i8*
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%9 = call i32 @getLine(i8* %8, i32 80)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%12 = call i32 @getLine(i8* %11, i32 80)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%15 = call i32 @getLine(i8* %14, i32 80)
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%18 = call i8* @strstr(i8* %16, i8* %17)
store i8* %18, i8** %5
br label %19
19: ; preds = %22, %0
%20 = load i8*, i8** %5
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%28 = call i8* @strstr(i8* %26, i8* %27)
store i8* %28, i8** %5
br label %19
29: ; preds = %19
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%31 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%32 = call i8* @strstr(i8* %30, i8* %31)
store i8* %32, i8** %5
br label %33
33: ; preds = %36, %29
%34 = load i8*, i8** %5
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %43
36: ; preds = %33
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%42 = call i8* @strstr(i8* %40, i8* %41)
store i8* %42, i8** %5
br label %33
43: ; preds = %33
%44 = load i32, i32* %6
%45 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %44, i8* %45)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"Enter line 1: \00"
@.str.1 = [15 x i8] c"Enter line 2: \00"
@.str.2 = [22 x i8] c"Enter search string: \00"
@.str.3 = [42 x i8] c"%d occurrences of '%s' found in the text\0A\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = alloca [80 x i8]
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @getLine(i8* %4, i32 80)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @getLine(i8* %5, i32 80)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @getLine(i8* %6, i32 80)
%13 = call i8* @strstr(i8* %4, i8* %6)
%14 = icmp eq i8* %13, null
br i1 %14, label %22, label %15
15: ; preds = %0, %15
%16 = phi i32 [ %18, %15 ], [ 0, %0 ]
%17 = phi i8* [ %20, %15 ], [ %13, %0 ]
%18 = add nuw nsw i32 %16, 1
%19 = getelementptr inbounds i8, i8* %17, i64 1
%20 = call i8* @strstr(i8* %19, i8* %6)
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %15
22: ; preds = %15, %0
%23 = phi i32 [ 0, %0 ], [ %18, %15 ]
%24 = call i8* @strstr(i8* %5, i8* %6)
%25 = icmp eq i8* %24, null
br i1 %25, label %33, label %26
26: ; preds = %22, %26
%27 = phi i32 [ %29, %26 ], [ %23, %22 ]
%28 = phi i8* [ %31, %26 ], [ %24, %22 ]
%29 = add nuw nsw i32 %27, 1
%30 = getelementptr inbounds i8, i8* %28, i64 1
%31 = call i8* @strstr(i8* %30, i8* %6)
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %26
33: ; preds = %26, %22
%34 = phi i32 [ %23, %22 ], [ %29, %26 ]
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %34, i8* %6)
ret i32 0
}