void CleanUpFileName(char *src, char *dst, int len) {
  while (*src) {
    if (--len <= 0)
      break;
    switch (*src & 0x7f) {
    case '/':
      *dst++ = '_';
      break;
    case '-':
      *dst++ = '.';
      break;
    default:
      *dst++ = (*src & 0x7f);
    }
    ++src;
  }
  *dst = '\0';
}


x86 assembly (clang, -O0):
<CleanUpFileName>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11bb <CleanUpFileName+0xbb>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jg     1133 <CleanUpFileName+0x33>
jmp    11bb <CleanUpFileName+0xbb>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
and    $0x7f,%eax
mov    %eax,-0x18(%rbp)
sub    $0x2d,%eax
je     1176 <CleanUpFileName+0x76>
jmp    114e <CleanUpFileName+0x4e>
mov    -0x18(%rbp),%eax
sub    $0x2f,%eax
jne    118d <CleanUpFileName+0x8d>
jmp    115f <CleanUpFileName+0x5f>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x5f,(%rax)
jmp    11aa <CleanUpFileName+0xaa>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x2e,(%rax)
jmp    11aa <CleanUpFileName+0xaa>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
and    $0x7f,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    110f <CleanUpFileName+0xf>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<CleanUpFileName>:
mov    (%rdi),%al
test   %al,%al
je     113d <CleanUpFileName+0x3d>
add    $0x1,%rdi
jmp    1126 <CleanUpFileName+0x26>
nopl   0x0(%rax)
mov    $0x5f,%al
mov    %al,(%rsi)
add    $0x1,%rsi
movzbl (%rdi),%eax
add    $0x1,%rdi
add    $0xffffffff,%edx
test   %al,%al
je     113d <CleanUpFileName+0x3d>
cmp    $0x2,%edx
jl     113d <CleanUpFileName+0x3d>
and    $0x7f,%al
cmp    $0x2f,%al
je     1110 <CleanUpFileName+0x10>
movzbl %al,%ecx
cmp    $0x2d,%ecx
jne    1112 <CleanUpFileName+0x12>
mov    $0x2e,%al
jmp    1112 <CleanUpFileName+0x12>
movb   $0x0,(%rsi)
ret

LLVM IR (-O0):
define void @CleanUpFileName(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
br label %7
7: ; preds = %35, %3
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %38
11: ; preds = %7
%12 = load i32, i32* %6
%13 = add nsw i32 %12, -1
store i32 %13, i32* %6
%14 = icmp sle i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
br label %38
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = and i32 %19, 127
switch i32 %20, label %27 [
i32 47, label %21
i32 45, label %24
]
21: ; preds = %16
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %5
store i8 95, i8* %22
br label %35
24: ; preds = %16
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %5
store i8 46, i8* %25
br label %35
27: ; preds = %16
%28 = load i8*, i8** %4
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = and i32 %30, 127
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %5
store i8 %32, i8* %33
br label %35
35: ; preds = %27, %24, %21
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %4
br label %7
38: ; preds = %15, %7
%39 = load i8*, i8** %5
store i8 0, i8* %39
ret void
}

LLVM IR (-O2):
define void @CleanUpFileName(i8* nocapture %0, i8* nocapture writeonly %1, i32 %2) {
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %24, label %6
6: ; preds = %3, %18
%7 = phi i8 [ %22, %18 ], [ %4, %3 ]
%8 = phi i32 [ %11, %18 ], [ %2, %3 ]
%9 = phi i8* [ %20, %18 ], [ %1, %3 ]
%10 = phi i8* [ %21, %18 ], [ %0, %3 ]
%11 = add nsw i32 %8, -1
%12 = icmp slt i32 %8, 2
br i1 %12, label %24, label %13
13: ; preds = %6
%14 = and i8 %7, 127
%15 = zext i8 %14 to i32
switch i32 %15, label %17 [
i32 47, label %18
i32 45, label %16
]
16: ; preds = %13
br label %18
17: ; preds = %13
br label %18
18: ; preds = %13, %17, %16
%19 = phi i8 [ %14, %17 ], [ 46, %16 ], [ 95, %13 ]
store i8 %19, i8* %9
%20 = getelementptr inbounds i8, i8* %9, i64 1
%21 = getelementptr inbounds i8, i8* %10, i64 1
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %6
24: ; preds = %18, %6, %3
%25 = phi i8* [ %1, %3 ], [ %9, %6 ], [ %20, %18 ]
store i8 0, i8* %25
ret void
}