#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*/ getch();
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ strrep(char *, char *, int);
void main() {
  char string1[100];
  char string2[50];
  int position;
  printf("\nPlease input original string:");
  gets(string1);
  printf("\nPlease input substitute string:");
  gets(string2);
  scanf("%d", &position);
  strrep(string1, string2, position);
  printf("\nThe final string:%s\n", string1);
  getch();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
call   1040 <gets@plt>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xb0(%rbp),%rdi
call   1040 <gets@plt>
lea    0xead(%rip),%rdi
lea    -0xb4(%rbp),%rsi
call   1060 <scanf@plt>
lea    -0x70(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    -0xb4(%rbp),%edx
call   1050 <strrep@plt>
lea    -0x70(%rbp),%rsi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1070 <getch@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xb8,%rsp
lea    0xe9f(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x50(%rsp),%r14
mov    %r14,%rdi
call   1040 <gets@plt>
lea    0xea3(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <gets@plt>
lea    0xea9(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <strrep@plt>
lea    0xe8c(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1070 <getch@plt>
add    $0xb8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [31 x i8] c"\0APlease input original string:\00"
@.str.1 = [33 x i8] c"\0APlease input substitute string:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [22 x i8] c"\0AThe final string:%s\0A\00"
define void @main() {
%1 = alloca [100 x i8]
%2 = alloca [50 x i8]
%3 = alloca i32
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%6 = call i32 @gets(i8* %5)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%9 = call i32 @gets(i8* %8)
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%13 = load i32, i32* %3
%14 = call i32 @strrep(i8* %11, i8* %12, i32 %13)
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = call i32 (...) @getch()
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"\0APlease input original string:\00"
@.str.1 = [33 x i8] c"\0APlease input substitute string:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [22 x i8] c"\0AThe final string:%s\0A\00"
define void @main() {
%1 = alloca [100 x i8]
%2 = alloca [50 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @gets(i8* %4)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @gets(i8* %5)
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%12 = load i32, i32* %3
%13 = call i32 @strrep(i8* %4, i8* %5, i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%15 = call i32 (...) @getch()
ret void
}