#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 dyString {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ dyStringAppend(struct dyString *, char *);
char *dyStringCannibalize(struct dyString **);
struct dyString *newDyString(int);
char *joinCmd(char **cmd) {
  struct dyString *str = newDyString(512);
  int i;
  for (i = 0; cmd[i] != NULL; i++) {
    if (i > 0)
      dyStringAppend(str, " ");
    dyStringAppend(str, cmd[i]);
  }
  return dyStringCannibalize(&str);
}


x86 assembly (clang, -O0):
<joinCmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x200,%edi
call   1040 <newDyString@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11a1 <joinCmd+0x71>
cmpl   $0x0,-0x14(%rbp)
jle    117e <joinCmd+0x4e>
mov    -0x10(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1030 <dyStringAppend@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <dyStringAppend@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1151 <joinCmd+0x21>
lea    -0x10(%rbp),%rdi
call   1050 <dyStringCannibalize@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<joinCmd>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    $0x200,%edi
call   1040 <newDyString@plt>
mov    %rax,0x8(%rsp)
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1191 <joinCmd+0x61>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <dyStringAppend@plt>
cmpq   $0x0,0x8(%rbx)
je     1191 <joinCmd+0x61>
add    $0x10,%rbx
lea    0xe90(%rip),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <dyStringAppend@plt>
mov    -0x8(%rbx),%rsi
mov    %r14,%rdi
call   1030 <dyStringAppend@plt>
cmpq   $0x0,(%rbx)
lea    0x8(%rbx),%rbx
jne    1170 <joinCmd+0x40>
lea    0x8(%rsp),%rdi
call   1050 <dyStringCannibalize@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.dyString = type { i32 }
@.str = [2 x i8] c" \00"
define i8* @joinCmd(i8** %0) {
%2 = alloca i8**
%3 = alloca %struct.dyString*
%4 = alloca i32
store i8** %0, i8*** %2
%5 = call %struct.dyString* @newDyString(i32 512)
store %struct.dyString* %5, %struct.dyString** %3
store i32 0, i32* %4
br label %6
6: ; preds = %27, %1
%7 = load i8**, i8*** %2
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8*, i8** %7, i64 %9
%11 = load i8*, i8** %10
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %30
13: ; preds = %6
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load %struct.dyString*, %struct.dyString** %3
%18 = call i32 @dyStringAppend(%struct.dyString* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %16, %13
%20 = load %struct.dyString*, %struct.dyString** %3
%21 = load i8**, i8*** %2
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 @dyStringAppend(%struct.dyString* %20, i8* %25)
br label %27
27: ; preds = %19
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %6
30: ; preds = %6
%31 = call i8* @dyStringCannibalize(%struct.dyString** %3)
ret i8* %31
}

LLVM IR (-O2):
%struct.dyString = type { i32 }
@.str = [2 x i8] c" \00"
define i8* @joinCmd(i8** nocapture %0) {
%2 = alloca %struct.dyString*
%3 = bitcast %struct.dyString** %2 to i8*
%4 = tail call %struct.dyString* @newDyString(i32 512)
store %struct.dyString* %4, %struct.dyString** %2
%5 = load i8*, i8** %0
%6 = icmp eq i8* %5, null
br i1 %6, label %22, label %7
7: ; preds = %1
%8 = tail call i32 @dyStringAppend(%struct.dyString* %4, i8* %5)
%9 = getelementptr inbounds i8*, i8** %0, i64 1
%10 = load i8*, i8** %9
%11 = icmp eq i8* %10, null
br i1 %11, label %22, label %12
12: ; preds = %7, %12
%13 = phi i64 [ %18, %12 ], [ 1, %7 ]
%14 = phi i8** [ %19, %12 ], [ %9, %7 ]
%15 = tail call i32 @dyStringAppend(%struct.dyString* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = load i8*, i8** %14
%17 = tail call i32 @dyStringAppend(%struct.dyString* %4, i8* %16)
%18 = add nuw i64 %13, 1
%19 = getelementptr inbounds i8*, i8** %0, i64 %18
%20 = load i8*, i8** %19
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %12
22: ; preds = %12, %7, %1
%23 = call i8* @dyStringCannibalize(%struct.dyString** %2)
ret i8* %23
}