#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*/ *strchr(char const *, char);
char *shellEscapeStr(const char *str_, char *buff_) {
  char *out = buff_;
  int hasSpace = strchr(str_, ' ') != NULL;
  if (hasSpace) {
    *out++ = '\\';
    *out++ = '\"';
  }
  while (*str_) {
    switch (*str_) {
    case '\\':
    case '\"':
    case '\t':
      *out++ = '\\';
      *out++ = *str_++;
      break;
    default:
      *out++ = *str_++;
      break;
    }
  }
  if (hasSpace) {
    *out++ = '\\';
    *out++ = '\"';
  }
  *out = '\0';
  return buff_;
}


x86 assembly (clang, -O0):
<shellEscapeStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1173 <shellEscapeStr+0x63>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5c,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x22,(%rax)
jmp    1178 <shellEscapeStr+0x68>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     121f <shellEscapeStr+0x10f>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x20(%rbp)
sub    $0x9,%eax
je     11bf <shellEscapeStr+0xaf>
jmp    119d <shellEscapeStr+0x8d>
mov    -0x20(%rbp),%eax
sub    $0x22,%eax
je     11bf <shellEscapeStr+0xaf>
jmp    11ae <shellEscapeStr+0x9e>
mov    -0x20(%rbp),%eax
sub    $0x5c,%eax
jne    11f8 <shellEscapeStr+0xe8>
jmp    11bf <shellEscapeStr+0xaf>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5c,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    121a <shellEscapeStr+0x10a>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1178 <shellEscapeStr+0x68>
cmpl   $0x0,-0x1c(%rbp)
je     124d <shellEscapeStr+0x13d>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5c,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x22,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shellEscapeStr>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x20,%esi
call   1030 <strchr@plt>
mov    %r14,%rcx
test   %rax,%rax
je     1136 <shellEscapeStr+0x26>
movw   $0x225c,(%r14)
lea    0x2(%r14),%rcx
mov    (%rbx),%dl
test   %dl,%dl
je     1183 <shellEscapeStr+0x73>
add    $0x1,%rbx
jmp    1169 <shellEscapeStr+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x5c,(%rcx)
movzbl -0x1(%rbx),%edx
mov    %dl,0x1(%rcx)
add    $0x2,%rcx
movzbl (%rbx),%edx
add    $0x1,%rbx
test   %dl,%dl
je     1183 <shellEscapeStr+0x73>
movsbl %dl,%esi
cmp    $0x9,%esi
je     1150 <shellEscapeStr+0x40>
cmp    $0x5c,%esi
je     1150 <shellEscapeStr+0x40>
cmp    $0x22,%esi
je     1150 <shellEscapeStr+0x40>
mov    %dl,(%rcx)
add    $0x1,%rcx
jmp    115e <shellEscapeStr+0x4e>
test   %rax,%rax
je     1191 <shellEscapeStr+0x81>
movw   $0x225c,(%rcx)
add    $0x2,%rcx
movb   $0x0,(%rcx)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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