#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*/ WUR(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int strlen(char const *);
int /*<<< orphan*/ write(int, char *, int);
void printcmdline(char **args) {
  char buf[1024];
  char *p = buf;
  *p++ = '+';
  *p++ = ' ';
  while (*args) {
    const char *arg = *args;
    int l = strlen(arg);
    if (l == 0) {
      arg = "''";
      l = 2;
    }
    if (p + l >= buf + sizeof buf - 3)
      break;
    memcpy(p, arg, l);
    args++;
    p += l;
    *p++ = ' ';
  }
  *p++ = '\n';
  WUR(write(2, buf, p - buf));
}


x86 assembly (clang, -O0):
<printcmdline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x418(%rbp)
mov    -0x418(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x418(%rbp)
movb   $0x2b,(%rax)
mov    -0x418(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x418(%rbp)
movb   $0x20,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     126d <printcmdline+0x12d>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
jne    11e0 <printcmdline+0xa0>
lea    0xe31(%rip),%rax
mov    %rax,-0x420(%rbp)
movl   $0x2,-0x424(%rbp)
mov    -0x418(%rbp),%rax
movslq -0x424(%rbp),%rcx
add    %rcx,%rax
lea    -0x410(%rbp),%rcx
add    $0x400,%rcx
add    $0xfffffffffffffffd,%rcx
cmp    %rcx,%rax
jb     1211 <printcmdline+0xd1>
jmp    126d <printcmdline+0x12d>
mov    -0x418(%rbp),%rdi
mov    -0x420(%rbp),%rsi
mov    -0x424(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x424(%rbp),%ecx
mov    -0x418(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x418(%rbp)
mov    -0x418(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x418(%rbp)
movb   $0x20,(%rax)
jmp    118d <printcmdline+0x4d>
mov    -0x418(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x418(%rbp)
movb   $0xa,(%rax)
lea    -0x410(%rbp),%rsi
mov    -0x418(%rbp),%rax
lea    -0x410(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
mov    $0x2,%edi
call   1040 <write@plt>
mov    %eax,%edi
call   1030 <WUR@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printcmdline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
movw   $0x202b,(%rsp)
lea    0x2(%rsp),%r12
mov    (%rdi),%r15
test   %r15,%r15
je     11cb <printcmdline+0x8b>
mov    %rdi,%r14
add    $0x8,%r14
mov    $0x2,%ebp
lea    0xe89(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
mov    %eax,%edx
cmove  %ebp,%edx
movslq %edx,%rbx
add    %r12,%rbx
lea    0x3fd(%rsp),%rcx
cmp    %rcx,%rbx
jae    11cb <printcmdline+0x8b>
test   %eax,%eax
cmove  %r13,%r15
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <memcpy@plt>
movb   $0x20,(%rbx)
add    $0x1,%rbx
mov    (%r14),%r15
add    $0x8,%r14
mov    %rbx,%r12
test   %r15,%r15
jne    1180 <printcmdline+0x40>
jmp    11ce <printcmdline+0x8e>
mov    %r12,%rbx
movb   $0xa,(%rbx)
mov    %rsp,%rsi
sub    %esi,%ebx
add    $0x1,%ebx
mov    $0x2,%edi
mov    %ebx,%edx
call   1040 <write@plt>
mov    %eax,%edi
call   1030 <WUR@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"''\00"
define void @printcmdline(i8** %0) {
%2 = alloca i8**
%3 = alloca [1024 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8** %0, i8*** %2
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i32 1
store i8* %9, i8** %4
store i8 43, i8* %8
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %4
store i8 32, i8* %10
br label %12
12: ; preds = %34, %1
%13 = load i8**, i8*** %2
%14 = load i8*, i8** %13
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %47
16: ; preds = %12
%17 = load i8**, i8*** %2
%18 = load i8*, i8** %17
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %16
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %5
store i32 2, i32* %6
br label %24
24: ; preds = %23, %16
%25 = load i8*, i8** %4
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%30 = getelementptr inbounds i8, i8* %29, i64 1024
%31 = getelementptr inbounds i8, i8* %30, i64 -3
%32 = icmp uge i8* %28, %31
br i1 %32, label %33, label %34
33: ; preds = %24
br label %47
34: ; preds = %24
%35 = load i8*, i8** %4
%36 = load i8*, i8** %5
%37 = load i32, i32* %6
%38 = call i32 @memcpy(i8* %35, i8* %36, i32 %37)
%39 = load i8**, i8*** %2
%40 = getelementptr inbounds i8*, i8** %39, i32 1
store i8** %40, i8*** %2
%41 = load i32, i32* %6
%42 = load i8*, i8** %4
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds i8, i8* %42, i64 %43
store i8* %44, i8** %4
%45 = load i8*, i8** %4
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %4
store i8 32, i8* %45
br label %12
47: ; preds = %33, %12
%48 = load i8*, i8** %4
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %4
store i8 10, i8* %48
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%51 = load i8*, i8** %4
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%53 = ptrtoint i8* %51 to i64
%54 = ptrtoint i8* %52 to i64
%55 = sub i64 %53, %54
%56 = trunc i64 %55 to i32
%57 = call i32 @write(i32 2, i8* %50, i32 %56)
%58 = call i32 @WUR(i32 %57)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"''\00"
define void @printcmdline(i8** nocapture %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 1
store i8 43, i8* %3
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 2
store i8 32, i8* %4
%6 = load i8*, i8** %0
%7 = icmp eq i8* %6, null
br i1 %7, label %27, label %8
8: ; preds = %1
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 1021
br label %10
10: ; preds = %8, %20
%11 = phi i8* [ %6, %8 ], [ %25, %20 ]
%12 = phi i8* [ %5, %8 ], [ %24, %20 ]
%13 = phi i8** [ %0, %8 ], [ %23, %20 ]
%14 = call i32 @strlen(i8* %11)
%15 = icmp eq i32 %14, 0
%16 = select i1 %15, i32 2, i32 %14
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %12, i64 %17
%19 = icmp ult i8* %18, %9
br i1 %19, label %20, label %27
20: ; preds = %10
%21 = select i1 %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %11
%22 = call i32 @memcpy(i8* %12, i8* %21, i32 %16)
%23 = getelementptr inbounds i8*, i8** %13, i64 1
%24 = getelementptr inbounds i8, i8* %18, i64 1
store i8 32, i8* %18
%25 = load i8*, i8** %23
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %10
27: ; preds = %20, %10, %1
%28 = phi i8* [ %5, %1 ], [ %12, %10 ], [ %24, %20 ]
%29 = getelementptr inbounds i8, i8* %28, i64 1
store i8 10, i8* %28
%30 = ptrtoint i8* %29 to i64
%31 = ptrtoint [1024 x i8]* %2 to i64
%32 = sub i64 %30, %31
%33 = trunc i64 %32 to i32
%34 = call i32 @write(i32 2, i8* %3, i32 %33)
%35 = call i32 @WUR(i32 %34)
ret void
}