char *ps_string_filter(char *text) {
  static char ps_string[1024];
  char *s = ps_string, c;
  if (text)
    while ((c = *text++)) {
      switch (c) {
      case '(':
      case ')':
      case '\\':
        *s++ = '\\';
        break;
      default:
        break;
      }
      *s++ = c;
    }
  *s++ = 0;
  return ps_string;
}


x86 assembly (clang, -O0):
<ps_string_filter>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
lea    0x2f21(%rip),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11a2 <ps_string_filter+0xa2>
jmp    1123 <ps_string_filter+0x23>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
cmp    $0x0,%al
je     119d <ps_string_filter+0x9d>
movsbl -0x11(%rbp),%eax
mov    %eax,-0x18(%rbp)
add    $0xffffffd8,%eax
sub    $0x2,%eax
jb     1168 <ps_string_filter+0x68>
jmp    1157 <ps_string_filter+0x57>
mov    -0x18(%rbp),%eax
sub    $0x5c,%eax
jne    117f <ps_string_filter+0x7f>
jmp    1168 <ps_string_filter+0x68>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x5c,(%rax)
jmp    1184 <ps_string_filter+0x84>
jmp    1184 <ps_string_filter+0x84>
mov    -0x11(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    1123 <ps_string_filter+0x23>
jmp    11a2 <ps_string_filter+0xa2>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
lea    0x2e75(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ps_string_filter>:
lea    0x2f29(%rip),%rax
test   %rdi,%rdi
je     115b <ps_string_filter+0x5b>
mov    (%rdi),%cl
test   %cl,%cl
je     115b <ps_string_filter+0x5b>
add    $0x1,%rdi
lea    0x2f13(%rip),%rax
movabs $0x10000000000003,%rdx
jmp    1141 <ps_string_filter+0x41>
nopl   0x0(%rax)
mov    %cl,(%rax)
add    $0x1,%rax
movzbl (%rdi),%ecx
add    $0x1,%rdi
test   %cl,%cl
je     115b <ps_string_filter+0x5b>
movsbl %cl,%esi
add    $0xffffffd8,%esi
cmp    $0x34,%esi
ja     1130 <ps_string_filter+0x30>
bt     %rsi,%rdx
jae    1130 <ps_string_filter+0x30>
movb   $0x5c,(%rax)
add    $0x1,%rax
jmp    1130 <ps_string_filter+0x30>
movb   $0x0,(%rax)
lea    0x2ecb(%rip),%rax
ret

LLVM IR (-O0):
@ps_string_filter.ps_string = internal global [1024 x i8] zeroinitializer
define i8* @ps_string_filter(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8
store i8* %0, i8** %2
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @ps_string_filter.ps_string, i64 0, i64 0), i8** %3
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %25
7: ; preds = %1
br label %8
8: ; preds = %20, %7
%9 = load i8*, i8** %2
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %2
%11 = load i8, i8* %9
store i8 %11, i8* %4
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %8
%14 = load i8, i8* %4
%15 = sext i8 %14 to i32
switch i32 %15, label %19 [
i32 40, label %16
i32 41, label %16
i32 92, label %16
]
16: ; preds = %13, %13, %13
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %3
store i8 92, i8* %17
br label %20
19: ; preds = %13
br label %20
20: ; preds = %19, %16
%21 = load i8, i8* %4
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %3
store i8 %21, i8* %22
br label %8
24: ; preds = %8
br label %25
25: ; preds = %24, %1
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %3
store i8 0, i8* %26
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @ps_string_filter.ps_string, i64 0, i64 0)
}

LLVM IR (-O2):
@ps_string_filter.ps_string = internal global [1024 x i8] zeroinitializer
define i8* @ps_string_filter(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %19, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %19, label %6
6: ; preds = %3, %14
%7 = phi i8 [ %17, %14 ], [ %4, %3 ]
%8 = phi i8* [ %10, %14 ], [ %0, %3 ]
%9 = phi i8* [ %16, %14 ], [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @ps_string_filter.ps_string, i64 0, i64 0), %3 ]
%10 = getelementptr inbounds i8, i8* %8, i64 1
%11 = sext i8 %7 to i32
switch i32 %11, label %14 [
i32 40, label %12
i32 41, label %12
i32 92, label %12
]
12: ; preds = %6, %6, %6
%13 = getelementptr inbounds i8, i8* %9, i64 1
store i8 92, i8* %9
br label %14
14: ; preds = %6, %12
%15 = phi i8* [ %9, %6 ], [ %13, %12 ]
%16 = getelementptr inbounds i8, i8* %15, i64 1
store i8 %7, i8* %15
%17 = load i8, i8* %10
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %6
19: ; preds = %14, %3, %1
%20 = phi i8* [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @ps_string_filter.ps_string, i64 0, i64 0), %1 ], [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @ps_string_filter.ps_string, i64 0, i64 0), %3 ], [ %16, %14 ]
store i8 0, i8* %20
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @ps_string_filter.ps_string, i64 0, i64 0)
}