void lws_filename_purify_inplace(char *filename) {
  while (*filename) {
    if (*filename == '.' && filename[1] == '.') {
      *filename = '_';
      filename[1] = '_';
    }
    if (*filename == ':' || *filename == '/' || *filename == '\\' ||
        *filename == '$' || *filename == '%')
      *filename = '_';
    filename++;
  }
}


x86 assembly (clang, -O0):
<lws_filename_purify_inplace>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ad <lws_filename_purify_inplace+0xad>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1145 <lws_filename_purify_inplace+0x45>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2e,%eax
jne    1145 <lws_filename_purify_inplace+0x45>
mov    -0x8(%rbp),%rax
movb   $0x5f,(%rax)
mov    -0x8(%rbp),%rax
movb   $0x5f,0x1(%rax)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
je     1195 <lws_filename_purify_inplace+0x95>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1195 <lws_filename_purify_inplace+0x95>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
je     1195 <lws_filename_purify_inplace+0x95>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x24,%eax
je     1195 <lws_filename_purify_inplace+0x95>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    119c <lws_filename_purify_inplace+0x9c>
mov    -0x8(%rbp),%rax
movb   $0x5f,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1108 <lws_filename_purify_inplace+0x8>
pop    %rbp
ret

x86 assembly (clang, -O2):
<lws_filename_purify_inplace>:
movabs $0x100000000400803,%rax
jmp    1117 <lws_filename_purify_inplace+0x17>
nopl   0x0(%rax)
movb   $0x5f,(%rdx)
add    $0x1,%rdi
movzbl (%rdi),%ecx
lea    -0x24(%rcx),%edx
cmp    $0x38,%dl
ja     1143 <lws_filename_purify_inplace+0x43>
movzbl %dl,%esi
bt     %rsi,%rax
mov    %rdi,%rdx
jb     1110 <lws_filename_purify_inplace+0x10>
cmp    $0xa,%rsi
jne    1143 <lws_filename_purify_inplace+0x43>
cmpb   $0x2e,0x1(%rdi)
jne    1113 <lws_filename_purify_inplace+0x13>
lea    0x1(%rdi),%rdx
movb   $0x5f,(%rdi)
jmp    1110 <lws_filename_purify_inplace+0x10>
test   %cl,%cl
jne    1113 <lws_filename_purify_inplace+0x13>
ret

LLVM IR (-O0):
define void @lws_filename_purify_inplace(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
br label %3
3: ; preds = %49, %1
%4 = load i8*, i8** %2
%5 = load i8, i8* %4
%6 = icmp ne i8 %5, 0
br i1 %6, label %7, label %52
7: ; preds = %3
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 46
br i1 %11, label %12, label %22
12: ; preds = %7
%13 = load i8*, i8** %2
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 46
br i1 %17, label %18, label %22
18: ; preds = %12
%19 = load i8*, i8** %2
store i8 95, i8* %19
%20 = load i8*, i8** %2
%21 = getelementptr inbounds i8, i8* %20, i64 1
store i8 95, i8* %21
br label %22
22: ; preds = %18, %12, %7
%23 = load i8*, i8** %2
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 58
br i1 %26, label %47, label %27
27: ; preds = %22
%28 = load i8*, i8** %2
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 47
br i1 %31, label %47, label %32
32: ; preds = %27
%33 = load i8*, i8** %2
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 92
br i1 %36, label %47, label %37
37: ; preds = %32
%38 = load i8*, i8** %2
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 36
br i1 %41, label %47, label %42
42: ; preds = %37
%43 = load i8*, i8** %2
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 37
br i1 %46, label %47, label %49
47: ; preds = %42, %37, %32, %27, %22
%48 = load i8*, i8** %2
store i8 95, i8* %48
br label %49
49: ; preds = %47, %42
%50 = load i8*, i8** %2
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %2
br label %3
52: ; preds = %3
ret void
}

LLVM IR (-O2):
define void @lws_filename_purify_inplace(i8* nocapture %0) {
br label %2
2: ; preds = %12, %1
%3 = phi i8* [ %0, %1 ], [ %13, %12 ]
%4 = load i8, i8* %3
switch i8 %4, label %12 [
i8 0, label %14
i8 46, label %5
i8 58, label %10
i8 47, label %10
i8 92, label %10
i8 36, label %10
i8 37, label %10
]
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %3, i64 1
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 46
br i1 %8, label %9, label %12
9: ; preds = %5
store i8 95, i8* %3
br label %10
10: ; preds = %2, %2, %2, %2, %2, %9
%11 = phi i8* [ %6, %9 ], [ %3, %2 ], [ %3, %2 ], [ %3, %2 ], [ %3, %2 ], [ %3, %2 ]
store i8 95, i8* %11
br label %12
12: ; preds = %10, %2, %5
%13 = getelementptr inbounds i8, i8* %3, i64 1
br label %2
14: ; preds = %2
ret void
}