#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*/ ENOMEM;
scalar_t__ aeron_reallocf(void **, size_t);
int /*<<< orphan*/ aeron_set_err(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, size_t);
int aeron_array_remove(uint8_t **array, size_t element_size, size_t index,
                       size_t old_length) {
  for (size_t i = index; i < (old_length - 1); i++) {
    memcpy(*array + (i * element_size), *array + ((i + 1) * element_size),
           element_size);
  }
  if (aeron_reallocf((void **)array, (old_length - 1) * element_size) < 0) {
    aeron_set_err(ENOMEM, "%s", "could not array remove realloc");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<aeron_array_remove>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    11b1 <aeron_array_remove+0x81>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rax
imul   -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x30(%rbp),%rax
add    $0x1,%rax
imul   -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x18(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1150 <aeron_array_remove+0x20>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
sub    $0x1,%rsi
imul   -0x18(%rbp),%rsi
call   1040 <aeron_reallocf@plt>
cmp    $0x0,%rax
jge    11f9 <aeron_array_remove+0xc9>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
lea    0xe1b(%rip),%rdx
call   1030 <aeron_set_err@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1200 <aeron_array_remove+0xd0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aeron_array_remove>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r15
lea    -0x1(%rcx),%rax
mov    %rax,(%rsp)
cmp    %rdx,%rax
jbe    119e <aeron_array_remove+0x6e>
mov    %rdx,%rbx
mov    %rdx,%r13
not    %r13
add    %rcx,%r13
lea    0x1(%rdx),%rbp
imul   %r12,%rbp
shl    $0x2,%rbp
lea    0x0(,%r12,4),%r14
imul   %r12,%rbx
shl    $0x2,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    (%r15),%rsi
lea    (%rsi,%rbx,1),%rdi
add    %rbp,%rsi
mov    %r12,%rdx
call   1050 <memcpy@plt>
add    %r14,%rbp
add    %r14,%rbx
add    $0xffffffffffffffff,%r13
jne    1180 <aeron_array_remove+0x50>
mov    (%rsp),%rsi
imul   %r12,%rsi
mov    %r15,%rdi
call   1040 <aeron_reallocf@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jns    11d9 <aeron_array_remove+0xa9>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
lea    0xe34(%rip),%rdx
call   1030 <aeron_set_err@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ENOMEM = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [31 x i8] c"could not array remove realloc\00"
define i32 @aeron_array_remove(i32** %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32**
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i32** %0, i32*** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i64 %3, i64* %9
%11 = load i64, i64* %8
store i64 %11, i64* %10
br label %12
12: ; preds = %33, %4
%13 = load i64, i64* %10
%14 = load i64, i64* %9
%15 = sub i64 %14, 1
%16 = icmp ult i64 %13, %15
br i1 %16, label %17, label %36
17: ; preds = %12
%18 = load i32**, i32*** %6
%19 = load i32*, i32** %18
%20 = load i64, i64* %10
%21 = load i64, i64* %7
%22 = mul i64 %20, %21
%23 = getelementptr inbounds i32, i32* %19, i64 %22
%24 = load i32**, i32*** %6
%25 = load i32*, i32** %24
%26 = load i64, i64* %10
%27 = add i64 %26, 1
%28 = load i64, i64* %7
%29 = mul i64 %27, %28
%30 = getelementptr inbounds i32, i32* %25, i64 %29
%31 = load i64, i64* %7
%32 = call i32 @memcpy(i32* %23, i32* %30, i64 %31)
br label %33
33: ; preds = %17
%34 = load i64, i64* %10
%35 = add i64 %34, 1
store i64 %35, i64* %10
br label %12
36: ; preds = %12
%37 = load i32**, i32*** %6
%38 = bitcast i32** %37 to i8**
%39 = load i64, i64* %9
%40 = sub i64 %39, 1
%41 = load i64, i64* %7
%42 = mul i64 %40, %41
%43 = call i64 @aeron_reallocf(i8** %38, i64 %42)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %36
%46 = load i32, i32* @ENOMEM
%47 = call i32 @aeron_set_err(i32 %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %5
br label %49
48: ; preds = %36
store i32 0, i32* %5
br label %49
49: ; preds = %48, %45
%50 = load i32, i32* %5
ret i32 %50
}

LLVM IR (-O2):
@ENOMEM = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [31 x i8] c"could not array remove realloc\00"
define i32 @aeron_array_remove(i32** %0, i64 %1, i64 %2, i64 %3) {
%5 = add i64 %3, -1
%6 = icmp ugt i64 %5, %2
br i1 %6, label %12, label %7
7: ; preds = %12, %4
%8 = bitcast i32** %0 to i8**
%9 = mul i64 %5, %1
%10 = tail call i64 @aeron_reallocf(i8** %8, i64 %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %22, label %25
12: ; preds = %4, %12
%13 = phi i64 [ %17, %12 ], [ %2, %4 ]
%14 = load i32*, i32** %0
%15 = mul i64 %13, %1
%16 = getelementptr inbounds i32, i32* %14, i64 %15
%17 = add nuw i64 %13, 1
%18 = mul i64 %17, %1
%19 = getelementptr inbounds i32, i32* %14, i64 %18
%20 = tail call i32 @memcpy(i32* %16, i32* %19, i64 %1)
%21 = icmp eq i64 %17, %5
br i1 %21, label %7, label %12
22: ; preds = %7
%23 = load i32, i32* @ENOMEM
%24 = tail call i32 @aeron_set_err(i32 %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %7, %22
%26 = phi i32 [ -1, %22 ], [ 0, %7 ]
ret i32 %26
}