#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*/ decmem(size_t);
int /*<<< orphan*/ err(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ incmem(size_t);
int intslen(int *);
int *malloc(size_t);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, size_t);
void addint(int **intsptr, int i) {
  int *oldints = *intsptr, len = intslen(oldints);
  const int *p;
  int *q, o, *newints;
  do {
    size_t BYTES = (len + 2) * sizeof *(newints);
    (newints) = malloc(BYTES);
    if (!(newints)) {
      err("out of memory");
      exit(1);
    }
    memset((newints), 0, BYTES);
    incmem(BYTES);
  } while (0);
  q = newints;
  for (p = oldints; (o = *p); p++)
    *q++ = o;
  *q++ = i;
  do {
    size_t BYTES = (len + 1) * sizeof *(oldints);
    decmem(BYTES);
    free(oldints);
  } while (0);
  *intsptr = newints;
}


x86 assembly (clang, -O0):
<addint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <intslen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x2,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11e4 <addint+0x64>
lea    0xe2b(%rip),%rdi
call   1060 <err@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x48(%rbp),%rdi
call   1080 <incmem@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
je     1243 <addint+0xc3>
mov    -0x34(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x30(%rbp)
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
jmp    120c <addint+0x8c>
mov    -0xc(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x30(%rbp)
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
call   1050 <decmem@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addint>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
mov    (%rdi),%r12
mov    %r12,%rdi
call   10a0 <intslen@plt>
movslq %eax,%r13
lea    0x8(,%r13,4),%rbx
mov    %rbx,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     121a <addint+0x9a>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1040 <memset@plt>
mov    %rbx,%rdi
call   1080 <incmem@plt>
mov    (%r12),%eax
mov    %rbp,%rcx
test   %eax,%eax
je     11f0 <addint+0x70>
lea    0x4(%r12),%rdx
mov    %rbp,%rcx
nop
mov    %eax,(%rcx)
add    $0x4,%rcx
mov    (%rdx),%eax
add    $0x4,%rdx
test   %eax,%eax
jne    11e0 <addint+0x60>
mov    %r15d,(%rcx)
lea    0x4(,%r13,4),%rdi
call   1050 <decmem@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbp,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xddf(%rip),%rdi
call   1060 <err@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"out of memory\00"
define void @addint(i32** %0, i32 %1) {
%3 = alloca i32**
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i64
store i32** %0, i32*** %3
store i32 %1, i32* %4
%13 = load i32**, i32*** %3
%14 = load i32*, i32** %13
store i32* %14, i32** %5
%15 = load i32*, i32** %5
%16 = call i32 @intslen(i32* %15)
store i32 %16, i32* %6
br label %17
17: ; preds = %2
%18 = load i32, i32* %6
%19 = add nsw i32 %18, 2
%20 = sext i32 %19 to i64
%21 = mul i64 %20, 4
store i64 %21, i64* %11
%22 = load i64, i64* %11
%23 = call i32* @malloc(i64 %22)
store i32* %23, i32** %10
%24 = load i32*, i32** %10
%25 = icmp ne i32* %24, null
br i1 %25, label %29, label %26
26: ; preds = %17
%27 = call i32 @err(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %17
%30 = load i32*, i32** %10
%31 = load i64, i64* %11
%32 = call i32 @memset(i32* %30, i32 0, i64 %31)
%33 = load i64, i64* %11
%34 = call i32 @incmem(i64 %33)
br label %35
35: ; preds = %29
%36 = load i32*, i32** %10
store i32* %36, i32** %8
%37 = load i32*, i32** %5
store i32* %37, i32** %7
br label %38
38: ; preds = %46, %35
%39 = load i32*, i32** %7
%40 = load i32, i32* %39
store i32 %40, i32* %9
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %49
42: ; preds = %38
%43 = load i32, i32* %9
%44 = load i32*, i32** %8
%45 = getelementptr inbounds i32, i32* %44, i32 1
store i32* %45, i32** %8
store i32 %43, i32* %44
br label %46
46: ; preds = %42
%47 = load i32*, i32** %7
%48 = getelementptr inbounds i32, i32* %47, i32 1
store i32* %48, i32** %7
br label %38
49: ; preds = %38
%50 = load i32, i32* %4
%51 = load i32*, i32** %8
%52 = getelementptr inbounds i32, i32* %51, i32 1
store i32* %52, i32** %8
store i32 %50, i32* %51
br label %53
53: ; preds = %49
%54 = load i32, i32* %6
%55 = add nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = mul i64 %56, 4
store i64 %57, i64* %12
%58 = load i64, i64* %12
%59 = call i32 @decmem(i64 %58)
%60 = load i32*, i32** %5
%61 = call i32 @free(i32* %60)
br label %62
62: ; preds = %53
%63 = load i32*, i32** %10
%64 = load i32**, i32*** %3
store i32* %63, i32** %64
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"out of memory\00"
define void @addint(i32** nocapture %0, i32 %1) {
%3 = load i32*, i32** %0
%4 = tail call i32 @intslen(i32* %3)
%5 = add nsw i32 %4, 2
%6 = sext i32 %5 to i64
%7 = shl nsw i64 %6, 2
%8 = tail call i32* @malloc(i64 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = tail call i32 @err(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = tail call i32 @memset(i32* %8, i32 0, i64 %7)
%15 = tail call i32 @incmem(i64 %7)
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 0
br i1 %17, label %26, label %18
18: ; preds = %13, %18
%19 = phi i32 [ %24, %18 ], [ %16, %13 ]
%20 = phi i32* [ %23, %18 ], [ %3, %13 ]
%21 = phi i32* [ %22, %18 ], [ %8, %13 ]
%22 = getelementptr inbounds i32, i32* %21, i64 1
store i32 %19, i32* %21
%23 = getelementptr inbounds i32, i32* %20, i64 1
%24 = load i32, i32* %23
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %18
26: ; preds = %18, %13
%27 = phi i32* [ %8, %13 ], [ %22, %18 ]
store i32 %1, i32* %27
%28 = add nsw i32 %4, 1
%29 = sext i32 %28 to i64
%30 = shl nsw i64 %29, 2
%31 = tail call i32 @decmem(i64 %30)
%32 = tail call i32 @free(i32* %3)
store i32* %8, i32** %0
ret void
}