#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 **malloc(int);
char *strdup(char *);
int xmms_strlist_len(char **);
char **xmms_strlist_prepend_copy(char **data, char *newstr) {
  int i;
  char **ret;
  ret = malloc((xmms_strlist_len(data) + 2) * sizeof(char *));
  ret[0] = strdup(newstr);
  for (i = 0; data[i] != NULL; i++)
    ret[i + 1] = strdup(data[i]);
  ret[i + 1] = NULL;
  return ret;
}


x86 assembly (clang, -O0):
<xmms_strlist_prepend_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <xmms_strlist_len@plt>
add    $0x2,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11bd <xmms_strlist_prepend_copy+0x8d>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <strdup@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1177 <xmms_strlist_prepend_copy+0x47>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xmms_strlist_prepend_copy>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
call   1030 <xmms_strlist_len@plt>
lea    0x10(,%rax,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1050 <strdup@plt>
mov    %rax,(%r12)
mov    (%r14),%rdi
test   %rdi,%rdi
je     118a <xmms_strlist_prepend_copy+0x5a>
mov    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
call   1050 <strdup@plt>
mov    %rax,(%r12,%rbx,8)
mov    (%r14,%rbx,8),%rdi
add    $0x1,%rbx
test   %rdi,%rdi
jne    1170 <xmms_strlist_prepend_copy+0x40>
mov    %ebx,%eax
jmp    118f <xmms_strlist_prepend_copy+0x5f>
mov    $0x1,%eax
movq   $0x0,(%r12,%rax,8)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define noalias i8** @xmms_strlist_prepend_copy(i8** %0, i8* nocapture %1) {
%3 = tail call i32 @xmms_strlist_len(i8** %0)
%4 = shl i32 %3, 3
%5 = add i32 %4, 16
%6 = tail call i8** @malloc(i32 %5)
%7 = tail call i8* @strdup(i8* %1)
store i8* %7, i8** %6
%8 = load i8*, i8** %0
%9 = icmp eq i8* %8, null
br i1 %9, label %22, label %10
10: ; preds = %2, %10
%11 = phi i64 [ %14, %10 ], [ 0, %2 ]
%12 = phi i8* [ %17, %10 ], [ %8, %2 ]
%13 = tail call i8* @strdup(i8* %12)
%14 = add nuw nsw i64 %11, 1
%15 = getelementptr inbounds i8*, i8** %6, i64 %14
store i8* %13, i8** %15
%16 = getelementptr inbounds i8*, i8** %0, i64 %14
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %10
19: ; preds = %10
%20 = add nuw i64 %11, 2
%21 = and i64 %20, 4294967295
br label %22
22: ; preds = %19, %2
%23 = phi i64 [ 1, %2 ], [ %21, %19 ]
%24 = getelementptr inbounds i8*, i8** %6, i64 %23
store i8* null, i8** %24
ret i8** %6
}