#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 *shell_quote_copy(char *, char *);
scalar_t__ shell_quote_length(char *);
scalar_t__ xmalloc(size_t);
char *xstrdup(char *);
char *shell_quote_argv(char **argv) {
  if (*argv != NULL) {
    char **argp;
    size_t length;
    char *command;
    char *p;
    length = 0;
    for (argp = argv;;) {
      length += shell_quote_length(*argp) + 1;
      argp++;
      if (*argp == NULL)
        break;
    }
    command = (char *)xmalloc(length);
    p = command;
    for (argp = argv;;) {
      p = shell_quote_copy(p, *argp);
      argp++;
      if (*argp == NULL)
        break;
      *p++ = ' ';
    }
    *p = '\0';
    return command;
  } else
    return xstrdup("");
}


x86 assembly (clang, -O0):
<shell_quote_argv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1221 <shell_quote_argv+0xe1>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1050 <shell_quote_length@plt>
add    $0x1,%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11a1 <shell_quote_argv+0x61>
jmp    11a6 <shell_quote_argv+0x66>
jmp    116a <shell_quote_argv+0x2a>
mov    -0x20(%rbp),%rdi
call   1030 <xmalloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   1060 <shell_quote_copy@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11f6 <shell_quote_argv+0xb6>
jmp    120d <shell_quote_argv+0xcd>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x20,(%rax)
jmp    11c3 <shell_quote_argv+0x83>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1231 <shell_quote_argv+0xf1>
lea    0xdd8(%rip),%rdi
call   1040 <xstrdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shell_quote_argv>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    (%rdi),%rdi
test   %rdi,%rdi
je     11c9 <shell_quote_argv+0x89>
lea    0x8(%r15),%rbx
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
call   1050 <shell_quote_length@plt>
add    %rax,%r14
add    $0x1,%r14
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
jne    1160 <shell_quote_argv+0x20>
mov    %r14,%rdi
call   1030 <xmalloc@plt>
mov    %rax,%r14
mov    (%r15),%rsi
mov    %rax,%rdi
call   1060 <shell_quote_copy@plt>
cmpq   $0x0,0x8(%r15)
je     11bd <shell_quote_argv+0x7d>
add    $0x10,%r15
nopl   0x0(%rax)
movb   $0x20,(%rax)
add    $0x1,%rax
mov    -0x8(%r15),%rsi
mov    %rax,%rdi
call   1060 <shell_quote_copy@plt>
cmpq   $0x0,(%r15)
lea    0x8(%r15),%r15
jne    11a0 <shell_quote_argv+0x60>
movb   $0x0,(%rax)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe30(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <xstrdup@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @shell_quote_argv(i8** %0) {
%2 = alloca i8*
%3 = alloca i8**
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
store i8** %0, i8*** %3
%8 = load i8**, i8*** %3
%9 = load i8*, i8** %8
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %50
11: ; preds = %1
store i64 0, i64* %5
%12 = load i8**, i8*** %3
store i8** %12, i8*** %4
br label %13
13: ; preds = %26, %11
%14 = load i8**, i8*** %4
%15 = load i8*, i8** %14
%16 = call i64 @shell_quote_length(i8* %15)
%17 = add nsw i64 %16, 1
%18 = load i64, i64* %5
%19 = add i64 %18, %17
store i64 %19, i64* %5
%20 = load i8**, i8*** %4
%21 = getelementptr inbounds i8*, i8** %20, i32 1
store i8** %21, i8*** %4
%22 = load i8**, i8*** %4
%23 = load i8*, i8** %22
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %13
br label %27
26: ; preds = %13
br label %13
27: ; preds = %25
%28 = load i64, i64* %5
%29 = call i64 @xmalloc(i64 %28)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %6
%31 = load i8*, i8** %6
store i8* %31, i8** %7
%32 = load i8**, i8*** %3
store i8** %32, i8*** %4
br label %33
33: ; preds = %44, %27
%34 = load i8*, i8** %7
%35 = load i8**, i8*** %4
%36 = load i8*, i8** %35
%37 = call i8* @shell_quote_copy(i8* %34, i8* %36)
store i8* %37, i8** %7
%38 = load i8**, i8*** %4
%39 = getelementptr inbounds i8*, i8** %38, i32 1
store i8** %39, i8*** %4
%40 = load i8**, i8*** %4
%41 = load i8*, i8** %40
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %44
43: ; preds = %33
br label %47
44: ; preds = %33
%45 = load i8*, i8** %7
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %7
store i8 32, i8* %45
br label %33
47: ; preds = %43
%48 = load i8*, i8** %7
store i8 0, i8* %48
%49 = load i8*, i8** %6
store i8* %49, i8** %2
br label %52
50: ; preds = %1
%51 = call i8* @xstrdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %51, i8** %2
br label %52
52: ; preds = %50, %47
%53 = load i8*, i8** %2
ret i8* %53
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @shell_quote_argv(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = icmp eq i8* %2, null
br i1 %3, label %33, label %4
4: ; preds = %1, %4
%5 = phi i8* [ %12, %4 ], [ %2, %1 ]
%6 = phi i8** [ %11, %4 ], [ %0, %1 ]
%7 = phi i64 [ %10, %4 ], [ 0, %1 ]
%8 = tail call i64 @shell_quote_length(i8* %5)
%9 = add i64 %7, 1
%10 = add i64 %9, %8
%11 = getelementptr inbounds i8*, i8** %6, i64 1
%12 = load i8*, i8** %11
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %4
14: ; preds = %4
%15 = tail call i64 @xmalloc(i64 %10)
%16 = inttoptr i64 %15 to i8*
%17 = load i8*, i8** %0
%18 = tail call i8* @shell_quote_copy(i8* %16, i8* %17)
%19 = getelementptr inbounds i8*, i8** %0, i64 1
%20 = load i8*, i8** %19
%21 = icmp eq i8* %20, null
br i1 %21, label %31, label %22
22: ; preds = %14, %22
%23 = phi i8** [ %28, %22 ], [ %19, %14 ]
%24 = phi i8* [ %27, %22 ], [ %18, %14 ]
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8 32, i8* %24
%26 = load i8*, i8** %23
%27 = tail call i8* @shell_quote_copy(i8* %25, i8* %26)
%28 = getelementptr inbounds i8*, i8** %23, i64 1
%29 = load i8*, i8** %28
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %22
31: ; preds = %22, %14
%32 = phi i8* [ %18, %14 ], [ %27, %22 ]
store i8 0, i8* %32
br label %35
33: ; preds = %1
%34 = tail call i8* @xstrdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %33, %31
%36 = phi i8* [ %16, %31 ], [ %34, %33 ]
ret i8* %36
}