#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*/ printf(char *, char *);
int stringlength(char *);
void insert(char *str, char *ch, int pos) {
  int i;
  int n = stringlength(str) - 1;
  for (i = (n - 1); i >= (pos - 1); i--) {
    *(str + (i + 1)) = *(str + i);
  }
  *(str + (pos - 1)) = *(ch + 0);
  printf("str : %s\n", str);
}


x86 assembly (clang, -O0):
<insert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <stringlength@plt>
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jl     1185 <insert+0x65>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    114b <insert+0x2b>
mov    -0x10(%rbp),%rax
mov    (%rax),%dl
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rsi
lea    0xe5a(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insert>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <stringlength@plt>
add    $0xfffffffe,%eax
movslq %ebp,%rdx
lea    -0x1(%rdx),%rsi
cmp    %esi,%eax
jl     1161 <insert+0x41>
cltq
add    $0x1,%rax
cs nopw 0x0(%rax,%rax,1)
nop
movzbl -0x1(%rbx,%rax,1),%ecx
mov    %cl,(%rbx,%rax,1)
add    $0xffffffffffffffff,%rax
cmp    %rdx,%rax
jge    1150 <insert+0x30>
mov    (%r14),%al
mov    %al,(%rbx,%rsi,1)
lea    0xe92(%rip),%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"str : %s\0A\00"
define void @insert(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = call i32 @stringlength(i8* %9)
%11 = sub nsw i32 %10, 1
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = sub nsw i32 %12, 1
store i32 %13, i32* %7
br label %14
14: ; preds = %30, %3
%15 = load i32, i32* %7
%16 = load i32, i32* %6
%17 = sub nsw i32 %16, 1
%18 = icmp sge i32 %15, %17
br i1 %18, label %19, label %33
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = load i8*, i8** %4
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
store i8 %24, i8* %29
br label %30
30: ; preds = %19
%31 = load i32, i32* %7
%32 = add nsw i32 %31, -1
store i32 %32, i32* %7
br label %14
33: ; preds = %14
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i64 0
%36 = load i8, i8* %35
%37 = load i8*, i8** %4
%38 = load i32, i32* %6
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
store i8 %36, i8* %41
%42 = load i8*, i8** %4
%43 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %42)
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"str : %s\0A\00"
define void @insert(i8* %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32 @stringlength(i8* %0)
%5 = add i32 %4, -2
%6 = add nsw i32 %2, -1
%7 = icmp slt i32 %5, %6
br i1 %7, label %19, label %8
8: ; preds = %3
%9 = sext i32 %5 to i64
%10 = sext i32 %2 to i64
br label %11
11: ; preds = %8, %11
%12 = phi i64 [ %9, %8 ], [ %17, %11 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = add nsw i64 %12, 1
%16 = getelementptr inbounds i8, i8* %0, i64 %15
store i8 %14, i8* %16
%17 = add nsw i64 %12, -1
%18 = icmp slt i64 %12, %10
br i1 %18, label %19, label %11
19: ; preds = %11, %3
%20 = load i8, i8* %1
%21 = sext i32 %6 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
store i8 %20, i8* %22
%23 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0)
ret void
}