#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);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int listadditem(char **list, char *item, int *count, int capacity) {
  if (*count >= capacity) {
    return 0;
  }
  list[*count] = malloc(strlen(item) / sizeof(char));
  strcpy(list[*count], item);
  *count += 1;
  return 1;
}


x86 assembly (clang, -O0):
<listadditem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
cmp    -0x24(%rbp),%eax
jl     1162 <listadditem+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11b4 <listadditem+0x84>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cltq
shr    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq (%rcx),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<listadditem>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
cmp    %ecx,(%rdx)
jge    116d <listadditem+0x3d>
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1050 <malloc@plt>
movslq (%rbx),%rcx
mov    %rax,(%r15,%rcx,8)
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
addl   $0x1,(%rbx)
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @listadditem(i8** nocapture %0, i8* %1, i32* nocapture %2, i32 %3) {
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, %3
br i1 %6, label %7, label %16
7: ; preds = %4
%8 = tail call i32 @strlen(i8* %1)
%9 = tail call i8* @malloc(i32 %8)
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8*, i8** %0, i64 %11
store i8* %9, i8** %12
%13 = tail call i32 @strcpy(i8* %9, i8* %1)
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
store i32 %15, i32* %2
br label %16
16: ; preds = %4, %7
%17 = phi i32 [ 1, %7 ], [ 0, %4 ]
ret i32 %17
}