#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
int main() {
  printf("Enter the String: \n");
  int i = 0, count = 0;
  ;
  char str1[100], key[100], str2[100];
  scanf("%s", str1);
  printf("Enter The Key: \n");
  scanf("%s", key);
  strcpy(str2, str1);
  while (strstr(str2, key) && count < 5) {
    count++;
    strcpy(str2, strstr(str1, key));
    for (i = strlen(key); i <= strlen(str2); i++)
      str1[i - strlen(key)] = str2[i];
    strncpy(str2, str1, strlen(str1));
    str2[strlen(str1)] = '\0';
    str2[strlen(str1) + 1] = '\0';
  }
  printf("No. of Time \"%s\" appears is: ", key);
  printf("%d \n", count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x70(%rbp),%rsi
lea    0xe7b(%rip),%rdi
call   1070 <scanf@plt>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xe0(%rbp),%rsi
lea    0xe5a(%rip),%rdi
call   1070 <scanf@plt>
lea    -0x150(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x150(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
call   1080 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x151(%rbp)
je     1204 <main+0xa4>
cmpl   $0x5,-0xc(%rbp)
setl   %al
mov    %al,-0x151(%rbp)
mov    -0x151(%rbp),%al
test   $0x1,%al
jne    1217 <main+0xb7>
jmp    1330 <main+0x1d0>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
lea    -0x150(%rbp),%rax
mov    %rax,-0x160(%rbp)
lea    -0x70(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
call   1080 <strstr@plt>
mov    -0x160(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
lea    -0xe0(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x164(%rbp)
lea    -0x150(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x164(%rbp),%eax
cmp    %ecx,%eax
jg     12cb <main+0x16b>
movslq -0x8(%rbp),%rax
mov    -0x150(%rbp,%rax,1),%al
mov    %al,-0x169(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x168(%rbp)
lea    -0xe0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x169(%rbp),%cl
mov    %eax,%edx
mov    -0x168(%rbp),%eax
sub    %edx,%eax
cltq
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    125c <main+0xfc>
lea    -0x150(%rbp),%rax
mov    %rax,-0x180(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x178(%rbp)
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x180(%rbp),%rdi
mov    -0x178(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x150(%rbp,%rax,1)
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
movb   $0x0,-0x150(%rbp,%rax,1)
jmp    11cf <main+0x6f>
lea    -0xe0(%rbp),%rsi
lea    0xcea(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xcf7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
lea    0xe9e(%rip),%rdi
call   1050 <puts@plt>
lea    0xe6c(%rip),%rbx
lea    0xe0(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <scanf@plt>
lea    0xe8b(%rip),%rdi
call   1050 <puts@plt>
lea    0x70(%rsp),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <scanf@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     12c9 <main+0x159>
xor    %r12d,%r12d
lea    0xe0(%rsp),%r14
lea    0x70(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %r13,%rsi
call   1090 <strstr@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1060 <strlen@plt>
cmp    %eax,%ebp
jg     1272 <main+0x102>
movslq %ebp,%rbp
add    $0xffffffffffffffff,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl 0x1(%rsp,%rbp,1),%ebx
mov    %r13,%rdi
call   1060 <strlen@plt>
cltq
neg    %rax
add    %rsp,%rax
add    $0xe0,%rax
mov    %bl,0x1(%rbp,%rax,1)
mov    %r15,%rdi
call   1060 <strlen@plt>
cltq
add    $0x1,%rbp
cmp    %rax,%rbp
jl     1240 <main+0xd0>
lea    0x1(%r12),%ebp
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,0x1(%rax,%r15,1)
mov    %r15,%rdi
mov    %r13,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     12cb <main+0x15b>
cmp    $0x4,%r12d
mov    %ebp,%r12d
jb     1200 <main+0x90>
jmp    12cb <main+0x15b>
xor    %ebp,%ebp
lea    0xd31(%rip),%rdi
lea    0x70(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd3c(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Enter the String: \0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [17 x i8] c"Enter The Key: \0A\00"
@.str.3 = [30 x i8] c"No. of Time \22%s\22 appears is: \00"
@.str.4 = [5 x i8] c"%d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = alloca [100 x i8]
%6 = alloca [100 x i8]
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
store i32 0, i32* %3
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%15 = call i32 @strcpy(i8* %13, i8* %14)
br label %16
16: ; preds = %55, %0
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%19 = call i8* @strstr(i8* %17, i8* %18)
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i32, i32* %3
%23 = icmp slt i32 %22, 5
br label %24
24: ; preds = %21, %16
%25 = phi i1 [ false, %16 ], [ %23, %21 ]
br i1 %25, label %26, label %70
26: ; preds = %24
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%32 = call i8* @strstr(i8* %30, i8* %31)
%33 = call i32 @strcpy(i8* %29, i8* %32)
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%35 = call i32 @strlen(i8* %34)
store i32 %35, i32* %2
br label %36
36: ; preds = %52, %26
%37 = load i32, i32* %2
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%39 = call i32 @strlen(i8* %38)
%40 = icmp sle i32 %37, %39
br i1 %40, label %41, label %55
41: ; preds = %36
%42 = load i32, i32* %2
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = load i32, i32* %2
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%48 = call i32 @strlen(i8* %47)
%49 = sub nsw i32 %46, %48
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %50
store i8 %45, i8* %51
br label %52
52: ; preds = %41
%53 = load i32, i32* %2
%54 = add nsw i32 %53, 1
store i32 %54, i32* %2
br label %36
55: ; preds = %36
%56 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%57 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%58 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%59 = call i32 @strlen(i8* %58)
%60 = call i32 @strncpy(i8* %56, i8* %57, i32 %59)
%61 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%62 = call i32 @strlen(i8* %61)
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %63
store i8 0, i8* %64
%65 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%66 = call i32 @strlen(i8* %65)
%67 = add nsw i32 %66, 1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %68
store i8 0, i8* %69
br label %16
70: ; preds = %24
%71 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %71)
%73 = load i32, i32* %3
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %73)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@.str.3 = [30 x i8] c"No. of Time \22%s\22 appears is: \00"
@.str.4 = [5 x i8] c"%d \0A\00"
@str = [19 x i8] c"Enter the String: \00"
@str.5 = [16 x i8] c"Enter The Key: \00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.5, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%11 = call i32 @strcpy(i8* %7, i8* %5)
%12 = call i8* @strstr(i8* %7, i8* %6)
%13 = icmp eq i8* %12, null
br i1 %13, label %50, label %14
14: ; preds = %0, %36
%15 = phi i32 [ %16, %36 ], [ 0, %0 ]
%16 = add nuw nsw i32 %15, 1
%17 = call i8* @strstr(i8* %5, i8* %6)
%18 = call i32 @strcpy(i8* %7, i8* %17)
%19 = call i32 @strlen(i8* %6)
%20 = call i32 @strlen(i8* %7)
%21 = icmp sgt i32 %19, %20
br i1 %21, label %36, label %22
22: ; preds = %14
%23 = sext i32 %19 to i64
br label %24
24: ; preds = %22, %24
%25 = phi i64 [ %23, %22 ], [ %32, %24 ]
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = call i32 @strlen(i8* %6)
%29 = sext i32 %28 to i64
%30 = sub nsw i64 %25, %29
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %30
store i8 %27, i8* %31
%32 = add nsw i64 %25, 1
%33 = call i32 @strlen(i8* %7)
%34 = sext i32 %33 to i64
%35 = icmp slt i64 %25, %34
br i1 %35, label %24, label %36
36: ; preds = %24, %14
%37 = call i32 @strlen(i8* %5)
%38 = call i32 @strncpy(i8* %7, i8* %5, i32 %37)
%39 = call i32 @strlen(i8* %5)
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %40
store i8 0, i8* %41
%42 = call i32 @strlen(i8* %5)
%43 = add nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %44
store i8 0, i8* %45
%46 = call i8* @strstr(i8* %7, i8* %6)
%47 = icmp ne i8* %46, null
%48 = icmp ult i32 %15, 4
%49 = select i1 %47, i1 %48, i1 false
br i1 %49, label %14, label %50
50: ; preds = %36, %0
%51 = phi i32 [ 0, %0 ], [ %16, %36 ]
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %51)
ret i32 0
}