#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ int32ToBuf(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memmove(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ printf(char *);
int insertInt32(uint8_t **pnt, uint8_t *end, int length, int value) {
  if (*pnt + 4 >= end) {
    printf("Error, running out of buffer space while adding int32 to buffer\n");
    exit(0);
  }
  memmove((*pnt) + 4, *pnt, length);
  int32ToBuf(value, *pnt);
  *pnt += 4;
  return 4;
}


x86 assembly (clang, -O0):
<insertInt32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
add    $0x10,%rax
cmp    -0x10(%rbp),%rax
jb     117e <insertInt32+0x3e>
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
add    $0x10,%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memmove@plt>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
call   1060 <int32ToBuf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x10,%rcx
mov    %rcx,(%rax)
mov    $0x4,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insertInt32>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %rdi,%rbx
mov    (%rdi),%rsi
lea    0x10(%rsi),%rdi
cmp    %rax,%rdi
jae    1176 <insertInt32+0x36>
mov    %ecx,%ebp
call   1040 <memmove@plt>
mov    (%rbx),%rsi
mov    %ebp,%edi
call   1060 <int32ToBuf@plt>
addq   $0x10,(%rbx)
mov    $0x4,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [65 x i8] c"Error, running out of buffer space while adding int32 to buffer\0A\00"
define i32 @insertInt32(i32** %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32** %0, i32*** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load i32**, i32*** %5
%10 = load i32*, i32** %9
%11 = getelementptr inbounds i32, i32* %10, i64 4
%12 = load i32*, i32** %6
%13 = icmp uge i32* %11, %12
br i1 %13, label %14, label %17
14: ; preds = %4
%15 = call i32 @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %4
%18 = load i32**, i32*** %5
%19 = load i32*, i32** %18
%20 = getelementptr inbounds i32, i32* %19, i64 4
%21 = load i32**, i32*** %5
%22 = load i32*, i32** %21
%23 = load i32, i32* %7
%24 = call i32 @memmove(i32* %20, i32* %22, i32 %23)
%25 = load i32, i32* %8
%26 = load i32**, i32*** %5
%27 = load i32*, i32** %26
%28 = call i32 @int32ToBuf(i32 %25, i32* %27)
%29 = load i32**, i32*** %5
%30 = load i32*, i32** %29
%31 = getelementptr inbounds i32, i32* %30, i64 4
store i32* %31, i32** %29
ret i32 4
}

LLVM IR (-O2):
@str = [64 x i8] c"Error, running out of buffer space while adding int32 to buffer\00"
define i32 @insertInt32(i32** nocapture %0, i32* readnone %1, i32 %2, i32 %3) {
%5 = load i32*, i32** %0
%6 = getelementptr inbounds i32, i32* %5, i64 4
%7 = icmp ult i32* %6, %1
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %4
%12 = tail call i32 @memmove(i32* %6, i32* %5, i32 %2)
%13 = load i32*, i32** %0
%14 = tail call i32 @int32ToBuf(i32 %3, i32* %13)
%15 = load i32*, i32** %0
%16 = getelementptr inbounds i32, i32* %15, i64 4
store i32* %16, i32** %0
ret i32 4
}