#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*/ memcpy(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned char);
int wordsplit_c_quote_char(char const);
void wordsplit_c_quote_copy(char *dst, const char *src, int quote_hex) {
  for (; *src; src++) {
    if (*src == '"') {
      *dst++ = '\\';
      *dst++ = *src;
    } else if (*src != '\t' && *src != '\\' &&
               (' ' <= ((unsigned)(*src)) && ((unsigned)(*src)) <= 127))
      *dst++ = *src;
    else {
      char tmp[4];
      if (quote_hex) {
        snprintf(tmp, sizeof tmp, "%%%02X", *(unsigned char *)src);
        memcpy(dst, tmp, 3);
        dst += 3;
      } else {
        int c = wordsplit_c_quote_char(*src);
        *dst++ = '\\';
        if (c != -1)
          *dst++ = c;
        else {
          snprintf(tmp, sizeof tmp, "%03o", *(unsigned char *)src);
          memcpy(dst, tmp, 3);
          dst += 3;
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<wordsplit_c_quote_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     12dc <wordsplit_c_quote_copy+0x1ac>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    118e <wordsplit_c_quote_copy+0x5e>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    12c6 <wordsplit_c_quote_copy+0x196>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
je     11ee <wordsplit_c_quote_copy+0xbe>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
je     11ee <wordsplit_c_quote_copy+0xbe>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x20,%eax
cmp    %ecx,%eax
ja     11ee <wordsplit_c_quote_copy+0xbe>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7f,%eax
ja     11ee <wordsplit_c_quote_copy+0xbe>
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    12c1 <wordsplit_c_quote_copy+0x191>
cmpl   $0x0,-0x14(%rbp)
je     1237 <wordsplit_c_quote_copy+0x107>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    $0x4,%esi
lea    0xdf4(%rip),%rdx
movzbl (%rax),%ecx
call   1030 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x3,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x8(%rbp)
jmp    12bc <wordsplit_c_quote_copy+0x18c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <wordsplit_c_quote_char@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
cmpl   $0xffffffff,-0x1c(%rbp)
je     127d <wordsplit_c_quote_copy+0x14d>
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    12b7 <wordsplit_c_quote_copy+0x187>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    $0x4,%esi
lea    0xd76(%rip),%rdx
movzbl (%rax),%ecx
call   1030 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x3,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x8(%rbp)
jmp    12bc <wordsplit_c_quote_copy+0x18c>
jmp    12c1 <wordsplit_c_quote_copy+0x191>
jmp    12c6 <wordsplit_c_quote_copy+0x196>
jmp    12cb <wordsplit_c_quote_copy+0x19b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1143 <wordsplit_c_quote_copy+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wordsplit_c_quote_copy>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0x4(%rsp),%r12
lea    0xeb0(%rip),%r13
jmp    1194 <wordsplit_c_quote_copy+0x64>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x9,%al
jne    11ce <wordsplit_c_quote_copy+0x9e>
test   %r14d,%r14d
je     11b0 <wordsplit_c_quote_copy+0x80>
movzbl %al,%ecx
mov    %r12,%rdi
mov    $0x4,%esi
mov    %r13,%rdx
call   1030 <snprintf@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    $0x3,%edx
call   1040 <memcpy@plt>
add    $0x3,%rbp
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x21,%al
jle    1160 <wordsplit_c_quote_copy+0x30>
cmp    $0x5c,%al
je     1164 <wordsplit_c_quote_copy+0x34>
cmp    $0x22,%al
jne    11d2 <wordsplit_c_quote_copy+0xa2>
movb   $0x5c,0x0(%rbp)
movzbl (%rbx),%eax
mov    %al,0x1(%rbp)
jmp    11c4 <wordsplit_c_quote_copy+0x94>
nop
movsbl %al,%edi
call   1050 <wordsplit_c_quote_char@plt>
movb   $0x5c,0x0(%rbp)
cmp    $0xffffffff,%eax
je     11e3 <wordsplit_c_quote_copy+0xb3>
mov    %al,0x1(%rbp)
add    $0x2,%rbp
add    $0x1,%rbx
jmp    1194 <wordsplit_c_quote_copy+0x64>
test   %al,%al
je     121b <wordsplit_c_quote_copy+0xeb>
cmp    $0x20,%al
jl     1164 <wordsplit_c_quote_copy+0x34>
mov    %al,0x0(%rbp)
add    $0x1,%rbp
add    $0x1,%rbx
jmp    1194 <wordsplit_c_quote_copy+0x64>
lea    0x1(%rbp),%r15
movzbl (%rbx),%ecx
mov    %r12,%rdi
mov    $0x4,%esi
lea    0xe0e(%rip),%rdx
call   1030 <snprintf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x3,%edx
call   1040 <memcpy@plt>
add    $0x4,%rbp
add    $0x1,%rbx
jmp    1194 <wordsplit_c_quote_copy+0x64>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%%%02X\00"
@.str.1 = [5 x i8] c"%03o\00"
define void @wordsplit_c_quote_copy(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [4 x i8]
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
br label %9
9: ; preds = %90, %3
%10 = load i8*, i8** %5
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %93
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 34
br i1 %17, label %18, label %25
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %4
store i8 92, i8* %19
%21 = load i8*, i8** %5
%22 = load i8, i8* %21
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
store i8 %22, i8* %23
br label %89
25: ; preds = %13
%26 = load i8*, i8** %5
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 9
br i1 %29, label %30, label %50
30: ; preds = %25
%31 = load i8*, i8** %5
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 92
br i1 %34, label %35, label %50
35: ; preds = %30
%36 = load i8*, i8** %5
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ule i32 32, %38
br i1 %39, label %40, label %50
40: ; preds = %35
%41 = load i8*, i8** %5
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ule i32 %43, 127
br i1 %44, label %45, label %50
45: ; preds = %40
%46 = load i8*, i8** %5
%47 = load i8, i8* %46
%48 = load i8*, i8** %4
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %4
store i8 %47, i8* %48
br label %88
50: ; preds = %40, %35, %30, %25
%51 = load i32, i32* %6
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %63
53: ; preds = %50
%54 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%55 = load i8*, i8** %5
%56 = load i8, i8* %55
%57 = call i32 @snprintf(i8* %54, i32 4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %56)
%58 = load i8*, i8** %4
%59 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%60 = call i32 @memcpy(i8* %58, i8* %59, i32 3)
%61 = load i8*, i8** %4
%62 = getelementptr inbounds i8, i8* %61, i64 3
store i8* %62, i8** %4
br label %87
63: ; preds = %50
%64 = load i8*, i8** %5
%65 = load i8, i8* %64
%66 = call i32 @wordsplit_c_quote_char(i8 signext %65)
store i32 %66, i32* %8
%67 = load i8*, i8** %4
%68 = getelementptr inbounds i8, i8* %67, i32 1
store i8* %68, i8** %4
store i8 92, i8* %67
%69 = load i32, i32* %8
%70 = icmp ne i32 %69, -1
br i1 %70, label %71, label %76
71: ; preds = %63
%72 = load i32, i32* %8
%73 = trunc i32 %72 to i8
%74 = load i8*, i8** %4
%75 = getelementptr inbounds i8, i8* %74, i32 1
store i8* %75, i8** %4
store i8 %73, i8* %74
br label %86
76: ; preds = %63
%77 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%78 = load i8*, i8** %5
%79 = load i8, i8* %78
%80 = call i32 @snprintf(i8* %77, i32 4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %79)
%81 = load i8*, i8** %4
%82 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%83 = call i32 @memcpy(i8* %81, i8* %82, i32 3)
%84 = load i8*, i8** %4
%85 = getelementptr inbounds i8, i8* %84, i64 3
store i8* %85, i8** %4
br label %86
86: ; preds = %76, %71
br label %87
87: ; preds = %86, %53
br label %88
88: ; preds = %87, %45
br label %89
89: ; preds = %88, %18
br label %90
90: ; preds = %89
%91 = load i8*, i8** %5
%92 = getelementptr inbounds i8, i8* %91, i32 1
store i8* %92, i8** %5
br label %9
93: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%%%02X\00"
@.str.1 = [5 x i8] c"%03o\00"
define void @wordsplit_c_quote_copy(i8* %0, i8* nocapture %1, i32 %2) {
%4 = alloca [4 x i8]
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%6 = icmp eq i32 %2, 0
br label %7
7: ; preds = %38, %3
%8 = phi i8* [ %1, %3 ], [ %40, %38 ]
%9 = phi i8* [ %0, %3 ], [ %39, %38 ]
%10 = load i8, i8* %8
switch i8 %10, label %15 [
i8 0, label %41
i8 34, label %11
i8 9, label %19
i8 92, label %19
]
11: ; preds = %7
%12 = getelementptr inbounds i8, i8* %9, i64 1
store i8 92, i8* %9
%13 = load i8, i8* %8
%14 = getelementptr inbounds i8, i8* %9, i64 2
store i8 %13, i8* %12
br label %38
15: ; preds = %7
%16 = icmp sgt i8 %10, 31
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = getelementptr inbounds i8, i8* %9, i64 1
store i8 %10, i8* %9
br label %38
19: ; preds = %7, %7, %15
br i1 %6, label %24, label %20
20: ; preds = %19
%21 = call i32 @snprintf(i8* %5, i32 4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %10)
%22 = call i32 @memcpy(i8* %9, i8* %5, i32 3)
%23 = getelementptr inbounds i8, i8* %9, i64 3
br label %36
24: ; preds = %19
%25 = call i32 @wordsplit_c_quote_char(i8 signext %10)
%26 = getelementptr inbounds i8, i8* %9, i64 1
store i8 92, i8* %9
%27 = icmp eq i32 %25, -1
br i1 %27, label %31, label %28
28: ; preds = %24
%29 = trunc i32 %25 to i8
%30 = getelementptr inbounds i8, i8* %9, i64 2
store i8 %29, i8* %26
br label %36
31: ; preds = %24
%32 = load i8, i8* %8
%33 = call i32 @snprintf(i8* %5, i32 4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %32)
%34 = call i32 @memcpy(i8* %26, i8* %5, i32 3)
%35 = getelementptr inbounds i8, i8* %9, i64 4
br label %36
36: ; preds = %28, %31, %20
%37 = phi i8* [ %23, %20 ], [ %30, %28 ], [ %35, %31 ]
br label %38
38: ; preds = %11, %36, %17
%39 = phi i8* [ %14, %11 ], [ %18, %17 ], [ %37, %36 ]
%40 = getelementptr inbounds i8, i8* %8, i64 1
br label %7
41: ; preds = %7
ret void
}