#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 */
char **realloc(char **, int);
char *strdup(char *);
int addToList(char ***list, char *entry, int num) {
  int x;
  char **l = *list;
  x = num + 1;
  l = realloc(l, (x + 1) * sizeof(char *));
  l[x - 1] = strdup(entry);
  l[x] = NULL;
  *list = l;
  return x;
}


x86 assembly (clang, -O0):
<addToList>:
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),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1030 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addToList>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rdi
lea    0x1(%rbx),%r12d
lea    0x10(,%rbx,8),%esi
call   1030 <realloc@plt>
mov    %rax,%rbp
mov    %r14,%rdi
call   1040 <strdup@plt>
movslq %ebx,%rcx
mov    %rax,0x0(%rbp,%rcx,8)
movq   $0x0,0x8(%rbp,%rcx,8)
mov    %rbp,(%r15)
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @addToList(i8*** nocapture %0, i8* nocapture %1, i32 %2) {
%4 = load i8**, i8*** %0
%5 = add nsw i32 %2, 1
%6 = shl i32 %2, 3
%7 = add i32 %6, 16
%8 = tail call i8** @realloc(i8** %4, i32 %7)
%9 = tail call i8* @strdup(i8* %1)
%10 = sext i32 %2 to i64
%11 = getelementptr inbounds i8*, i8** %8, i64 %10
store i8* %9, i8** %11
%12 = sext i32 %5 to i64
%13 = getelementptr inbounds i8*, i8** %8, i64 %12
store i8* null, i8** %13
store i8** %8, i8*** %0
ret i32 %5
}