#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ memmove(char *, char *, scalar_t__);
char *strchr(char *, char);
scalar_t__ strlen(char *);
int remove_dots_from_uri_path(char *path) {
  if (!path || !*path)
    return 0;
  if (*path != '/')
    return -1;
  while (1) {
    if (path[1] == '.' && path[2] == '.' &&
        (path[3] == '/' || path[3] == '\0')) {
      memmove(path, path + 3, strlen(path + 3) + 1);
      return 1;
    } else {
      char *p1 = strchr(path + 1, '/');
      if (!p1)
        return 0;
      if (!remove_dots_from_uri_path(p1))
        return 0;
      memmove(path, p1, strlen(p1) + 1);
    }
  }
}


x86 assembly (clang, -O0):
<remove_dots_from_uri_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1164 <remove_dots_from_uri_path+0x24>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1170 <remove_dots_from_uri_path+0x30>
movl   $0x0,-0x4(%rbp)
jmp    1293 <remove_dots_from_uri_path+0x153>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     118c <remove_dots_from_uri_path+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1293 <remove_dots_from_uri_path+0x153>
jmp    1191 <remove_dots_from_uri_path+0x51>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2e,%eax
jne    1216 <remove_dots_from_uri_path+0xd6>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x2e,%eax
jne    1216 <remove_dots_from_uri_path+0xd6>
mov    -0x10(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x2f,%eax
je     11d5 <remove_dots_from_uri_path+0x95>
mov    -0x10(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x0,%eax
jne    1216 <remove_dots_from_uri_path+0xd6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x3,%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1060 <memmove@plt>
movl   $0x1,-0x4(%rbp)
jmp    1293 <remove_dots_from_uri_path+0x153>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1243 <remove_dots_from_uri_path+0x103>
movl   $0x0,-0x4(%rbp)
jmp    1293 <remove_dots_from_uri_path+0x153>
mov    -0x18(%rbp),%rdi
call   1030 <remove_dots_from_uri_path@plt>
cmp    $0x0,%eax
jne    1261 <remove_dots_from_uri_path+0x121>
movl   $0x0,-0x4(%rbp)
jmp    1293 <remove_dots_from_uri_path+0x153>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1060 <memmove@plt>
jmp    1191 <remove_dots_from_uri_path+0x51>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_dots_from_uri_path>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %r15d,%r15d
test   %rdi,%rdi
je     11c9 <remove_dots_from_uri_path+0x89>
mov    %rdi,%r12
mov    (%rdi),%al
test   %al,%al
je     11c9 <remove_dots_from_uri_path+0x89>
cmp    $0x2f,%al
jne    11c3 <remove_dots_from_uri_path+0x83>
lea    0x1(%r12),%rbp
lea    0x3(%r12),%r14
cmpb   $0x2e,0x0(%rbp)
jne    1183 <remove_dots_from_uri_path+0x43>
nopl   (%rax)
cmpb   $0x2e,0x2(%r12)
jne    1183 <remove_dots_from_uri_path+0x43>
mov    (%r14),%al
cmp    $0x2f,%al
je     11d5 <remove_dots_from_uri_path+0x95>
test   %al,%al
je     11d5 <remove_dots_from_uri_path+0x95>
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11c9 <remove_dots_from_uri_path+0x89>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <remove_dots_from_uri_path@plt>
test   %eax,%eax
je     11c9 <remove_dots_from_uri_path+0x89>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <memmove@plt>
cmpb   $0x2e,0x0(%rbp)
je     1170 <remove_dots_from_uri_path+0x30>
jmp    1183 <remove_dots_from_uri_path+0x43>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <memmove@plt>
mov    $0x1,%r15d
jmp    11c9 <remove_dots_from_uri_path+0x89>

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

LLVM IR (-O2):
define i32 @remove_dots_from_uri_path(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %32, label %3
3: ; preds = %1
%4 = load i8, i8* %0
switch i8 %4, label %9 [
i8 0, label %32
i8 47, label %5
]
5: ; preds = %3
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = getelementptr inbounds i8, i8* %0, i64 2
%8 = getelementptr inbounds i8, i8* %0, i64 3
br label %10
9: ; preds = %3
br label %32
10: ; preds = %5, %28
%11 = load i8, i8* %6
%12 = icmp eq i8 %11, 46
br i1 %12, label %13, label %22
13: ; preds = %10
%14 = load i8, i8* %7
%15 = icmp eq i8 %14, 46
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = load i8, i8* %8
switch i8 %17, label %22 [
i8 47, label %18
i8 0, label %18
]
18: ; preds = %16, %16
%19 = tail call i64 @strlen(i8* %8)
%20 = add nsw i64 %19, 1
%21 = tail call i32 @memmove(i8* %0, i8* %8, i64 %20)
br label %32
22: ; preds = %16, %13, %10
%23 = tail call i8* @strchr(i8* %6, i8 signext 47)
%24 = icmp eq i8* %23, null
br i1 %24, label %32, label %25
25: ; preds = %22
%26 = tail call i32 @remove_dots_from_uri_path(i8* %23)
%27 = icmp eq i32 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %25
%29 = tail call i64 @strlen(i8* %23)
%30 = add nsw i64 %29, 1
%31 = tail call i32 @memmove(i8* %0, i8* %23, i64 %30)
br label %10
32: ; preds = %25, %22, %3, %1, %18, %9
%33 = phi i32 [ -1, %9 ], [ 1, %18 ], [ 0, %3 ], [ 0, %1 ], [ 0, %22 ], [ 0, %25 ]
ret i32 %33
}