#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 */
scalar_t__ strchr(char *, char const);
void StrCp(char *dest, const char *src) {
  static char esc_chars[] = "#*|&;()<> \t\n\r\"!$?'`~";
  while (*src) {
    if (strchr(esc_chars, *src))
      *dest++ = '\\';
    *dest++ = *src++;
  }
  *dest = '\0';
}


x86 assembly (clang, -O0):
<StrCp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1183 <StrCp+0x73>
mov    -0x10(%rbp),%rax
lea    0x2ef8(%rip),%rdi
movsbl (%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     115c <StrCp+0x4c>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    1120 <StrCp+0x10>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StrCp>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    (%rsi),%al
test   %al,%al
je     1160 <StrCp+0x50>
mov    %rsi,%r14
add    $0x1,%r14
lea    0x2f04(%rip),%r15
jmp    1147 <StrCp+0x37>
xchg   %ax,%ax
movzbl -0x1(%r14),%eax
mov    %al,(%rbx)
add    $0x1,%rbx
movzbl (%r14),%eax
add    $0x1,%r14
test   %al,%al
je     1160 <StrCp+0x50>
movsbl %al,%esi
mov    %r15,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
je     1130 <StrCp+0x20>
movb   $0x5c,(%rbx)
add    $0x1,%rbx
jmp    1130 <StrCp+0x20>
movb   $0x0,(%rbx)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@StrCp.esc_chars = internal global [21 x i8] c"#*|&;()<> \09\0A\0D\22!$?'`~\00"
define void @StrCp(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
br label %5
5: ; preds = %17, %2
%6 = load i8*, i8** %4
%7 = load i8, i8* %6
%8 = icmp ne i8 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %5
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = call i64 @strchr(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @StrCp.esc_chars, i64 0, i64 0), i8 signext %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %3
store i8 92, i8* %15
br label %17
17: ; preds = %14, %9
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %4
%20 = load i8, i8* %18
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %3
store i8 %20, i8* %21
br label %5
23: ; preds = %5
%24 = load i8*, i8** %3
store i8 0, i8* %24
ret void
}

LLVM IR (-O2):
@StrCp.esc_chars = internal global [21 x i8] c"#*|&;()<> \09\0A\0D\22!$?'`~\00"
define void @StrCp(i8* nocapture writeonly %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %20, label %5
5: ; preds = %2, %13
%6 = phi i8 [ %18, %13 ], [ %3, %2 ]
%7 = phi i8* [ %15, %13 ], [ %1, %2 ]
%8 = phi i8* [ %17, %13 ], [ %0, %2 ]
%9 = tail call i64 @strchr(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @StrCp.esc_chars, i64 0, i64 0), i8 signext %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %5
%12 = getelementptr inbounds i8, i8* %8, i64 1
store i8 92, i8* %8
br label %13
13: ; preds = %11, %5
%14 = phi i8* [ %12, %11 ], [ %8, %5 ]
%15 = getelementptr inbounds i8, i8* %7, i64 1
%16 = load i8, i8* %7
%17 = getelementptr inbounds i8, i8* %14, i64 1
store i8 %16, i8* %14
%18 = load i8, i8* %15
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %5
20: ; preds = %13, %2
%21 = phi i8* [ %0, %2 ], [ %17, %13 ]
store i8 0, i8* %21
ret void
}