#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*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int replst(char *str, int i, int sl, const char *repl) {
  char str1[1024];
  char str2[1024];
  char str3[1024];
  strncpy(str1, str, i);
  str1[i] = '\0';
  strcat(str1, repl);
  strcat(str1, &str[i + sl]);
  strcpy(str, str1);
  return 0;
}


x86 assembly (clang, -O0):
<replst>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <strncpy@plt>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcat@plt>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
cltq
add    %rax,%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1040 <strcpy@plt>
xor    %eax,%eax
add    $0xc20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replst>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rcx,%r15
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rsp,%r12
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rbp
movb   $0x0,(%rsp,%rbp,1)
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
add    %r14d,%ebp
movslq %ebp,%rsi
add    %rbx,%rsi
mov    %r12,%rdi
call   1050 <strcat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @replst(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [1024 x i8]
%10 = alloca [1024 x i8]
%11 = alloca [1024 x i8]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%13 = load i8*, i8** %5
%14 = load i32, i32* %6
%15 = call i32 @strncpy(i8* %12, i8* %13, i32 %14)
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 %17
store i8 0, i8* %18
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%20 = load i8*, i8** %8
%21 = call i32 @strcat(i8* %19, i8* %20)
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%23 = load i8*, i8** %5
%24 = load i32, i32* %6
%25 = load i32, i32* %7
%26 = add nsw i32 %24, %25
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %23, i64 %27
%29 = call i32 @strcat(i8* %22, i8* %28)
%30 = load i8*, i8** %5
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%32 = call i32 @strcpy(i8* %30, i8* %31)
ret i32 0
}

LLVM IR (-O2):
define i32 @replst(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%7 = call i32 @strncpy(i8* %6, i8* %0, i32 %1)
%8 = sext i32 %1 to i64
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %8
store i8 0, i8* %9
%10 = call i32 @strcat(i8* %6, i8* %3)
%11 = add nsw i32 %2, %1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = call i32 @strcat(i8* %6, i8* %13)
%15 = call i32 @strcpy(i8* %0, i8* %6)
ret i32 0
}