#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*/ sprintf(char *, char *, char *, char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strsub(char *, char *, int, int);
void InsertString(char *ret, char *data, int a, int b) {
  char begin[4096], end[4096];
  {
    strsub(begin, ret, 1, a - 1);
    strsub(end, ret, b, (int)strlen(ret));
    sprintf(ret, "%s%s%s", begin, data, end);
  }
}


x86 assembly (clang, -O0):
<InsertString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2040,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%edx
call   1040 <strsub@plt>
lea    -0x2020(%rbp),%rax
mov    %rax,-0x2038(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x2030(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x2024(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x2038(%rbp),%rdi
mov    -0x2030(%rbp),%rsi
mov    -0x2024(%rbp),%edx
mov    %eax,%ecx
call   1040 <strsub@plt>
mov    -0x8(%rbp),%rdi
lea    -0x1020(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x2020(%rbp),%r8
lea    0xe39(%rip),%rsi
call   1050 <sprintf@plt>
add    $0x2040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<InsertString>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2000,%rsp
mov    %ecx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    -0x1(%rdx),%ecx
lea    0x1000(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <strsub@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rsp,%r12
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %eax,%ecx
call   1040 <strsub@plt>
lea    0xe7d(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %r12,%r8
call   1050 <sprintf@plt>
add    $0x2000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%s%s%s\00"
define void @InsertString(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [4096 x i8]
%10 = alloca [4096 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%12 = load i8*, i8** %5
%13 = load i32, i32* %7
%14 = sub nsw i32 %13, 1
%15 = call i32 @strsub(i8* %11, i8* %12, i32 1, i32 %14)
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%17 = load i8*, i8** %5
%18 = load i32, i32* %8
%19 = load i8*, i8** %5
%20 = call i64 @strlen(i8* %19)
%21 = trunc i64 %20 to i32
%22 = call i32 @strsub(i8* %16, i8* %17, i32 %18, i32 %21)
%23 = load i8*, i8** %5
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%25 = load i8*, i8** %6
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%27 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %24, i8* %25, i8* %26)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%s%s%s\00"
define void @InsertString(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca [4096 x i8]
%6 = alloca [4096 x i8]
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%9 = add nsw i32 %2, -1
%10 = call i32 @strsub(i8* %7, i8* %0, i32 1, i32 %9)
%11 = call i64 @strlen(i8* dereferenceable(1) %0)
%12 = trunc i64 %11 to i32
%13 = call i32 @strsub(i8* %8, i8* %0, i32 %3, i32 %12)
%14 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %1, i8* %8)
ret void
}