#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 *);
void str_insert(char *s, char c, int n) {
  int l = strlen(s);
  if (n < 0)
    return;
  memmove(s + n + 1, s + n, l - n + 1);
  s[n] = c;
}


x86 assembly (clang, -O0):
<str_insert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1150 <str_insert+0x30>
jmp    1186 <str_insert+0x66>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x10(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
sub    -0x10(%rbp),%edx
add    $0x1,%edx
call   1040 <memmove@plt>
mov    -0x9(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_insert>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %ebp,%ebp
js     1157 <str_insert+0x37>
mov    %ebp,%r15d
lea    (%rbx,%r15,1),%rsi
lea    (%rbx,%r15,1),%rdi
add    $0x1,%rdi
sub    %ebp,%eax
add    $0x1,%eax
mov    %eax,%edx
call   1040 <memmove@plt>
mov    %r14b,(%rbx,%r15,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @str_insert(i8* %0, i8 signext %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8 %1, i8* %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %7
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
br label %33
13: ; preds = %3
%14 = load i8*, i8** %4
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = load i8*, i8** %4
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i32, i32* %7
%24 = load i32, i32* %6
%25 = sub nsw i32 %23, %24
%26 = add nsw i32 %25, 1
%27 = call i32 @memmove(i8* %18, i8* %22, i32 %26)
%28 = load i8, i8* %5
%29 = load i8*, i8** %4
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 %28, i8* %32
br label %33
33: ; preds = %13, %12
ret void
}

LLVM IR (-O2):
define void @str_insert(i8* %0, i8 signext %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp slt i32 %2, 0
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = zext i32 %2 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = sub nsw i32 1, %2
%11 = add i32 %10, %4
%12 = tail call i32 @memmove(i8* %9, i8* %8, i32 %11)
store i8 %1, i8* %8
br label %13
13: ; preds = %3, %6
ret void
}