#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);
int /*<<< orphan*/ sprintf(char *, char *, long);
char *strdup(char *);
void addList(int *ix, char ***list, char *fmt, long x) {
  char buf[40];
  *list = realloc(*list, (*ix + 1) * sizeof(char *));
  if (x)
    sprintf(buf, fmt, x);
  (*list)[(*ix)++] = strdup(x ? buf : fmt);
}


x86 assembly (clang, -O0):
<addList>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1030 <realloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     118b <addList+0x5b>
lea    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <sprintf@plt>
cmpq   $0x0,-0x20(%rbp)
je     11a3 <addList+0x73>
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
jmp    11ab <addList+0x7b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rsi
mov    (%rsi),%ecx
mov    %ecx,%edi
add    $0x1,%edi
mov    %edi,(%rsi)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addList>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r13
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    (%rsi),%rdi
mov    (%r15),%eax
lea    0x8(,%rax,8),%esi
call   1030 <realloc@plt>
mov    %rax,(%rbx)
test   %r13,%r13
je     117d <addList+0x4d>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1040 <sprintf@plt>
mov    (%rbx),%r12
mov    %rbp,%r14
jmp    1180 <addList+0x50>
mov    %rax,%r12
mov    %r14,%rdi
call   1050 <strdup@plt>
movslq (%r15),%rcx
lea    0x1(%rcx),%edx
mov    %edx,(%r15)
mov    %rax,(%r12,%rcx,8)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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