#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 *calloc(scalar_t__, int);
int /*<<< orphan*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char const *);
void expand_list(char **buffer, const char *addition, const char *delim) {
  char *newbuf;
  if (*buffer) {
    newbuf = malloc(strlen(*buffer) + strlen(delim) + strlen(addition) + 1);
    strcpy(newbuf, *buffer);
    strcat(newbuf, delim);
  } else
    newbuf = calloc(strlen(addition) + 1, 1);
  strcat(newbuf, addition);
  if (*buffer)
    free(*buffer);
  *buffer = newbuf;
}


x86 assembly (clang, -O0):
<expand_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     11e8 <expand_list+0x88>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcat@plt>
jmp    1206 <expand_list+0xa6>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     122d <expand_list+0xcd>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expand_list>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
mov    (%rdi),%r13
test   %r13,%r13
je     11c5 <expand_list+0x65>
mov    %rdx,%r15
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbp
mov    %r14,%rdi
call   1050 <strlen@plt>
add    %rbx,%rbp
lea    (%rax,%rbp,1),%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
jmp    11de <expand_list+0x7e>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
mov    (%r12),%rdi
test   %rdi,%rdi
je     11f7 <expand_list+0x97>
call   1030 <free@plt>
mov    %rbx,(%r12)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @expand_list(i8** %0, i8* %1, i8* %2) {
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8**, i8*** %4
%9 = load i8*, i8** %8
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %30
11: ; preds = %3
%12 = load i8**, i8*** %4
%13 = load i8*, i8** %12
%14 = call i64 @strlen(i8* %13)
%15 = load i8*, i8** %6
%16 = call i64 @strlen(i8* %15)
%17 = add nsw i64 %14, %16
%18 = load i8*, i8** %5
%19 = call i64 @strlen(i8* %18)
%20 = add nsw i64 %17, %19
%21 = add nsw i64 %20, 1
%22 = call i8* @malloc(i64 %21)
store i8* %22, i8** %7
%23 = load i8*, i8** %7
%24 = load i8**, i8*** %4
%25 = load i8*, i8** %24
%26 = call i32 @strcpy(i8* %23, i8* %25)
%27 = load i8*, i8** %7
%28 = load i8*, i8** %6
%29 = call i32 @strcat(i8* %27, i8* %28)
br label %35
30: ; preds = %3
%31 = load i8*, i8** %5
%32 = call i64 @strlen(i8* %31)
%33 = add nsw i64 %32, 1
%34 = call i8* @calloc(i64 %33, i32 1)
store i8* %34, i8** %7
br label %35
35: ; preds = %30, %11
%36 = load i8*, i8** %7
%37 = load i8*, i8** %5
%38 = call i32 @strcat(i8* %36, i8* %37)
%39 = load i8**, i8*** %4
%40 = load i8*, i8** %39
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %46
42: ; preds = %35
%43 = load i8**, i8*** %4
%44 = load i8*, i8** %43
%45 = call i32 @free(i8* %44)
br label %46
46: ; preds = %42, %35
%47 = load i8*, i8** %7
%48 = load i8**, i8*** %4
store i8* %47, i8** %48
ret void
}

LLVM IR (-O2):
define void @expand_list(i8** nocapture %0, i8* %1, i8* %2) {
%4 = load i8*, i8** %0
%5 = icmp eq i8* %4, null
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = tail call i64 @strlen(i8* %4)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%9 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%10 = add i64 %7, 1
%11 = add i64 %10, %8
%12 = add i64 %11, %9
%13 = tail call i8* @malloc(i64 %12)
%14 = tail call i32 @strcpy(i8* %13, i8* %4)
%15 = tail call i32 @strcat(i8* %13, i8* %2)
br label %20
16: ; preds = %3
%17 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%18 = add nsw i64 %17, 1
%19 = tail call i8* @calloc(i64 %18, i32 1)
br label %20
20: ; preds = %16, %6
%21 = phi i8* [ %13, %6 ], [ %19, %16 ]
%22 = tail call i32 @strcat(i8* %21, i8* %1)
%23 = load i8*, i8** %0
%24 = icmp eq i8* %23, null
br i1 %24, label %27, label %25
25: ; preds = %20
%26 = tail call i32 @free(i8* %23)
br label %27
27: ; preds = %25, %20
store i8* %21, i8** %0
ret void
}