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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe67(%rip),%rdi
call   1050 <puts@plt>
lea    -0x70(%rbp),%rdi
call   1080 <gets@plt>
lea    0xe5b(%rip),%rdi
call   1050 <puts@plt>
lea    -0xe0(%rbp),%rdi
call   1080 <gets@plt>
lea    -0x150(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x150(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
call   1030 <reverse@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x158(%rbp)
mov    -0x158(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x158(%rbp)
cmp    $0x0,%rax
je     1268 <main+0xe8>
mov    -0x158(%rbp),%rax
mov    %rax,-0x168(%rbp)
lea    -0x150(%rbp),%rax
mov    %rax,-0x160(%rbp)
lea    -0x150(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x168(%rbp),%rdi
mov    -0x160(%rbp),%rsi
mov    %eax,%edx
call   1090 <memmove@plt>
mov    -0x158(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x158(%rbp)
jmp    11f0 <main+0x70>
lea    -0x70(%rbp),%rsi
lea    0xd9f(%rip),%rdi
call   1070 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x150,%rsp
lea    0xe6d(%rip),%rdi
call   1050 <puts@plt>
lea    0xe0(%rsp),%r14
mov    %r14,%rdi
call   1080 <gets@plt>
lea    0xe5a(%rip),%rdi
call   1050 <puts@plt>
lea    0x70(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <gets@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <reverse@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10a0 <strstr@plt>
test   %rax,%rax
je     122c <main+0xac>
mov    %rax,%rbx
mov    %rsp,%r14
lea    0x70(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1090 <memmove@plt>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   10a0 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1200 <main+0x80>
lea    0xddf(%rip),%rdi
lea    0xe0(%rsp),%rsi
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x150,%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 [100 x i8]
%5 = alloca i8*
store i32 0, i32* %1
%6 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%8 = call i32 @gets(i8* %7)
%9 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%11 = call i32 @gets(i8* %10)
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%17 = call i32 @reverse(i8* %15, i8* %16)
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
store i8* %18, i8** %5
br label %19
19: ; preds = %24, %0
%20 = load i8*, i8** %5
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%22 = call i8* @strstr(i8* %20, i8* %21)
store i8* %22, i8** %5
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %32
24: ; preds = %19
%25 = load i8*, i8** %5
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
%29 = call i32 @memmove(i8* %25, i8* %26, i32 %28)
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %5
br label %19
32: ; preds = %19
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = load i32, i32* %1
ret i32 %35
}

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 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @gets(i8* %4)
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @gets(i8* %5)
%11 = call i32 @strcpy(i8* %6, i8* %5)
%12 = call i32 @reverse(i8* %6, i8* %5)
%13 = call i8* @strstr(i8* dereferenceable(1) %4, i8* %5)
%14 = icmp eq i8* %13, null
br i1 %14, label %22, label %15
15: ; preds = %0, %15
%16 = phi i8* [ %20, %15 ], [ %13, %0 ]
%17 = call i32 @strlen(i8* %6)
%18 = call i32 @memmove(i8* %16, i8* %6, i32 %17)
%19 = getelementptr inbounds i8, i8* %16, i64 1
%20 = call i8* @strstr(i8* dereferenceable(1) %19, i8* %5)
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %15
22: ; preds = %15, %0
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %4)
ret i32 0
}