#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 *);
char **malloc_or_die(int);
char **realloc(char **, int);
char *strdup(char const *);
char **tracecmd_add_list(char **list, const char *name, int len) {
  if (!list)
    list = malloc_or_die(sizeof(*list) * 2);
  else {
    list = realloc(list, sizeof(*list) * (len + 2));
    if (!list)
      die("Can not allocate list");
  }
  list[len] = strdup(name);
  if (!list[len])
    die("Can not allocate list");
  list[len + 1] = NULL;
  return list;
}


x86 assembly (clang, -O0):
<tracecmd_add_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1171 <tracecmd_add_list+0x31>
mov    $0x10,%edi
call   1030 <malloc_or_die@plt>
mov    %rax,-0x8(%rbp)
jmp    11a8 <tracecmd_add_list+0x68>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a3 <tracecmd_add_list+0x63>
lea    0xe62(%rip),%rdi
call   1050 <die@plt>
jmp    11a8 <tracecmd_add_list+0x68>
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11df <tracecmd_add_list+0x9f>
lea    0xe26(%rip),%rdi
call   1050 <die@plt>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tracecmd_add_list>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%r15d
mov    %rsi,%r14
test   %rdi,%rdi
je     1175 <tracecmd_add_list+0x35>
lea    0x10(,%r15,8),%esi
call   1040 <realloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1182 <tracecmd_add_list+0x42>
lea    0xe94(%rip),%rdi
call   1050 <die@plt>
xor    %ebx,%ebx
jmp    1182 <tracecmd_add_list+0x42>
mov    $0x10,%edi
call   1030 <malloc_or_die@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1060 <strdup@plt>
movslq %r15d,%r14
mov    %rax,(%rbx,%r14,8)
test   %rax,%rax
jne    11a2 <tracecmd_add_list+0x62>
lea    0xe63(%rip),%rdi
call   1050 <die@plt>
movq   $0x0,0x8(%rbx,%r14,8)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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