#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 */
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int /*<<< orphan*/);
int main() {
  int i = 0, j;
  char words[15][20];
  char t, key[20], word[20];
  printf("Enter The Word to Replace: ");
  scanf("%s", word);
  printf("Enter the Key Word: ");
  scanf("%s", key);
  printf("Enter The String: ");
  do {
    scanf("%s", words[i]);
    if (strcmp(words[i], word) == 0)
      strncpy(words[i], key, strlen(key));
    i++;
  } while ((t = getchar()) != '\n');
  for (j = 0; j < i; j++)
    printf("%s ", words[j]);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x180(%rbp),%rsi
lea    0xe87(%rip),%rdi
call   1080 <scanf@plt>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x160(%rbp),%rsi
lea    0xe66(%rip),%rdi
call   1080 <scanf@plt>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movslq -0x8(%rbp),%rax
lea    -0x140(%rbp),%rsi
imul   $0x14,%rax,%rax
add    %rax,%rsi
lea    0xe3a(%rip),%rdi
call   1080 <scanf@plt>
movslq -0x8(%rbp),%rax
lea    -0x140(%rbp),%rdi
imul   $0x14,%rax,%rax
add    %rax,%rdi
lea    -0x180(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1257 <main+0xf7>
movslq -0x8(%rbp),%rcx
lea    -0x140(%rbp),%rax
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
mov    %rax,-0x190(%rbp)
lea    -0x160(%rbp),%rax
mov    %rax,-0x188(%rbp)
lea    -0x160(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x190(%rbp),%rdi
mov    -0x188(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %al,-0x141(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
jne    11c9 <main+0x69>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12ba <main+0x15a>
movslq -0xc(%rbp),%rax
lea    -0x140(%rbp),%rsi
imul   $0x14,%rax,%rax
add    %rax,%rsi
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1280 <main+0x120>
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x190,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x170,%rsp
lea    0xe7a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe88(%rip),%r12
mov    %rsp,%r14
mov    %r12,%rdi
mov    %r14,%rsi
call   1090 <scanf@plt>
lea    0xe76(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x20(%rsp),%r15
mov    %r12,%rdi
mov    %r15,%rsi
call   1090 <scanf@plt>
lea    0xe6d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x40(%rsp),%rbx
xor    %ebp,%ebp
jmp    11f2 <main+0x82>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <getchar@plt>
add    $0x1,%ebp
add    $0x14,%rbx
cmp    $0xa,%al
je     1224 <main+0xb4>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1090 <scanf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    11e0 <main+0x70>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <strncpy@plt>
jmp    11e0 <main+0x70>
mov    %ebp,%ebp
lea    0x40(%rsp),%rbx
lea    0xe15(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x14,%rbx
add    $0xffffffffffffffff,%rbp
jne    1240 <main+0xd0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x170,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Enter The Word to Replace: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [21 x i8] c"Enter the Key Word: \00"
@.str.3 = [19 x i8] c"Enter The String: \00"
@.str.4 = [4 x i8] c"%s \00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [15 x [20 x i8]]
%5 = alloca i8
%6 = alloca [20 x i8]
%7 = alloca [20 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %40, %0
%16 = load i32, i32* %2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [15 x [20 x i8]], [15 x [20 x i8]]* %4, i64 0, i64 %17
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %18, i64 0, i64 0
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i32, i32* %2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [15 x [20 x i8]], [15 x [20 x i8]]* %4, i64 0, i64 %22
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %23, i64 0, i64 0
%25 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%26 = call i64 @strcmp(i8* %24, i8* %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %15
%29 = load i32, i32* %2
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [15 x [20 x i8]], [15 x [20 x i8]]* %4, i64 0, i64 %30
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %31, i64 0, i64 0
%33 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%34 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%35 = call i32 @strlen(i8* %34)
%36 = call i32 @strncpy(i8* %32, i8* %33, i32 %35)
br label %37
37: ; preds = %28, %15
%38 = load i32, i32* %2
%39 = add nsw i32 %38, 1
store i32 %39, i32* %2
br label %40
40: ; preds = %37
%41 = call signext i8 (...) @getchar()
store i8 %41, i8* %5
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 10
br i1 %43, label %15, label %44
44: ; preds = %40
store i32 0, i32* %3
br label %45
45: ; preds = %55, %44
%46 = load i32, i32* %3
%47 = load i32, i32* %2
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %58
49: ; preds = %45
%50 = load i32, i32* %3
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [15 x [20 x i8]], [15 x [20 x i8]]* %4, i64 0, i64 %51
%53 = getelementptr inbounds [20 x i8], [20 x i8]* %52, i64 0, i64 0
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %49
%56 = load i32, i32* %3
%57 = add nsw i32 %56, 1
store i32 %57, i32* %3
br label %45
58: ; preds = %45
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [28 x i8] c"Enter The Word to Replace: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [21 x i8] c"Enter the Key Word: \00"
@.str.3 = [19 x i8] c"Enter The String: \00"
@.str.4 = [4 x i8] c"%s \00"
define i32 @main() {
%1 = alloca [15 x [20 x i8]]
%2 = alloca [20 x i8]
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [15 x [20 x i8]], [15 x [20 x i8]]* %1, i64 0, i64 0, i64 0
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %12
12: ; preds = %21, %0
%13 = phi i64 [ %22, %21 ], [ 0, %0 ]
%14 = getelementptr inbounds [15 x [20 x i8]], [15 x [20 x i8]]* %1, i64 0, i64 %13, i64 0
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = call i64 @strcmp(i8* %14, i8* %6)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = call i32 @strlen(i8* %5)
%20 = call i32 @strncpy(i8* %14, i8* %5, i32 %19)
br label %21
21: ; preds = %18, %12
%22 = add nuw i64 %13, 1
%23 = call signext i8 (...) @getchar()
%24 = icmp eq i8 %23, 10
br i1 %24, label %25, label %12
25: ; preds = %21
%26 = add i64 %13, 1
%27 = and i64 %26, 4294967295
br label %28
28: ; preds = %25, %28
%29 = phi i64 [ 0, %25 ], [ %32, %28 ]
%30 = getelementptr inbounds [15 x [20 x i8]], [15 x [20 x i8]]* %1, i64 0, i64 %29, i64 0
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %30)
%32 = add nuw nsw i64 %29, 1
%33 = icmp eq i64 %32, %27
br i1 %33, label %34, label %28
34: ; preds = %28
%35 = call i32 @putchar(i32 10)
ret i32 0
}