#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(void **, void **, size_t);
void **xrealloc(void **, size_t);
void linsert(void *p, size_t *len, size_t idx, void *v) {
  void ***pl, **l;
  pl = p;
  *pl = xrealloc(*pl, (*len + 1) * sizeof(void *));
  l = *pl;
  memmove(&l[idx + 1], &l[idx], (*len - idx) * sizeof(void *));
  l[idx] = v;
  (*len)++;
}


x86 assembly (clang, -O0):
<linsert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
add    $0x1,%rsi
shl    $0x3,%rsi
call   1030 <xrealloc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rax
add    $0x1,%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
sub    -0x18(%rbp),%rdx
shl    $0x3,%rdx
call   1040 <memmove@plt>
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linsert>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r12
mov    (%rdi),%rdi
mov    (%rsi),%rax
lea    0x8(,%rax,8),%rsi
call   1030 <xrealloc@plt>
mov    %rax,%rbx
mov    %rax,(%r12)
lea    (%rax,%r13,8),%rdi
add    $0x8,%rdi
lea    (%rax,%r13,8),%rsi
mov    (%r15),%rdx
sub    %r13,%rdx
shl    $0x3,%rdx
call   1040 <memmove@plt>
mov    %r14,(%rbx,%r13,8)
addq   $0x1,(%r15)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @linsert(i8* %0, i64* %1, i64 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8***
%10 = alloca i8**
store i8* %0, i8** %5
store i64* %1, i64** %6
store i64 %2, i64* %7
store i8* %3, i8** %8
%11 = load i8*, i8** %5
%12 = bitcast i8* %11 to i8***
store i8*** %12, i8**** %9
%13 = load i8***, i8**** %9
%14 = load i8**, i8*** %13
%15 = load i64*, i64** %6
%16 = load i64, i64* %15
%17 = add i64 %16, 1
%18 = mul i64 %17, 8
%19 = call i8** @xrealloc(i8** %14, i64 %18)
%20 = load i8***, i8**** %9
store i8** %19, i8*** %20
%21 = load i8***, i8**** %9
%22 = load i8**, i8*** %21
store i8** %22, i8*** %10
%23 = load i8**, i8*** %10
%24 = load i64, i64* %7
%25 = add i64 %24, 1
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8**, i8*** %10
%28 = load i64, i64* %7
%29 = getelementptr inbounds i8*, i8** %27, i64 %28
%30 = load i64*, i64** %6
%31 = load i64, i64* %30
%32 = load i64, i64* %7
%33 = sub i64 %31, %32
%34 = mul i64 %33, 8
%35 = call i32 @memmove(i8** %26, i8** %29, i64 %34)
%36 = load i8*, i8** %8
%37 = load i8**, i8*** %10
%38 = load i64, i64* %7
%39 = getelementptr inbounds i8*, i8** %37, i64 %38
store i8* %36, i8** %39
%40 = load i64*, i64** %6
%41 = load i64, i64* %40
%42 = add i64 %41, 1
store i64 %42, i64* %40
ret void
}

LLVM IR (-O2):
define void @linsert(i8* nocapture %0, i64* nocapture %1, i64 %2, i8* %3) {
%5 = bitcast i8* %0 to i8***
%6 = load i8**, i8*** %5
%7 = load i64, i64* %1
%8 = shl i64 %7, 3
%9 = add i64 %8, 8
%10 = tail call i8** @xrealloc(i8** %6, i64 %9)
store i8** %10, i8*** %5
%11 = add i64 %2, 1
%12 = getelementptr inbounds i8*, i8** %10, i64 %11
%13 = getelementptr inbounds i8*, i8** %10, i64 %2
%14 = load i64, i64* %1
%15 = sub i64 %14, %2
%16 = shl i64 %15, 3
%17 = tail call i32 @memmove(i8** %12, i8** %13, i64 %16)
store i8* %3, i8** %13
%18 = load i64, i64* %1
%19 = add i64 %18, 1
store i64 %19, i64* %1
ret void
}