#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 */
int /*<<< orphan*/ memcpy(char *, char *, int);
int strlen(char *);
int cm_join_members(char **mem, char *buf) {
  int i, j, l = 0;
  for (i = 0; mem[i] != NULL; i++) {
    if (i != 0) {
      memcpy(buf + l, ",", 1);
      l += 1;
    }
    j = strlen(mem[i]);
    memcpy(buf + l, mem[i], j);
    l += j;
  }
  memcpy(buf + l, "\0", 1);
  return 0;
}


x86 assembly (clang, -O0):
<cm_join_members>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11ca <cm_join_members+0xaa>
cmpl   $0x0,-0x14(%rbp)
je     1180 <cm_join_members+0x60>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
lea    0xe93(%rip),%rsi
mov    $0x1,%edx
call   1040 <memcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x18(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113e <cm_join_members+0x1e>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
lea    0xe26(%rip),%rsi
mov    $0x1,%edx
call   1040 <memcpy@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cm_join_members>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%rdi
test   %rdi,%rdi
je     11a3 <cm_join_members+0x83>
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    (%rbx),%rsi
mov    %r14,%rdi
mov    %eax,%edx
call   1040 <memcpy@plt>
cmpq   $0x0,0x8(%rbx)
je     11a5 <cm_join_members+0x85>
add    $0x8,%rbx
lea    0xea4(%rip),%r15
nopl   0x0(%rax)
movslq %ebp,%r12
lea    (%r14,%r12,1),%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1040 <memcpy@plt>
mov    (%rbx),%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
lea    (%r14,%r12,1),%rdi
add    $0x1,%rdi
mov    (%rbx),%rsi
mov    %eax,%edx
call   1040 <memcpy@plt>
add    %r12d,%ebp
add    $0x1,%ebp
cmpq   $0x0,0x8(%rbx)
lea    0x8(%rbx),%rbx
jne    1160 <cm_join_members+0x40>
jmp    11a5 <cm_join_members+0x85>
xor    %ebp,%ebp
movslq %ebp,%rax
add    %rax,%r14
lea    0xe50(%rip),%rsi
mov    %r14,%rdi
mov    $0x1,%edx
call   1040 <memcpy@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
@.str.1 = [2 x i8] zeroinitializer
define i32 @cm_join_members(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8** %0, i8*** %3
store i8* %1, i8** %4
store i32 0, i32* %7
store i32 0, i32* %5
br label %8
8: ; preds = %47, %2
%9 = load i8**, i8*** %3
%10 = load i32, i32* %5
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8*, i8** %9, i64 %11
%13 = load i8*, i8** %12
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %50
15: ; preds = %8
%16 = load i32, i32* %5
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %15
%19 = load i8*, i8** %4
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = call i32 @memcpy(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %26
26: ; preds = %18, %15
%27 = load i8**, i8*** %3
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
%31 = load i8*, i8** %30
%32 = call i32 @strlen(i8* %31)
store i32 %32, i32* %6
%33 = load i8*, i8** %4
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8**, i8*** %3
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
%42 = load i32, i32* %6
%43 = call i32 @memcpy(i8* %36, i8* %41, i32 %42)
%44 = load i32, i32* %6
%45 = load i32, i32* %7
%46 = add nsw i32 %45, %44
store i32 %46, i32* %7
br label %47
47: ; preds = %26
%48 = load i32, i32* %5
%49 = add nsw i32 %48, 1
store i32 %49, i32* %5
br label %8
50: ; preds = %8
%51 = load i8*, i8** %4
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = call i32 @memcpy(i8* %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
@.str.1 = [2 x i8] zeroinitializer
define i32 @cm_join_members(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %31, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %3)
%7 = load i8*, i8** %0
%8 = tail call i32 @memcpy(i8* %1, i8* %7, i32 %6)
%9 = getelementptr inbounds i8*, i8** %0, i64 1
%10 = load i8*, i8** %9
%11 = icmp eq i8* %10, null
br i1 %11, label %31, label %12
12: ; preds = %5, %12
%13 = phi i64 [ %27, %12 ], [ 1, %5 ]
%14 = phi i8** [ %28, %12 ], [ %9, %5 ]
%15 = phi i32 [ %26, %12 ], [ %6, %5 ]
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %1, i64 %16
%18 = tail call i32 @memcpy(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%19 = add nsw i32 %15, 1
%20 = load i8*, i8** %14
%21 = tail call i32 @strlen(i8* %20)
%22 = sext i32 %19 to i64
%23 = getelementptr inbounds i8, i8* %1, i64 %22
%24 = load i8*, i8** %14
%25 = tail call i32 @memcpy(i8* %23, i8* %24, i32 %21)
%26 = add nsw i32 %21, %19
%27 = add nuw i64 %13, 1
%28 = getelementptr inbounds i8*, i8** %0, i64 %27
%29 = load i8*, i8** %28
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %12
31: ; preds = %12, %5, %2
%32 = phi i32 [ 0, %2 ], [ %6, %5 ], [ %26, %12 ]
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %1, i64 %33
%35 = tail call i32 @memcpy(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
ret i32 0
}