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


x86 assembly (clang, -O0):
<remove_double_dots>:
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     11a8 <remove_double_dots+0xa8>
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
jne    11a3 <remove_double_dots+0xa3>
jmp    1158 <remove_double_dots+0x58>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x2e,%ecx
mov    %al,-0x11(%rbp)
je     117d <remove_double_dots+0x7d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    118d <remove_double_dots+0x8d>
jmp    119e <remove_double_dots+0x9e>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1158 <remove_double_dots+0x58>
jmp    11a3 <remove_double_dots+0xa3>
jmp    1110 <remove_double_dots+0x10>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_double_dots>:
mov    (%rdi),%cl
test   %cl,%cl
je     1144 <remove_double_dots+0x44>
mov    %rdi,%rax
jmp    111e <remove_double_dots+0x1e>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rax
mov    (%rax),%cl
add    $0x1,%rdi
test   %cl,%cl
je     1144 <remove_double_dots+0x44>
mov    %cl,(%rdi)
cmpb   $0x2f,(%rax)
jne    1110 <remove_double_dots+0x10>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x1(%rax),%ecx
add    $0x1,%rax
mov    %ecx,%edx
and    $0xfe,%dl
cmp    $0x2e,%dl
je     1130 <remove_double_dots+0x30>
jmp    1116 <remove_double_dots+0x16>
movb   $0x0,(%rdi)
ret

LLVM IR (-O0):
define void @remove_double_dots(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 = %38, %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 %39
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 %21, label %38
21: ; preds = %10
br label %22
22: ; preds = %34, %21
%23 = load i8*, i8** %2
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 46
br i1 %26, label %32, 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 label %32
32: ; preds = %27, %22
%33 = phi i1 [ true, %22 ], [ %31, %27 ]
br i1 %33, label %34, label %37
34: ; preds = %32
%35 = load i8*, i8** %2
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %2
br label %22
37: ; preds = %32
br label %38
38: ; preds = %37, %10
br label %5
39: ; preds = %5
%40 = load i8*, i8** %3
store i8 0, i8* %40
ret void
}

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