#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 *concat(char *, char *, char *);
scalar_t__ strcmp(char *, char *);
char *build_command(char **commands) {
  char *result = "";
  int i = 0;
  while (strcmp("\0", commands[i])) {
    result = concat(result, " ", commands[i]);
    i++;
  }
  return result;
}


x86 assembly (clang, -O0):
<build_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xece(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xeb1(%rip),%rdi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     118e <build_command+0x6e>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe89(%rip),%rsi
call   1030 <concat@plt>
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113e <build_command+0x1e>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_command>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%rsi
lea    0xecd(%rip),%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1188 <build_command+0x68>
add    $0x8,%rbx
lea    0xeb7(%rip),%r14
lea    0xeaf(%rip),%r15
lea    0xeaa(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    -0x8(%rbx),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <concat@plt>
mov    %rax,%r14
mov    (%rbx),%rsi
mov    %r12,%rdi
call   1040 <strcmp@plt>
add    $0x8,%rbx
test   %rax,%rax
jne    1160 <build_command+0x40>
jmp    118f <build_command+0x6f>
lea    0xe72(%rip),%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] zeroinitializer
@.str.2 = [2 x i8] c" \00"
define i8* @build_command(i8** %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i32
store i8** %0, i8*** %2
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
store i32 0, i32* %4
br label %5
5: ; preds = %13, %1
%6 = load i8**, i8*** %2
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8*, i8** %6, i64 %8
%10 = load i8*, i8** %9
%11 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %5
%14 = load i8*, i8** %3
%15 = load i8**, i8*** %2
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = call i8* @concat(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %19)
store i8* %20, i8** %3
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %5
23: ; preds = %5
%24 = load i8*, i8** %3
ret i8* %24
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] zeroinitializer
@.str.2 = [2 x i8] c" \00"
define i8* @build_command(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = tail call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %16, label %5
5: ; preds = %1, %5
%6 = phi i64 [ %11, %5 ], [ 0, %1 ]
%7 = phi i8** [ %12, %5 ], [ %0, %1 ]
%8 = phi i8* [ %10, %5 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %1 ]
%9 = load i8*, i8** %7
%10 = tail call i8* @concat(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = add nuw i64 %6, 1
%12 = getelementptr inbounds i8*, i8** %0, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %5
16: ; preds = %5, %1
%17 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %1 ], [ %10, %5 ]
ret i8* %17
}