char *has_double_dots(path)
char *path;
{
  char *dots = 0;
  char *s = path;
  char *p;
  while (1) {
    p = strstr(s, "..");
    if (!p || *(p - 1) == '/' && ((*(p + 2) == '\0' || *(p + 2) == '/'))) {
      dots = p;
      break;
    }
    s = p + 2;
  }
  return dots;
}


x86 assembly (clang, -O0):
<has_double_dots>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xec9(%rip),%rsi
call   1030 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     117e <has_double_dots+0x6e>
mov    -0x20(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x2f,%eax
jne    118b <has_double_dots+0x7b>
mov    -0x20(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x0,%eax
je     117e <has_double_dots+0x6e>
mov    -0x20(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x2f,%eax
jne    118b <has_double_dots+0x7b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    119c <has_double_dots+0x8c>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
jmp    112c <has_double_dots+0x1c>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<has_double_dots>:
push   %rbx
lea    0xee8(%rip),%rsi
call   1030 <strstr@plt>
test   %rax,%rax
je     1159 <has_double_dots+0x49>
lea    0xed7(%rip),%rbx
jmp    1144 <has_double_dots+0x34>
nopl   0x0(%rax,%rax,1)
add    $0x2,%rax
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strstr@plt>
test   %rax,%rax
je     1159 <has_double_dots+0x49>
cmpb   $0x2f,-0x1(%rax)
jne    1130 <has_double_dots+0x20>
movzbl 0x2(%rax),%ecx
cmp    $0x2f,%cl
je     1157 <has_double_dots+0x47>
test   %cl,%cl
jne    1130 <has_double_dots+0x20>
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"..\00"
define i8* @has_double_dots(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %3
%6 = load i8*, i8** %2
store i8* %6, i8** %4
br label %7
7: ; preds = %1, %32
%8 = load i8*, i8** %4
%9 = call i8* @strstr(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %30
12: ; preds = %7
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i64 -1
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 47
br i1 %17, label %18, label %32
18: ; preds = %12
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 2
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %18
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i64 2
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 47
br i1 %29, label %30, label %32
30: ; preds = %24, %18, %7
%31 = load i8*, i8** %5
store i8* %31, i8** %3
br label %35
32: ; preds = %24, %12
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i64 2
store i8* %34, i8** %4
br label %7
35: ; preds = %30
%36 = load i8*, i8** %3
ret i8* %36
}

LLVM IR (-O2):
@.str = [3 x i8] c"..\00"
define i8* @has_double_dots(i8* %0) {
%2 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %12, label %4
4: ; preds = %1, %14
%5 = phi i8* [ %16, %14 ], [ %2, %1 ]
%6 = getelementptr inbounds i8, i8* %5, i64 -1
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 47
br i1 %8, label %9, label %14
9: ; preds = %4
%10 = getelementptr inbounds i8, i8* %5, i64 2
%11 = load i8, i8* %10
switch i8 %11, label %14 [
i8 0, label %12
i8 47, label %12
]
12: ; preds = %14, %9, %9, %1
%13 = phi i8* [ null, %1 ], [ %5, %9 ], [ %5, %9 ], [ null, %14 ]
ret i8* %13
14: ; preds = %9, %4
%15 = getelementptr inbounds i8, i8* %5, i64 2
%16 = tail call i8* @strstr(i8* dereferenceable(1) %15, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %12, label %4
}