#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char const *);
scalar_t__ strlen(char const *);
char *build_command_line(const char *argv[]) {
  int size = 0;
  int n = 0;
  int i;
  char *string;
  if (argv) {
    for (i = 0; argv[i]; ++i) {
      size += (strlen(argv[i]) + 1);
      ++n;
    }
  }
  ++size;
  string = (char *)malloc(size);
  if (!string) {
    fprintf(stderr, "DOWN-ROOT: out of memory\n");
    exit(1);
  }
  string[0] = '\0';
  for (i = 0; i < n; ++i) {
    strcat(string, argv[i]);
    if (i + 1 < n)
      strcat(string, " ");
  }
  return string;
}


x86 assembly (clang, -O0):
<build_command_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11cd <build_command_line+0x7d>
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11c8 <build_command_line+0x78>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
add    $0x1,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117c <build_command_line+0x2c>
jmp    11cd <build_command_line+0x7d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    120c <build_command_line+0xbc>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    126d <build_command_line+0x11d>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcat@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cmp    -0x10(%rbp),%eax
jge    125a <build_command_line+0x10a>
mov    -0x20(%rbp),%rdi
lea    0xdc5(%rip),%rsi
call   1060 <strcat@plt>
jmp    125f <build_command_line+0x10f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    121a <build_command_line+0xca>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_command_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x1,%ebx
xor    %r15d,%r15d
test   %rdi,%rdi
je     119b <build_command_line+0x4b>
mov    (%r14),%rdi
test   %rdi,%rdi
je     119b <build_command_line+0x4b>
xor    %r15d,%r15d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
call   1030 <strlen@plt>
add    %eax,%ebx
add    $0x1,%ebx
mov    0x8(%r14,%r15,8),%rdi
add    $0x1,%r15
test   %rdi,%rdi
jne    1180 <build_command_line+0x30>
add    $0x1,%ebx
mov    %ebx,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1216 <build_command_line+0xc6>
mov    %rax,%rbx
movb   $0x0,(%rax)
test   %r15d,%r15d
je     1204 <build_command_line+0xb4>
mov    %r15d,%r12d
mov    %r12,%r13
neg    %r13
mov    $0x1,%ebp
lea    0xe53(%rip),%r15
jmp    11e5 <build_command_line+0x95>
nopl   0x0(%rax)
lea    0x1(,%rbp,1),%rax
add    %r13,%rax
add    $0x1,%rbp
cmp    $0x1,%rax
je     1204 <build_command_line+0xb4>
mov    -0x8(%r14,%rbp,8),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
cmp    %r12,%rbp
jae    11d0 <build_command_line+0x80>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
jmp    11d0 <build_command_line+0x80>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
lea    0xdda(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"DOWN-ROOT: out of memory\0A\00"
@.str.1 = [2 x i8] c" \00"
define i8* @build_command_line(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8** %0, i8*** %2
store i32 0, i32* %3
store i32 0, i32* %4
%7 = load i8**, i8*** %2
%8 = icmp ne i8** %7, null
br i1 %8, label %9, label %35
9: ; preds = %1
store i32 0, i32* %5
br label %10
10: ; preds = %31, %9
%11 = load i8**, i8*** %2
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %11, i64 %13
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %34
17: ; preds = %10
%18 = load i8**, i8*** %2
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
%23 = call i64 @strlen(i8* %22)
%24 = add nsw i64 %23, 1
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = add nsw i64 %26, %24
%28 = trunc i64 %27 to i32
store i32 %28, i32* %3
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %31
31: ; preds = %17
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %10
34: ; preds = %10
br label %35
35: ; preds = %34, %1
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
%38 = load i32, i32* %3
%39 = call i64 @malloc(i32 %38)
%40 = inttoptr i64 %39 to i8*
store i8* %40, i8** %6
%41 = load i8*, i8** %6
%42 = icmp ne i8* %41, null
br i1 %42, label %47, label %43
43: ; preds = %35
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %35
%48 = load i8*, i8** %6
%49 = getelementptr inbounds i8, i8* %48, i64 0
store i8 0, i8* %49
store i32 0, i32* %5
br label %50
50: ; preds = %70, %47
%51 = load i32, i32* %5
%52 = load i32, i32* %4
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %73
54: ; preds = %50
%55 = load i8*, i8** %6
%56 = load i8**, i8*** %2
%57 = load i32, i32* %5
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8*, i8** %56, i64 %58
%60 = load i8*, i8** %59
%61 = call i32 @strcat(i8* %55, i8* %60)
%62 = load i32, i32* %5
%63 = add nsw i32 %62, 1
%64 = load i32, i32* %4
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %69
66: ; preds = %54
%67 = load i8*, i8** %6
%68 = call i32 @strcat(i8* %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %69
69: ; preds = %66, %54
br label %70
70: ; preds = %69
%71 = load i32, i32* %5
%72 = add nsw i32 %71, 1
store i32 %72, i32* %5
br label %50
73: ; preds = %50
%74 = load i8*, i8** %6
ret i8* %74
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"DOWN-ROOT: out of memory\0A\00"
@.str.1 = [2 x i8] c" \00"
define i8* @build_command_line(i8** %0) {
%2 = icmp eq i8** %0, null
br i1 %2, label %21, label %3
3: ; preds = %1
%4 = load i8*, i8** %0
%5 = icmp eq i8* %4, null
br i1 %5, label %21, label %6
6: ; preds = %3, %6
%7 = phi i64 [ %14, %6 ], [ 0, %3 ]
%8 = phi i8* [ %16, %6 ], [ %4, %3 ]
%9 = phi i32 [ %13, %6 ], [ 0, %3 ]
%10 = tail call i64 @strlen(i8* %8)
%11 = trunc i64 %10 to i32
%12 = add i32 %9, 1
%13 = add i32 %12, %11
%14 = add nuw nsw i64 %7, 1
%15 = getelementptr inbounds i8*, i8** %0, i64 %14
%16 = load i8*, i8** %15
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %6
18: ; preds = %6
%19 = trunc i64 %14 to i32
%20 = add i32 %13, 1
br label %21
21: ; preds = %18, %3, %1
%22 = phi i32 [ 0, %1 ], [ 0, %3 ], [ %19, %18 ]
%23 = phi i32 [ 1, %1 ], [ 1, %3 ], [ %20, %18 ]
%24 = tail call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i8*
%26 = icmp eq i64 %24, 0
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %21
store i8 0, i8* %25
%32 = icmp eq i32 %22, 0
br i1 %32, label %46, label %33
33: ; preds = %31
%34 = zext i32 %22 to i64
br label %35
35: ; preds = %33, %44
%36 = phi i64 [ 0, %33 ], [ %40, %44 ]
%37 = getelementptr inbounds i8*, i8** %0, i64 %36
%38 = load i8*, i8** %37
%39 = tail call i32 @strcat(i8* %25, i8* %38)
%40 = add nuw nsw i64 %36, 1
%41 = icmp ult i64 %40, %34
br i1 %41, label %42, label %44
42: ; preds = %35
%43 = tail call i32 @strcat(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %44
44: ; preds = %35, %42
%45 = icmp eq i64 %40, %34
br i1 %45, label %46, label %35
46: ; preds = %44, %31
ret i8* %25
}