#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*/ memmove(char *, char *, int);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *sInsert(char *d, const char *s, int p, int n) {
  if (p > strlen(d))
    return d;
  memmove(d + p + strlen(s), d + p, strlen(d) - p + 1);
  strncpy(d + p, s, strlen(s));
  return d;
}


x86 assembly (clang, -O0):
<sInsert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jle    116f <sInsert+0x3f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11fb <sInsert+0xcb>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
sub    -0x1c(%rbp),%edx
add    $0x1,%edx
call   1050 <memmove@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sInsert>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
cmp    %ebp,%eax
jl     118a <sInsert+0x5a>
movslq %ebp,%r15
add    %rbx,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
movslq %eax,%r12
add    %r15,%r12
mov    %rbx,%rdi
call   1040 <strlen@plt>
sub    %ebp,%eax
lea    0x1(%rax),%edx
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <memmove@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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