#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 */
struct ll_node {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
struct ll_node *ll_append(struct ll_node **, char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
scalar_t__ strlen(char *);
struct ll_node *ll_csv_append(struct ll_node **head, char *contents,
                              int current_word) {
  char *word = contents + current_word;
  char *word_copy = malloc(strlen(word) + 1);
  if (word_copy == NULL) {
    fprintf(stderr, "%s: %s\n", "malloc", strerror(errno));
    return NULL;
  }
  strcpy(word_copy, word);
  return ll_append(head, word_copy);
}


x86 assembly (clang, -O0):
<ll_csv_append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11e6 <ll_csv_append+0x86>
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rcx
lea    0xe33(%rip),%rsi
lea    0xe34(%rip),%rdx
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1204 <ll_csv_append+0xa4>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <ll_append@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ll_csv_append>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
movslq %edx,%rbx
add    %rsi,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     11a2 <ll_csv_append+0x42>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %r15,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <ll_append@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%ebx
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe40(%rip),%rsi
lea    0xe41(%rip),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
call   1050 <fprintf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.ll_node = type { i32 }
@stderr = global i32 0
@.str = [8 x i8] c"%s: %s\0A\00"
@.str.1 = [7 x i8] c"malloc\00"
@errno = global i32 0
define %struct.ll_node* @ll_csv_append(%struct.ll_node** %0, i8* %1, i32 %2) {
%4 = alloca %struct.ll_node*
%5 = alloca %struct.ll_node**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store %struct.ll_node** %0, %struct.ll_node*** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %6
%11 = load i32, i32* %7
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
store i8* %13, i8** %8
%14 = load i8*, i8** %8
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 %15, 1
%17 = call i8* @malloc(i64 %16)
store i8* %17, i8** %9
%18 = load i8*, i8** %9
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %25
20: ; preds = %3
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %23)
store %struct.ll_node* null, %struct.ll_node** %4
br label %32
25: ; preds = %3
%26 = load i8*, i8** %9
%27 = load i8*, i8** %8
%28 = call i32 @strcpy(i8* %26, i8* %27)
%29 = load %struct.ll_node**, %struct.ll_node*** %5
%30 = load i8*, i8** %9
%31 = call %struct.ll_node* @ll_append(%struct.ll_node** %29, i8* %30)
store %struct.ll_node* %31, %struct.ll_node** %4
br label %32
32: ; preds = %25, %20
%33 = load %struct.ll_node*, %struct.ll_node** %4
ret %struct.ll_node* %33
}

LLVM IR (-O2):
%struct.ll_node = type { i32 }
@stderr = global i32 0
@.str = [8 x i8] c"%s: %s\0A\00"
@.str.1 = [7 x i8] c"malloc\00"
@errno = global i32 0
define %struct.ll_node* @ll_csv_append(%struct.ll_node** %0, i8* %1, i32 %2) {
%4 = sext i32 %2 to i64
%5 = getelementptr inbounds i8, i8* %1, i64 %4
%6 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%7 = add nsw i64 %6, 1
%8 = tail call i8* @malloc(i64 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %15
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %18
15: ; preds = %3
%16 = tail call i32 @strcpy(i8* %8, i8* %5)
%17 = tail call %struct.ll_node* @ll_append(%struct.ll_node** %0, i8* %8)
br label %18
18: ; preds = %15, %10
%19 = phi %struct.ll_node* [ null, %10 ], [ %17, %15 ]
ret %struct.ll_node* %19
}