#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 *fh_str_concat(char *, char *);
char *fh_str_slice(char *, int, int);
int /*<<< orphan*/ free(char *);
int strlen(char *);
char *splice(char *str, char *rep, int start, int end) {
  char *front, *back, *tmp, *new;
  front = fh_str_slice(str, 0, start);
  back = fh_str_slice(str, end, strlen(str));
  tmp = fh_str_concat(front, rep);
  new = fh_str_concat(tmp, back);
  free(front);
  free(back);
  free(tmp);
  return new;
}


x86 assembly (clang, -O0):
<splice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1050 <fh_str_slice@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    %eax,%edx
call   1050 <fh_str_slice@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <fh_str_concat@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <fh_str_concat@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<splice>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %esi,%esi
call   1050 <fh_str_slice@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %eax,%edx
call   1050 <fh_str_slice@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <fh_str_concat@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1060 <fh_str_concat@plt>
mov    %rax,%r14
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @splice(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load i8*, i8** %5
%14 = load i32, i32* %7
%15 = call i8* @fh_str_slice(i8* %13, i32 0, i32 %14)
store i8* %15, i8** %9
%16 = load i8*, i8** %5
%17 = load i32, i32* %8
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
%20 = call i8* @fh_str_slice(i8* %16, i32 %17, i32 %19)
store i8* %20, i8** %10
%21 = load i8*, i8** %9
%22 = load i8*, i8** %6
%23 = call i8* @fh_str_concat(i8* %21, i8* %22)
store i8* %23, i8** %11
%24 = load i8*, i8** %11
%25 = load i8*, i8** %10
%26 = call i8* @fh_str_concat(i8* %24, i8* %25)
store i8* %26, i8** %12
%27 = load i8*, i8** %9
%28 = call i32 @free(i8* %27)
%29 = load i8*, i8** %10
%30 = call i32 @free(i8* %29)
%31 = load i8*, i8** %11
%32 = call i32 @free(i8* %31)
%33 = load i8*, i8** %12
ret i8* %33
}

LLVM IR (-O2):
define i8* @splice(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = tail call i8* @fh_str_slice(i8* %0, i32 0, i32 %2)
%6 = tail call i32 @strlen(i8* %0)
%7 = tail call i8* @fh_str_slice(i8* %0, i32 %3, i32 %6)
%8 = tail call i8* @fh_str_concat(i8* %5, i8* %1)
%9 = tail call i8* @fh_str_concat(i8* %8, i8* %7)
%10 = tail call i32 @free(i8* %5)
%11 = tail call i32 @free(i8* %7)
%12 = tail call i32 @free(i8* %8)
ret i8* %9
}