#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*/ shiftLeft(char *, int, int);
int /*<<< orphan*/ shiftRight(char *, int, int);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void replacestr(char *src, int from, int to, char *str) {
  if (to - from + 1 >= strlen(str)) {
    shiftLeft(src, to, to - from + 1 - strlen(str));
  } else {
    shiftRight(src, to, strlen(str) - (to - from + 1));
  }
  strncpy(str, src + from, strlen(str));
}


x86 assembly (clang, -O0):
<replacestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jl     11b1 <replacestr+0x71>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x2c(%rbp),%edx
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%esi
sub    %eax,%edx
call   1040 <shiftLeft@plt>
jmp    11e1 <replacestr+0xa1>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%esi
mov    %eax,%edx
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
add    $0x1,%eax
sub    %eax,%edx
call   1050 <shiftRight@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replacestr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r12d
mov    %esi,%r15d
mov    %rdi,%rbx
mov    %edx,%ebp
sub    %esi,%ebp
add    $0x1,%ebp
mov    %rcx,%rdi
call   1060 <strlen@plt>
mov    %eax,%r13d
mov    %r14,%rdi
call   1060 <strlen@plt>
cmp    %r13d,%ebp
jge    1187 <replacestr+0x47>
sub    %ebp,%eax
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %eax,%edx
call   1050 <shiftRight@plt>
jmp    1196 <replacestr+0x56>
sub    %eax,%ebp
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %ebp,%edx
call   1040 <shiftLeft@plt>
movslq %r15d,%rax
add    %rax,%rbx
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strncpy@plt>

LLVM IR (-O0):
define void @replacestr(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = sub nsw i32 %9, %10
%12 = add nsw i32 %11, 1
%13 = load i8*, i8** %8
%14 = call i32 @strlen(i8* %13)
%15 = icmp sge i32 %12, %14
br i1 %15, label %16, label %27
16: ; preds = %4
%17 = load i8*, i8** %5
%18 = load i32, i32* %7
%19 = load i32, i32* %7
%20 = load i32, i32* %6
%21 = sub nsw i32 %19, %20
%22 = add nsw i32 %21, 1
%23 = load i8*, i8** %8
%24 = call i32 @strlen(i8* %23)
%25 = sub nsw i32 %22, %24
%26 = call i32 @shiftLeft(i8* %17, i32 %18, i32 %25)
br label %38
27: ; preds = %4
%28 = load i8*, i8** %5
%29 = load i32, i32* %7
%30 = load i8*, i8** %8
%31 = call i32 @strlen(i8* %30)
%32 = load i32, i32* %7
%33 = load i32, i32* %6
%34 = sub nsw i32 %32, %33
%35 = add nsw i32 %34, 1
%36 = sub nsw i32 %31, %35
%37 = call i32 @shiftRight(i8* %28, i32 %29, i32 %36)
br label %38
38: ; preds = %27, %16
%39 = load i8*, i8** %8
%40 = load i8*, i8** %5
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8*, i8** %8
%45 = call i32 @strlen(i8* %44)
%46 = call i32 @strncpy(i8* %39, i8* %43, i32 %45)
ret void
}

LLVM IR (-O2):
define void @replacestr(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = sub nsw i32 %2, %1
%6 = add nsw i32 %5, 1
%7 = tail call i32 @strlen(i8* %3)
%8 = icmp slt i32 %6, %7
%9 = tail call i32 @strlen(i8* %3)
br i1 %8, label %13, label %10
10: ; preds = %4
%11 = sub nsw i32 %6, %9
%12 = tail call i32 @shiftLeft(i8* %0, i32 %2, i32 %11)
br label %16
13: ; preds = %4
%14 = sub nsw i32 %9, %6
%15 = tail call i32 @shiftRight(i8* %0, i32 %2, i32 %14)
br label %16
16: ; preds = %13, %10
%17 = sext i32 %1 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = tail call i32 @strlen(i8* %3)
%20 = tail call i32 @strncpy(i8* %3, i8* %18, i32 %19)
ret void
}