#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*/ err(int, char *);
char **realloc(char **, int);
char *strdup(char const *);
void add_to_list(char ***list, int *count, const char *item) {
  (*count)++;
  *list = realloc(*list, sizeof **list * *count);
  if (!*list)
    err(1, "realloc");
  (*list)[*count - 1] = strdup(item);
  if (!(*list)[*count - 1])
    err(1, "strdup");
}


x86 assembly (clang, -O0):
<add_to_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1191 <add_to_list+0x61>
mov    $0x1,%edi
lea    0xe74(%rip),%rsi
call   1030 <err@plt>
mov    -0x18(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11e3 <add_to_list+0xb3>
mov    $0x1,%edi
lea    0xe2a(%rip),%rsi
call   1030 <err@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_to_list>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
mov    (%rsi),%eax
lea    0x1(%rax),%ecx
mov    %ecx,(%rsi)
mov    (%rdi),%rdi
lea    0x8(,%rax,8),%esi
call   1040 <realloc@plt>
mov    %rax,%rbx
mov    %rax,(%r12)
test   %rax,%rax
jne    1178 <add_to_list+0x48>
lea    0xe96(%rip),%rsi
mov    $0x1,%edi
call   1030 <err@plt>
mov    (%r12),%rbx
mov    %r15,%rdi
call   1050 <strdup@plt>
movslq (%r14),%rcx
mov    %rax,-0x8(%rbx,%rcx,8)
mov    (%r12),%rax
cmpq   $0x0,-0x8(%rax,%rcx,8)
je     11a0 <add_to_list+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe61(%rip),%rsi
mov    $0x1,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <err@plt>

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

LLVM IR (-O2):
@.str = [8 x i8] c"realloc\00"
@.str.1 = [7 x i8] c"strdup\00"
define void @add_to_list(i8*** nocapture %0, i32* nocapture %1, i8* nocapture %2) {
%4 = load i32, i32* %1
%5 = add nsw i32 %4, 1
store i32 %5, i32* %1
%6 = load i8**, i8*** %0
%7 = shl i32 %5, 3
%8 = tail call i8** @realloc(i8** %6, i32 %7)
store i8** %8, i8*** %0
%9 = icmp eq i8** %8, null
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%12 = load i8**, i8*** %0
br label %13
13: ; preds = %10, %3
%14 = phi i8** [ %12, %10 ], [ %8, %3 ]
%15 = tail call i8* @strdup(i8* %2)
%16 = load i32, i32* %1
%17 = add nsw i32 %16, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %14, i64 %18
store i8* %15, i8** %19
%20 = load i8**, i8*** %0
%21 = getelementptr inbounds i8*, i8** %20, i64 %18
%22 = load i8*, i8** %21
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %26
24: ; preds = %13
%25 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %13
ret void
}