#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strlen(char *);
char *parse_command(int argc, char **argv, int start) {
  int commandlength = 0;
  for (int i = start; i < argc; i++) {
    commandlength = strlen(argv[i]);
  }
  char *commandstr = malloc(sizeof(char *) * (commandlength + 1));
  memset(commandstr, 0, (commandlength + 1));
  for (int i = start; i < argc; i++) {
    if (strlen(commandstr) > 0) {
      strcat(commandstr, " ");
    }
    strcat(commandstr, argv[i]);
  }
  return commandstr;
}


x86 assembly (clang, -O0):
<parse_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    118d <parse_command+0x4d>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115f <parse_command+0x1f>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%edx
add    $0x1,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    120d <parse_command+0xcd>
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jle    11ea <parse_command+0xaa>
mov    -0x28(%rbp),%rdi
lea    0xe1b(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcat@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11bb <parse_command+0x7b>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_command>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %rsi,%r15
mov    %edi,%r14d
mov    $0x1,%ebp
cmp    %edi,%edx
jge    1170 <parse_command+0x30>
movslq %r14d,%rax
mov    -0x8(%r15,%rax,8),%rdi
call   1030 <strlen@plt>
mov    %rax,%rbp
add    $0x1,%ebp
lea    0x0(,%rbp,8),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <memset@plt>
cmp    %r14d,%r12d
jge    11e0 <parse_command+0xa0>
movslq %r12d,%rax
lea    (%r15,%rax,8),%r13
sub    %r12d,%r14d
xor    %ebp,%ebp
lea    0xe5d(%rip),%r15
jmp    11c6 <parse_command+0x86>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13,%rbp,8),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
add    $0x1,%rbp
cmp    %ebp,%r14d
je     11e0 <parse_command+0xa0>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
jle    11b0 <parse_command+0x70>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
jmp    11b0 <parse_command+0x70>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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