#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*/ memset(char *, char, size_t);
scalar_t__ strchr(char const *, char);
char *system_quote_arg(char *q, char const *a) {
  int needs_quoting = !*a || strchr(a, ' ') || strchr(a, '\t');
  size_t backslashes = 0;
  char c;
  if (needs_quoting)
    *q++ = '"';
  for (;; *q++ = c) {
    c = *a++;
    switch (c) {
    case '\\':
      backslashes++;
      continue;
    case '"':
      backslashes++;
      memset(q, '\\', backslashes);
      q += backslashes;
    default:
      backslashes = 0;
      continue;
    case 0:
      break;
    }
    break;
  }
  if (needs_quoting) {
    memset(q, '\\', backslashes);
    q += backslashes;
    *q++ = '"';
  }
  return q;
}


x86 assembly (clang, -O0):
<system_quote_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
mov    $0x1,%al
cmpb   $0x0,(%rcx)
mov    %al,-0x22(%rbp)
je     117a <system_quote_arg+0x5a>
mov    -0x10(%rbp),%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x22(%rbp)
jne    117a <system_quote_arg+0x5a>
mov    -0x10(%rbp),%rdi
mov    $0x9,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11a9 <system_quote_arg+0x89>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x22,(%rax)
jmp    11ae <system_quote_arg+0x8e>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
mov    %eax,-0x28(%rbp)
test   %eax,%eax
je     1240 <system_quote_arg+0x120>
jmp    11d6 <system_quote_arg+0xb6>
mov    -0x28(%rbp),%eax
sub    $0x22,%eax
je     1209 <system_quote_arg+0xe9>
jmp    11e7 <system_quote_arg+0xc7>
mov    -0x28(%rbp),%eax
sub    $0x5c,%eax
jne    1233 <system_quote_arg+0x113>
jmp    11f8 <system_quote_arg+0xd8>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    124a <system_quote_arg+0x12a>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x5c,%esi
call   1040 <memset@plt>
mov    -0x20(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
movq   $0x0,-0x20(%rbp)
jmp    124a <system_quote_arg+0x12a>
jmp    1245 <system_quote_arg+0x125>
jmp    1263 <system_quote_arg+0x143>
mov    -0x21(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    11ae <system_quote_arg+0x8e>
cmpl   $0x0,-0x14(%rbp)
je     129d <system_quote_arg+0x17d>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x5c,%esi
call   1040 <memset@plt>
mov    -0x20(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x22,(%rax)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<system_quote_arg>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbp
cmpb   $0x0,(%rsi)
je     115b <system_quote_arg+0x3b>
mov    %r14,%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    115b <system_quote_arg+0x3b>
mov    %r14,%rdi
mov    $0x9,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11e8 <system_quote_arg+0xc8>
movb   $0x22,0x0(%rbp)
add    $0x1,%rbp
mov    $0x1,%r12b
xor    %r15d,%r15d
jmp    1182 <system_quote_arg+0x62>
nopl   0x0(%rax,%rax,1)
test   %eax,%eax
je     11ba <system_quote_arg+0x9a>
xor    %r15d,%r15d
add    $0x1,%r14
mov    %bl,0x0(%rbp)
add    $0x1,%rbp
movzbl (%r14),%ebx
movsbl %bl,%eax
cmp    $0x22,%eax
je     11a0 <system_quote_arg+0x80>
cmp    $0x5c,%eax
jne    1170 <system_quote_arg+0x50>
add    $0x1,%r15
jmp    1177 <system_quote_arg+0x57>
nopl   0x0(%rax)
lea    0x1(%r15),%rdx
mov    %rbp,%rdi
mov    $0x5c,%esi
call   1040 <memset@plt>
add    %r15,%rbp
add    $0x1,%rbp
jmp    1174 <system_quote_arg+0x54>
test   %r12b,%r12b
je     11dc <system_quote_arg+0xbc>
mov    %rbp,%rdi
mov    $0x5c,%esi
mov    %r15,%rdx
call   1040 <memset@plt>
movb   $0x22,0x0(%rbp,%r15,1)
add    %r15,%rbp
add    $0x1,%rbp
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r12d,%r12d
jmp    1166 <system_quote_arg+0x46>

LLVM IR (-O0):
define i8* @system_quote_arg(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i64 @strchr(i8* %12, i8 signext 32)
%14 = icmp ne i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = call i64 @strchr(i8* %16, i8 signext 9)
%18 = icmp ne i64 %17, 0
br label %19
19: ; preds = %15, %11, %2
%20 = phi i1 [ true, %11 ], [ true, %2 ], [ %18, %15 ]
%21 = zext i1 %20 to i32
store i32 %21, i32* %5
store i64 0, i64* %6
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %3
store i8 34, i8* %25
br label %27
27: ; preds = %24, %19
br label %28
28: ; preds = %49, %27
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %4
%31 = load i8, i8* %29
store i8 %31, i8* %7
%32 = load i8, i8* %7
%33 = sext i8 %32 to i32
switch i32 %33, label %46 [
i32 92, label %34
i32 34, label %37
i32 0, label %47
]
34: ; preds = %28
%35 = load i64, i64* %6
%36 = add i64 %35, 1
store i64 %36, i64* %6
br label %49
37: ; preds = %28
%38 = load i64, i64* %6
%39 = add i64 %38, 1
store i64 %39, i64* %6
%40 = load i8*, i8** %3
%41 = load i64, i64* %6
%42 = call i32 @memset(i8* %40, i8 signext 92, i64 %41)
%43 = load i64, i64* %6
%44 = load i8*, i8** %3
%45 = getelementptr inbounds i8, i8* %44, i64 %43
store i8* %45, i8** %3
br label %46
46: ; preds = %28, %37
store i64 0, i64* %6
br label %49
47: ; preds = %28
br label %48
48: ; preds = %47
br label %53
49: ; preds = %46, %34
%50 = load i8, i8* %7
%51 = load i8*, i8** %3
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %3
store i8 %50, i8* %51
br label %28
53: ; preds = %48
%54 = load i32, i32* %5
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %65
56: ; preds = %53
%57 = load i8*, i8** %3
%58 = load i64, i64* %6
%59 = call i32 @memset(i8* %57, i8 signext 92, i64 %58)
%60 = load i64, i64* %6
%61 = load i8*, i8** %3
%62 = getelementptr inbounds i8, i8* %61, i64 %60
store i8* %62, i8** %3
%63 = load i8*, i8** %3
%64 = getelementptr inbounds i8, i8* %63, i32 1
store i8* %64, i8** %3
store i8 34, i8* %63
br label %65
65: ; preds = %56, %53
%66 = load i8*, i8** %3
ret i8* %66
}

LLVM IR (-O2):
define i8* @system_quote_arg(i8* %0, i8* %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = tail call i64 @strchr(i8* %1, i8 signext 32)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = tail call i64 @strchr(i8* %1, i8 signext 9)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %2, %5, %8
%12 = getelementptr inbounds i8, i8* %0, i64 1
store i8 34, i8* %0
br label %13
13: ; preds = %11, %8
%14 = phi i1 [ true, %11 ], [ false, %8 ]
%15 = phi i8* [ %12, %11 ], [ %0, %8 ]
br label %16
16: ; preds = %29, %13
%17 = phi i8* [ %1, %13 ], [ %20, %29 ]
%18 = phi i64 [ 0, %13 ], [ %30, %29 ]
%19 = phi i8* [ %15, %13 ], [ %32, %29 ]
%20 = getelementptr inbounds i8, i8* %17, i64 1
%21 = load i8, i8* %17
%22 = sext i8 %21 to i32
switch i32 %22, label %29 [
i32 92, label %23
i32 34, label %25
i32 0, label %33
]
23: ; preds = %16
%24 = add i64 %18, 1
br label %29
25: ; preds = %16
%26 = add i64 %18, 1
%27 = tail call i32 @memset(i8* %19, i8 signext 92, i64 %26)
%28 = getelementptr inbounds i8, i8* %19, i64 %26
br label %29
29: ; preds = %25, %16, %23
%30 = phi i64 [ %24, %23 ], [ 0, %16 ], [ 0, %25 ]
%31 = phi i8* [ %19, %23 ], [ %19, %16 ], [ %28, %25 ]
%32 = getelementptr inbounds i8, i8* %31, i64 1
store i8 %21, i8* %31
br label %16
33: ; preds = %16
br i1 %14, label %34, label %38
34: ; preds = %33
%35 = tail call i32 @memset(i8* %19, i8 signext 92, i64 %18)
%36 = getelementptr inbounds i8, i8* %19, i64 %18
%37 = getelementptr inbounds i8, i8* %36, i64 1
store i8 34, i8* %36
br label %38
38: ; preds = %34, %33
%39 = phi i8* [ %37, %34 ], [ %19, %33 ]
ret i8* %39
}