int basic_sanitize(char *str) {
  if (!str)
    return -1;
  while (*str) {
    switch (*str) {
    case '\\':
    case '\'':
    case '`':
    case '"':
    case '%':
      *str = ' ';
    }
    str++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<basic_sanitize>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    111f <basic_sanitize+0x1f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <basic_sanitize+0xac>
jmp    1124 <basic_sanitize+0x24>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11a5 <basic_sanitize+0xa5>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
sub    $0x22,%eax
je     118d <basic_sanitize+0x8d>
jmp    1149 <basic_sanitize+0x49>
mov    -0x14(%rbp),%eax
sub    $0x25,%eax
je     118d <basic_sanitize+0x8d>
jmp    115a <basic_sanitize+0x5a>
mov    -0x14(%rbp),%eax
sub    $0x27,%eax
je     118d <basic_sanitize+0x8d>
jmp    116b <basic_sanitize+0x6b>
mov    -0x14(%rbp),%eax
sub    $0x5c,%eax
je     118d <basic_sanitize+0x8d>
jmp    117c <basic_sanitize+0x7c>
mov    -0x14(%rbp),%eax
sub    $0x60,%eax
jne    1194 <basic_sanitize+0x94>
jmp    118d <basic_sanitize+0x8d>
mov    -0x10(%rbp),%rax
movb   $0x20,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1124 <basic_sanitize+0x24>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<basic_sanitize>:
test   %rdi,%rdi
je     1143 <basic_sanitize+0x43>
mov    (%rdi),%dl
xor    %eax,%eax
test   %dl,%dl
je     1142 <basic_sanitize+0x42>
add    $0x1,%rdi
movabs $0x4400000000000029,%rcx
jmp    112b <basic_sanitize+0x2b>
nopl   (%rax)
movzbl (%rdi),%edx
add    $0x1,%rdi
test   %dl,%dl
je     1142 <basic_sanitize+0x42>
movsbl %dl,%edx
add    $0xffffffde,%edx
cmp    $0x3e,%edx
ja     1120 <basic_sanitize+0x20>
bt     %rdx,%rcx
jae    1120 <basic_sanitize+0x20>
movb   $0x20,-0x1(%rdi)
jmp    1120 <basic_sanitize+0x20>
ret
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
define i32 @basic_sanitize(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = icmp ne i8* %4, null
br i1 %5, label %7, label %6
6: ; preds = %1
store i32 -1, i32* %2
br label %22
7: ; preds = %1
br label %8
8: ; preds = %18, %7
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
switch i32 %15, label %18 [
i32 92, label %16
i32 39, label %16
i32 96, label %16
i32 34, label %16
i32 37, label %16
]
16: ; preds = %12, %12, %12, %12, %12
%17 = load i8*, i8** %3
store i8 32, i8* %17
br label %18
18: ; preds = %16, %12
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %3
br label %8
21: ; preds = %8
store i32 0, i32* %2
br label %22
22: ; preds = %21, %6
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
define i32 @basic_sanitize(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %15, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %3, %11
%7 = phi i8 [ %13, %11 ], [ %4, %3 ]
%8 = phi i8* [ %12, %11 ], [ %0, %3 ]
%9 = sext i8 %7 to i32
switch i32 %9, label %11 [
i32 92, label %10
i32 39, label %10
i32 96, label %10
i32 34, label %10
i32 37, label %10
]
10: ; preds = %6, %6, %6, %6, %6
store i8 32, i8* %8
br label %11
11: ; preds = %10, %6
%12 = getelementptr inbounds i8, i8* %8, i64 1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %6
15: ; preds = %11, %3, %1
%16 = phi i32 [ -1, %1 ], [ 0, %3 ], [ 0, %11 ]
ret i32 %16
}