#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 *joinCmds(char ***cmds) {
  struct dyString *str = newDyString(512);
  int i, j;
  for (i = 0; cmds[i] != NULL; i++) {
    if (i > 0)
      dyStringAppend(str, " | ");
    for (j = 0; cmds[i][j] != NULL; j++) {
      if (j > 0)
        dyStringAppend(str, " ");
      dyStringAppend(str, cmds[i][j]);
    }
  }
  return dyStringCannibalize(&str);
}


x86 assembly (clang, -O0):
<joinCmds>:
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     11f8 <joinCmds+0xc8>
cmpl   $0x0,-0x14(%rbp)
jle    117e <joinCmds+0x4e>
mov    -0x10(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1030 <dyStringAppend@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11e5 <joinCmds+0xb5>
cmpl   $0x0,-0x18(%rbp)
jle    11ba <joinCmds+0x8a>
mov    -0x10(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   1030 <dyStringAppend@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <dyStringAppend@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1185 <joinCmds+0x55>
jmp    11ea <joinCmds+0xba>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1151 <joinCmds+0x21>
lea    -0x10(%rbp),%rdi
call   1050 <dyStringCannibalize@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<joinCmds>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x200,%edi
call   1040 <newDyString@plt>
mov    %rax,%rbx
mov    %rax,(%rsp)
mov    (%r14),%rax
test   %rax,%rax
je     11ef <joinCmds+0xbf>
xor    %r13d,%r13d
lea    0xe9d(%rip),%r15
mov    %r14,%rbp
jmp    1186 <joinCmds+0x56>
nopw   0x0(%rax,%rax,1)
lea    (%r14,%r13,8),%rbp
add    $0x8,%rbp
mov    0x8(%r14,%r13,8),%rax
add    $0x1,%r13
test   %rax,%rax
je     11ef <joinCmds+0xbf>
test   %r13,%r13
je     119e <joinCmds+0x6e>
mov    %rbx,%rdi
lea    0xe6b(%rip),%rsi
call   1030 <dyStringAppend@plt>
mov    0x0(%rbp),%rax
mov    (%rax),%rsi
test   %rsi,%rsi
je     1170 <joinCmds+0x40>
mov    %rbx,%rdi
call   1030 <dyStringAppend@plt>
mov    0x0(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     1170 <joinCmds+0x40>
xor    %r12d,%r12d
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <dyStringAppend@plt>
mov    0x0(%rbp),%rax
mov    0x8(%rax,%r12,1),%rsi
mov    %rbx,%rdi
call   1030 <dyStringAppend@plt>
mov    0x0(%rbp),%rax
cmpq   $0x0,0x10(%rax,%r12,1)
lea    0x8(%r12),%r12
jne    11c0 <joinCmds+0x90>
jmp    1170 <joinCmds+0x40>
mov    %rsp,%rdi
call   1050 <dyStringCannibalize@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dyString = type { i32 }
@.str = [4 x i8] c" | \00"
@.str.1 = [2 x i8] c" \00"
define i8* @joinCmds(i8*** %0) {
%2 = alloca i8***
%3 = alloca %struct.dyString*
%4 = alloca i32
%5 = alloca i32
store i8*** %0, i8**** %2
%6 = call %struct.dyString* @newDyString(i32 512)
store %struct.dyString* %6, %struct.dyString** %3
store i32 0, i32* %4
br label %7
7: ; preds = %54, %1
%8 = load i8***, i8**** %2
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8**, i8*** %8, i64 %10
%12 = load i8**, i8*** %11
%13 = icmp ne i8** %12, null
br i1 %13, label %14, label %57
14: ; preds = %7
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load %struct.dyString*, %struct.dyString** %3
%19 = call i32 @dyStringAppend(%struct.dyString* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %17, %14
store i32 0, i32* %5
br label %21
21: ; preds = %50, %20
%22 = load i8***, i8**** %2
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8**, i8*** %22, i64 %24
%26 = load i8**, i8*** %25
%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 = icmp ne i8* %30, null
br i1 %31, label %32, label %53
32: ; preds = %21
%33 = load i32, i32* %5
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load %struct.dyString*, %struct.dyString** %3
%37 = call i32 @dyStringAppend(%struct.dyString* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %38
38: ; preds = %35, %32
%39 = load %struct.dyString*, %struct.dyString** %3
%40 = load i8***, i8**** %2
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8**, i8*** %40, i64 %42
%44 = load i8**, i8*** %43
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %44, i64 %46
%48 = load i8*, i8** %47
%49 = call i32 @dyStringAppend(%struct.dyString* %39, i8* %48)
br label %50
50: ; preds = %38
%51 = load i32, i32* %5
%52 = add nsw i32 %51, 1
store i32 %52, i32* %5
br label %21
53: ; preds = %21
br label %54
54: ; preds = %53
%55 = load i32, i32* %4
%56 = add nsw i32 %55, 1
store i32 %56, i32* %4
br label %7
57: ; preds = %7
%58 = call i8* @dyStringCannibalize(%struct.dyString** %3)
ret i8* %58
}

LLVM IR (-O2):
%struct.dyString = type { i32 }
@.str = [4 x i8] c" | \00"
@.str.1 = [2 x i8] c" \00"
define i8* @joinCmds(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 %42, label %7
7: ; preds = %1, %37
%8 = phi i8** [ %40, %37 ], [ %5, %1 ]
%9 = phi i64 [ %38, %37 ], [ 0, %1 ]
%10 = phi i8*** [ %39, %37 ], [ %0, %1 ]
%11 = icmp eq i64 %9, 0
br i1 %11, label %15, label %12
12: ; preds = %7
%13 = tail call i32 @dyStringAppend(%struct.dyString* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%14 = load i8**, i8*** %10
br label %15
15: ; preds = %12, %7
%16 = phi i8** [ %14, %12 ], [ %8, %7 ]
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
br i1 %18, label %37, label %19
19: ; preds = %15
%20 = tail call i32 @dyStringAppend(%struct.dyString* %4, i8* %17)
%21 = load i8**, i8*** %10
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = icmp eq i8* %23, null
br i1 %24, label %37, label %25
25: ; preds = %19, %25
%26 = phi i64 [ %32, %25 ], [ 1, %19 ]
%27 = tail call i32 @dyStringAppend(%struct.dyString* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = load i8**, i8*** %10
%29 = getelementptr inbounds i8*, i8** %28, i64 %26
%30 = load i8*, i8** %29
%31 = tail call i32 @dyStringAppend(%struct.dyString* %4, i8* %30)
%32 = add nuw i64 %26, 1
%33 = load i8**, i8*** %10
%34 = getelementptr inbounds i8*, i8** %33, i64 %32
%35 = load i8*, i8** %34
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %25
37: ; preds = %25, %19, %15
%38 = add nuw i64 %9, 1
%39 = getelementptr inbounds i8**, i8*** %0, i64 %38
%40 = load i8**, i8*** %39
%41 = icmp eq i8** %40, null
br i1 %41, label %42, label %7
42: ; preds = %37, %1
%43 = call i8* @dyStringCannibalize(%struct.dyString** %2)
ret i8* %43
}