#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*/ free(char *);
int len(char *);
char *malloc(int);
char *slice(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
char *replaceBetween(char *s, int start, int end, char *what) {
  char *buffer = malloc(len(s) + len(what));
  *(buffer) = '\0';
  char *part = slice(s, 0, start - 1, 0);
  strcat(buffer, part);
  strcat(buffer, what);
  char *part2 = slice(s, end, len(s) - 1, 0);
  strcat(buffer, part2);
  free(part);
  free(part2);
  return buffer;
}


x86 assembly (clang, -O0):
<replaceBetween>:
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    -0x8(%rbp),%rdi
call   1030 <len@plt>
mov    %eax,-0x44(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <len@plt>
mov    -0x44(%rbp),%edi
add    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
xor    %ecx,%ecx
mov    %ecx,%esi
call   1050 <slice@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <len@plt>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    %eax,%edx
sub    $0x1,%edx
xor    %ecx,%ecx
call   1050 <slice@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replaceBetween>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r13
call   1030 <len@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <len@plt>
add    %eax,%ebx
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
add    $0xffffffff,%ebp
mov    %r13,%rdi
xor    %esi,%esi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1050 <slice@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %rax,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
mov    %r13,%rdi
call   1030 <len@plt>
lea    -0x1(%rax),%edx
mov    %r13,%rdi
mov    %r14d,%esi
xor    %ecx,%ecx
call   1050 <slice@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   1070 <strcat@plt>
mov    %r12,%rdi
call   1040 <free@plt>
mov    %rbp,%rdi
call   1040 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @replaceBetween(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%12 = load i8*, i8** %5
%13 = call i32 @len(i8* %12)
%14 = load i8*, i8** %8
%15 = call i32 @len(i8* %14)
%16 = add nsw i32 %13, %15
%17 = call i8* @malloc(i32 %16)
store i8* %17, i8** %9
%18 = load i8*, i8** %9
store i8 0, i8* %18
%19 = load i8*, i8** %5
%20 = load i32, i32* %6
%21 = sub nsw i32 %20, 1
%22 = call i8* @slice(i8* %19, i32 0, i32 %21, i32 0)
store i8* %22, i8** %10
%23 = load i8*, i8** %9
%24 = load i8*, i8** %10
%25 = call i32 @strcat(i8* %23, i8* %24)
%26 = load i8*, i8** %9
%27 = load i8*, i8** %8
%28 = call i32 @strcat(i8* %26, i8* %27)
%29 = load i8*, i8** %5
%30 = load i32, i32* %7
%31 = load i8*, i8** %5
%32 = call i32 @len(i8* %31)
%33 = sub nsw i32 %32, 1
%34 = call i8* @slice(i8* %29, i32 %30, i32 %33, i32 0)
store i8* %34, i8** %11
%35 = load i8*, i8** %9
%36 = load i8*, i8** %11
%37 = call i32 @strcat(i8* %35, i8* %36)
%38 = load i8*, i8** %10
%39 = call i32 @free(i8* %38)
%40 = load i8*, i8** %11
%41 = call i32 @free(i8* %40)
%42 = load i8*, i8** %9
ret i8* %42
}

LLVM IR (-O2):
define i8* @replaceBetween(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = tail call i32 @len(i8* %0)
%6 = tail call i32 @len(i8* %3)
%7 = add nsw i32 %6, %5
%8 = tail call i8* @malloc(i32 %7)
store i8 0, i8* %8
%9 = add nsw i32 %1, -1
%10 = tail call i8* @slice(i8* %0, i32 0, i32 %9, i32 0)
%11 = tail call i32 @strcat(i8* %8, i8* %10)
%12 = tail call i32 @strcat(i8* %8, i8* %3)
%13 = tail call i32 @len(i8* %0)
%14 = add nsw i32 %13, -1
%15 = tail call i8* @slice(i8* %0, i32 %2, i32 %14, i32 0)
%16 = tail call i32 @strcat(i8* %8, i8* %15)
%17 = tail call i32 @free(i8* %10)
%18 = tail call i32 @free(i8* %15)
ret i8* %8
}