#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*/ die(char *);
int *malloc_or_die(int);
int *realloc(int *, int);
int *tracecmd_add_id(int *list, int id, int len) {
  if (!list)
    list = malloc_or_die(sizeof(*list) * 2);
  else {
    list = realloc(list, sizeof(*list) * (len + 2));
    if (!list)
      die("Can ont allocate list");
  }
  list[len++] = id;
  list[len] = -1;
  return list;
}


x86 assembly (clang, -O0):
<tracecmd_add_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1160 <tracecmd_add_id+0x30>
mov    $0x8,%edi
call   1030 <malloc_or_die@plt>
mov    %rax,-0x8(%rbp)
jmp    1197 <tracecmd_add_id+0x67>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x2,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1192 <tracecmd_add_id+0x62>
lea    0xe73(%rip),%rdi
call   1050 <die@plt>
jmp    1197 <tracecmd_add_id+0x67>
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tracecmd_add_id>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%ebp
test   %rdi,%rdi
je     115d <tracecmd_add_id+0x2d>
lea    0x8(,%rbx,4),%esi
call   1040 <realloc@plt>
test   %rax,%rax
jne    1167 <tracecmd_add_id+0x37>
lea    0xeac(%rip),%rdi
call   1050 <die@plt>
xor    %eax,%eax
jmp    1167 <tracecmd_add_id+0x37>
mov    $0x8,%edi
call   1030 <malloc_or_die@plt>
movslq %ebx,%rcx
mov    %ebp,(%rax,%rcx,4)
movl   $0xffffffff,0x4(%rax,%rcx,4)
ff
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Can ont allocate list\00"
define i32* @tracecmd_add_id(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 = icmp ne i32* %7, null
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = call i32* @malloc_or_die(i32 8)
store i32* %10, i32** %4
br label %24
11: ; preds = %3
%12 = load i32*, i32** %4
%13 = load i32, i32* %6
%14 = add nsw i32 %13, 2
%15 = sext i32 %14 to i64
%16 = mul i64 4, %15
%17 = trunc i64 %16 to i32
%18 = call i32* @realloc(i32* %12, i32 %17)
store i32* %18, i32** %4
%19 = load i32*, i32** %4
%20 = icmp ne i32* %19, null
br i1 %20, label %23, label %21
21: ; preds = %11
%22 = call i32 @die(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %11
br label %24
24: ; preds = %23, %9
%25 = load i32, i32* %5
%26 = load i32*, i32** %4
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds i32, i32* %26, i64 %29
store i32 %25, i32* %30
%31 = load i32*, i32** %4
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
store i32 -1, i32* %34
%35 = load i32*, i32** %4
ret i32* %35
}

LLVM IR (-O2):
@.str = [22 x i8] c"Can ont allocate list\00"
define i32* @tracecmd_add_id(i32* %0, i32 %1, i32 %2) {
%4 = icmp eq i32* %0, null
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32* @malloc_or_die(i32 8)
br label %14
7: ; preds = %3
%8 = shl i32 %2, 2
%9 = add i32 %8, 8
%10 = tail call i32* @realloc(i32* %0, i32 %9)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @die(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %7, %12, %5
%15 = phi i32* [ %10, %7 ], [ null, %12 ], [ %6, %5 ]
%16 = add nsw i32 %2, 1
%17 = sext i32 %2 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
store i32 %1, i32* %18
%19 = sext i32 %16 to i64
%20 = getelementptr inbounds i32, i32* %15, i64 %19
store i32 -1, i32* %20
ret i32* %15
}