#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 int64_t;

/* Variables and functions */
int *realloc(int *, unsigned int);
void arr_add(int64_t **arr, unsigned int *len, int64_t idx) {
  (*arr) = realloc(*arr, (*len + 2) * sizeof(int64_t));
  (*arr)[*len + 0] = idx;
  (*arr)[*len + 1] = -1;
  (*len)++;
}


x86 assembly (clang, -O0):
<arr_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x2,%eax
mov    %eax,%eax
shl    $0x2,%rax
mov    %eax,%esi
call   1030 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
add    $0x0,%ecx
mov    %ecx,%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arr_add>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    (%rdi),%rdi
mov    (%rsi),%eax
lea    0x8(,%rax,4),%esi
call   1030 <realloc@plt>
mov    %rax,0x0(%rbp)
mov    (%rbx),%ecx
mov    %r14d,(%rax,%rcx,4)
mov    (%rbx),%ecx
add    $0x1,%ecx
movl   $0xffffffff,(%rax,%rcx,4)
addl   $0x1,(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @arr_add(i32** %0, i32* %1, i32 %2) {
%4 = alloca i32**
%5 = alloca i32*
%6 = alloca i32
store i32** %0, i32*** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%7 = load i32**, i32*** %4
%8 = load i32*, i32** %7
%9 = load i32*, i32** %5
%10 = load i32, i32* %9
%11 = add i32 %10, 2
%12 = zext i32 %11 to i64
%13 = mul i64 %12, 4
%14 = trunc i64 %13 to i32
%15 = call i32* @realloc(i32* %8, i32 %14)
%16 = load i32**, i32*** %4
store i32* %15, i32** %16
%17 = load i32, i32* %6
%18 = load i32**, i32*** %4
%19 = load i32*, i32** %18
%20 = load i32*, i32** %5
%21 = load i32, i32* %20
%22 = add i32 %21, 0
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %19, i64 %23
store i32 %17, i32* %24
%25 = load i32**, i32*** %4
%26 = load i32*, i32** %25
%27 = load i32*, i32** %5
%28 = load i32, i32* %27
%29 = add i32 %28, 1
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %26, i64 %30
store i32 -1, i32* %31
%32 = load i32*, i32** %5
%33 = load i32, i32* %32
%34 = add i32 %33, 1
store i32 %34, i32* %32
ret void
}

LLVM IR (-O2):
define void @arr_add(i32** nocapture %0, i32* nocapture %1, i32 %2) {
%4 = load i32*, i32** %0
%5 = load i32, i32* %1
%6 = shl i32 %5, 2
%7 = add i32 %6, 8
%8 = tail call i32* @realloc(i32* %4, i32 %7)
store i32* %8, i32** %0
%9 = load i32, i32* %1
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds i32, i32* %8, i64 %10
store i32 %2, i32* %11
%12 = load i32, i32* %1
%13 = add i32 %12, 1
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %8, i64 %14
store i32 -1, i32* %15
%16 = load i32, i32* %1
%17 = add i32 %16, 1
store i32 %17, i32* %1
ret void
}