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


x86 assembly (clang, -O0):
<escape_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1278 <escape_copy+0x138>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    1196 <escape_copy+0x56>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x22,(%rax)
jmp    1262 <escape_copy+0x122>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
je     11d8 <escape_copy+0x98>
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
je     11d8 <escape_copy+0x98>
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    125d <escape_copy+0x11d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1060 <argcv_escape_char@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
cmpl   $0xffffffff,-0x14(%rbp)
je     121e <escape_copy+0xde>
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    1258 <escape_copy+0x118>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    $0x4,%esi
lea    0xdce(%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    125d <escape_copy+0x11d>
jmp    1262 <escape_copy+0x122>
jmp    1267 <escape_copy+0x127>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1150 <escape_copy+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escape_copy>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xea6(%rip),%r15
lea    0xc(%rsp),%r12
jmp    117e <escape_copy+0x3e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movw   $0x225c,(%r14)
add    $0x2,%r14
add    $0x1,%rbx
movzbl (%rbx),%ecx
cmp    $0x9,%cl
je     11b0 <escape_copy+0x70>
cmp    $0x22,%cl
je     1170 <escape_copy+0x30>
test   %cl,%cl
je     11f8 <escape_copy+0xb8>
movzbl %cl,%edi
call   1050 <isprint@plt>
movzbl (%rbx),%ecx
test   %rax,%rax
je     11b0 <escape_copy+0x70>
mov    %cl,(%r14)
add    $0x1,%r14
add    $0x1,%rbx
jmp    117e <escape_copy+0x3e>
nopl   0x0(%rax)
movsbl %cl,%edi
call   1060 <argcv_escape_char@plt>
movb   $0x5c,(%r14)
cmp    $0xffffffff,%eax
je     11c7 <escape_copy+0x87>
mov    %al,0x1(%r14)
jmp    1176 <escape_copy+0x36>
lea    0x1(%r14),%r13
movzbl (%rbx),%ecx
mov    %r12,%rdi
mov    $0x4,%esi
mov    %r15,%rdx
call   1030 <snprintf@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    $0x3,%edx
call   1040 <memcpy@plt>
add    $0x4,%r14
add    $0x1,%rbx
jmp    117e <escape_copy+0x3e>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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