#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_FAILURE;
scalar_t__ asprintf(char **, char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
char *strdup(int /*<<< orphan*/);
char *cmdline(char **av) {
  char *v = NULL;
  while (*av)
    if (v) {
      if (asprintf(&v, "%s %s", v, *av++) < 0)
        err(EXIT_FAILURE, "malloc");
    } else {
      if ((v = strdup(*av++)) == NULL)
        err(EXIT_FAILURE, "strdup");
    }
  return v;
}


x86 assembly (clang, -O0):
<cmdline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     11ef <cmdline+0xbf>
cmpq   $0x0,-0x10(%rbp)
je     11a9 <cmdline+0x79>
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%rax
mov    %eax,%ecx
lea    -0x10(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1040 <asprintf@plt>
cmp    $0x0,%rax
jge    11a4 <cmdline+0x74>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
call   1030 <err@plt>
jmp    11ea <cmdline+0xba>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%rax
mov    %eax,%edi
call   1050 <strdup@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11e5 <cmdline+0xb5>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe2d(%rip),%rsi
call   1030 <err@plt>
jmp    11ea <cmdline+0xba>
jmp    1144 <cmdline+0x14>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmdline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movq   $0x0,(%rsp)
mov    (%rdi),%rcx
test   %rcx,%rcx
je     11d5 <cmdline+0xa5>
mov    %rdi,%rbx
add    $0x8,%rbx
xor    %edx,%edx
lea    0xeae(%rip),%r12
mov    0x2e7a(%rip),%r13
lea    0xe93(%rip),%r14
mov    %rsp,%r15
lea    0xe8f(%rip),%rbp
jmp    1199 <cmdline+0x69>
nopl   0x0(%rax)
mov    0x0(%r13),%edi
call   1030 <err@plt>
mov    (%rbx),%rcx
add    $0x8,%rbx
mov    (%rsp),%rdx
test   %rcx,%rcx
je     11d7 <cmdline+0xa7>
test   %rdx,%rdx
je     11c0 <cmdline+0x90>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <asprintf@plt>
mov    %rbp,%rsi
test   %rax,%rax
jns    1189 <cmdline+0x59>
jmp    1180 <cmdline+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ecx,%edi
call   1050 <strdup@plt>
mov    %rax,(%rsp)
mov    %r12,%rsi
test   %rax,%rax
jne    1189 <cmdline+0x59>
jmp    1180 <cmdline+0x50>
xor    %edx,%edx
mov    %rdx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s %s\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c"malloc\00"
@.str.2 = [7 x i8] c"strdup\00"
define i8* @cmdline(i8** %0) {
%2 = alloca i8**
%3 = alloca i8*
store i8** %0, i8*** %2
store i8* null, i8** %3
br label %4
4: ; preds = %34, %1
%5 = load i8**, i8*** %2
%6 = load i8*, i8** %5
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %35
8: ; preds = %4
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %23
11: ; preds = %8
%12 = load i8*, i8** %3
%13 = load i8**, i8*** %2
%14 = getelementptr inbounds i8*, i8** %13, i32 1
store i8** %14, i8*** %2
%15 = load i8*, i8** %13
%16 = ptrtoint i8* %15 to i32
%17 = call i64 @asprintf(i8** %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @err(i32 %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %19, %11
br label %34
23: ; preds = %8
%24 = load i8**, i8*** %2
%25 = getelementptr inbounds i8*, i8** %24, i32 1
store i8** %25, i8*** %2
%26 = load i8*, i8** %24
%27 = ptrtoint i8* %26 to i32
%28 = call i8* @strdup(i32 %27)
store i8* %28, i8** %3
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %33
30: ; preds = %23
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @err(i32 %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %30, %23
br label %34
34: ; preds = %33, %22
br label %4
35: ; preds = %4
%36 = load i8*, i8** %3
ret i8* %36
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s %s\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c"malloc\00"
@.str.2 = [7 x i8] c"strdup\00"
define i8* @cmdline(i8** nocapture %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%4 = load i8*, i8** %0
%5 = icmp eq i8* %4, null
br i1 %5, label %28, label %6
6: ; preds = %1, %23
%7 = phi i8* [ %27, %23 ], [ null, %1 ]
%8 = phi i8* [ %25, %23 ], [ %4, %1 ]
%9 = phi i8** [ %24, %23 ], [ %0, %1 ]
%10 = icmp eq i8* %7, null
%11 = ptrtoint i8* %8 to i64
%12 = trunc i64 %11 to i32
br i1 %10, label %16, label %13
13: ; preds = %6
%14 = call i64 @asprintf(i8** %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %7, i32 %12)
%15 = icmp slt i64 %14, 0
br i1 %15, label %19, label %23
16: ; preds = %6
%17 = call i8* @strdup(i32 %12)
store i8* %17, i8** %2
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %23
19: ; preds = %16, %13
%20 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %13 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %16 ]
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @err(i32 %21, i8* %20)
br label %23
23: ; preds = %19, %16, %13
%24 = getelementptr inbounds i8*, i8** %9, i64 1
%25 = load i8*, i8** %24
%26 = icmp eq i8* %25, null
%27 = load i8*, i8** %2
br i1 %26, label %28, label %6
28: ; preds = %23, %1
%29 = phi i8* [ null, %1 ], [ %27, %23 ]
ret i8* %29
}