char *pS(char *s) {
  static char buff[1024];
  char *p = buff;
  while (*s != '\0') {
    if (*s == '\\')
      *p++ = '\\';
    *p++ = *s++;
  }
  *p++ = '\0';
  return buff;
}


x86 assembly (clang, -O0):
<pS>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
lea    0x2f21(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     116c <pS+0x6c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    1145 <pS+0x45>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x5c,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    1113 <pS+0x13>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
lea    0x2eab(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<pS>:
lea    0x2f29(%rip),%rax
jmp    1124 <pS+0x24>
nopl   0x0(%rax)
movb   $0x5c,(%rax)
add    $0x1,%rax
movzbl (%rdi),%ecx
add    $0x1,%rdi
mov    %cl,(%rax)
add    $0x1,%rax
movzbl (%rdi),%ecx
cmp    $0x5c,%cl
je     1110 <pS+0x10>
test   %cl,%cl
jne    111a <pS+0x1a>
movb   $0x0,(%rax)
lea    0x2ef6(%rip),%rax
ret

LLVM IR (-O0):
@pS.buff = internal global [1024 x i8] zeroinitializer
define i8* @pS(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @pS.buff, i64 0, i64 0), i8** %3
br label %4
4: ; preds = %17, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %4
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 92
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** %2
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %2
%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 %4
23: ; preds = %4
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %3
store i8 0, i8* %24
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @pS.buff, i64 0, i64 0)
}

LLVM IR (-O2):
@pS.buff = internal global [1024 x i8] zeroinitializer
define i8* @pS(i8* nocapture %0) {
br label %2
2: ; preds = %9, %1
%3 = phi i8* [ %0, %1 ], [ %12, %9 ]
%4 = phi i8* [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @pS.buff, i64 0, i64 0), %1 ], [ %13, %9 ]
%5 = load i8, i8* %3
switch i8 %5, label %9 [
i8 0, label %14
i8 92, label %6
]
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %4, i64 1
store i8 92, i8* %4
%8 = load i8, i8* %3
br label %9
9: ; preds = %2, %6
%10 = phi i8 [ %8, %6 ], [ %5, %2 ]
%11 = phi i8* [ %7, %6 ], [ %4, %2 ]
%12 = getelementptr inbounds i8, i8* %3, i64 1
%13 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %10, i8* %11
br label %2
14: ; preds = %2
store i8 0, i8* %4
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @pS.buff, i64 0, i64 0)
}