void remove_double_dots_and_double_slashes(char *s) {
  char *p = s;
  while (*s != '\0') {
    *p++ = *s++;
    if (s[-1] == '/' || s[-1] == '\\') {
      while (s[0] != '\0') {
        if (s[0] == '/' || s[0] == '\\') {
          s++;
        } else if (s[0] == '.' && s[1] == '.') {
          s += 2;
        } else {
          break;
        }
      }
    }
  }
  *p = '\0';
}


x86 assembly (clang, -O0):
<remove_double_dots_and_double_slashes>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f5 <remove_double_dots_and_double_slashes+0xf5>
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)
mov    -0x8(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x2f,%eax
je     1164 <remove_double_dots_and_double_slashes+0x64>
mov    -0x8(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x5c,%eax
jne    11f0 <remove_double_dots_and_double_slashes+0xf0>
jmp    1169 <remove_double_dots_and_double_slashes+0x69>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11eb <remove_double_dots_and_double_slashes+0xeb>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1199 <remove_double_dots_and_double_slashes+0x99>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11aa <remove_double_dots_and_double_slashes+0xaa>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11e6 <remove_double_dots_and_double_slashes+0xe6>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11dc <remove_double_dots_and_double_slashes+0xdc>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2e,%eax
jne    11dc <remove_double_dots_and_double_slashes+0xdc>
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
jmp    11e1 <remove_double_dots_and_double_slashes+0xe1>
jmp    11eb <remove_double_dots_and_double_slashes+0xeb>
jmp    11e6 <remove_double_dots_and_double_slashes+0xe6>
jmp    1169 <remove_double_dots_and_double_slashes+0x69>
jmp    11f0 <remove_double_dots_and_double_slashes+0xf0>
jmp    1110 <remove_double_dots_and_double_slashes+0x10>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_double_dots_and_double_slashes>:
mov    (%rdi),%cl
test   %cl,%cl
je     1159 <remove_double_dots_and_double_slashes+0x59>
mov    %rdi,%rax
jmp    111a <remove_double_dots_and_double_slashes+0x1a>
nopl   0x0(%rax,%rax,1)
mov    (%rax),%cl
add    $0x1,%rdi
test   %cl,%cl
je     1159 <remove_double_dots_and_double_slashes+0x59>
mov    %cl,(%rdi)
mov    (%rax),%cl
add    $0x1,%rax
cmp    $0x5c,%cl
je     1133 <remove_double_dots_and_double_slashes+0x33>
cmp    $0x2f,%cl
je     1133 <remove_double_dots_and_double_slashes+0x33>
jmp    1110 <remove_double_dots_and_double_slashes+0x10>
xchg   %ax,%ax
add    %rdx,%rax
movzbl (%rax),%ecx
mov    $0x1,%edx
cmp    $0x5c,%cl
je     1130 <remove_double_dots_and_double_slashes+0x30>
cmp    $0x2f,%cl
je     1130 <remove_double_dots_and_double_slashes+0x30>
cmp    $0x2e,%cl
jne    1112 <remove_double_dots_and_double_slashes+0x12>
mov    $0x2,%edx
cmpb   $0x2e,0x1(%rax)
je     1130 <remove_double_dots_and_double_slashes+0x30>
mov    $0x2e,%cl
jmp    1112 <remove_double_dots_and_double_slashes+0x12>
movb   $0x0,(%rdi)
ret

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

LLVM IR (-O2):
define void @remove_double_dots_and_double_slashes(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %28, label %4
4: ; preds = %1, %24
%5 = phi i8 [ %25, %24 ], [ %2, %1 ]
%6 = phi i8* [ %9, %24 ], [ %0, %1 ]
%7 = phi i8* [ %26, %24 ], [ %0, %1 ]
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %5, i8* %6
%10 = load i8, i8* %7
switch i8 %10, label %12 [
i8 47, label %11
i8 92, label %11
]
11: ; preds = %4, %4
br label %14
12: ; preds = %4
%13 = load i8, i8* %8
br label %24
14: ; preds = %11, %21
%15 = phi i8* [ %23, %21 ], [ %8, %11 ]
%16 = load i8, i8* %15
switch i8 %16, label %24 [
i8 46, label %17
i8 47, label %21
i8 92, label %21
]
17: ; preds = %14
%18 = getelementptr inbounds i8, i8* %15, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 46
br i1 %20, label %21, label %24
21: ; preds = %17, %14, %14
%22 = phi i64 [ 1, %14 ], [ 1, %14 ], [ 2, %17 ]
%23 = getelementptr inbounds i8, i8* %15, i64 %22
br label %14
24: ; preds = %14, %17, %12
%25 = phi i8 [ %13, %12 ], [ %16, %14 ], [ 46, %17 ]
%26 = phi i8* [ %8, %12 ], [ %15, %17 ], [ %15, %14 ]
%27 = icmp eq i8 %25, 0
br i1 %27, label %28, label %4
28: ; preds = %24, %1
%29 = phi i8* [ %0, %1 ], [ %9, %24 ]
store i8 0, i8* %29
ret void
}