#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*/ gets(char *);
int /*<<< orphan*/ memmove(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int strlen(char *);
char *strstr(char *, char *);
main() {
  char s1[100];
  char s2[100];
  char *ptr;
  puts("enter s1");
  gets(s1);
  puts("enter s2");
  gets(s2);
  ptr = s1;
  while (ptr = strstr(ptr, s2)) {
    memmove(ptr, ptr + strlen(s2), strlen(ptr) - 1);
    ptr += strlen(s2);
  }
  printf("%s\n", s1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
call   1030 <puts@plt>
lea    -0x70(%rbp),%rdi
call   1060 <gets@plt>
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
lea    -0xe0(%rbp),%rdi
call   1060 <gets@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0xe8(%rbp)
mov    -0xe8(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
call   1080 <strstr@plt>
mov    %rax,-0xe8(%rbp)
cmp    $0x0,%rax
je     1257 <main+0xf7>
mov    -0xe8(%rbp),%rax
mov    %rax,-0xf8(%rbp)
mov    -0xe8(%rbp),%rax
mov    %rax,-0x100(%rbp)
lea    -0xe0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x100(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0xf0(%rbp)
mov    -0xe8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xf8(%rbp),%rdi
mov    -0xf0(%rbp),%rsi
mov    %eax,%edx
sub    $0x1,%edx
call   1070 <memmove@plt>
lea    -0xe0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0xe8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0xe8(%rbp)
jmp    11aa <main+0x4a>
lea    -0x70(%rbp),%rsi
lea    0xdb0(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xe0,%rsp
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
lea    0x70(%rsp),%r14
mov    %r14,%rdi
call   1060 <gets@plt>
lea    0xe7d(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <gets@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     1202 <main+0xa2>
mov    %rax,%rbx
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <strlen@plt>
movslq %eax,%r15
add    %rbx,%r15
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    -0x1(%rax),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <memmove@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
movslq %eax,%rdi
add    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11c0 <main+0x60>
lea    0xe09(%rip),%rdi
lea    0x70(%rsp),%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"enter s1\00"
@.str.1 = [9 x i8] c"enter s2\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = alloca i8*
store i32 0, i32* %1
%5 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = call i32 @gets(i8* %6)
%8 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%10 = call i32 @gets(i8* %9)
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
store i8* %11, i8** %4
br label %12
12: ; preds = %17, %0
%13 = load i8*, i8** %4
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%15 = call i8* @strstr(i8* %13, i8* %14)
store i8* %15, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %33
17: ; preds = %12
%18 = load i8*, i8** %4
%19 = load i8*, i8** %4
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = load i8*, i8** %4
%25 = call i32 @strlen(i8* %24)
%26 = sub nsw i32 %25, 1
%27 = call i32 @memmove(i8* %18, i8* %23, i32 %26)
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
%30 = load i8*, i8** %4
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8, i8* %30, i64 %31
store i8* %32, i8** %4
br label %12
33: ; preds = %12
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@.str = [9 x i8] c"enter s1\00"
@.str.1 = [9 x i8] c"enter s2\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @gets(i8* %3)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @gets(i8* %4)
%9 = call i8* @strstr(i8* dereferenceable(1) %3, i8* %4)
%10 = icmp eq i8* %9, null
br i1 %10, label %24, label %11
11: ; preds = %0, %11
%12 = phi i8* [ %22, %11 ], [ %9, %0 ]
%13 = call i32 @strlen(i8* %4)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = call i32 @strlen(i8* %12)
%17 = add nsw i32 %16, -1
%18 = call i32 @memmove(i8* %12, i8* %15, i32 %17)
%19 = call i32 @strlen(i8* %4)
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %12, i64 %20
%22 = call i8* @strstr(i8* dereferenceable(1) %21, i8* %4)
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %11
24: ; preds = %11, %0
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %3)
ret i32 0
}