#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__);
int /*<<< orphan*/ sp_fix_slash_repeated(char *);
int /*<<< orphan*/ sp_make_system_slash(char *);
scalar_t__ strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *sp_fix_p_cdpp(char *path) {
  char *p = path;
  sp_make_system_slash(path);
  sp_fix_slash_repeated(path);
  while (1) {
    if (!*p)
      break;
    if ((*p == '/'))
      p++;
    if (!*p)
      break;
    if ((strncmp(p,
                 ".."
                 "/",
                 3) == 0 ||
         strncmp(p, "..", 3) == 0)) {
      char *old_p = p - 2;
      if (p == path || (p == path + 1 && *path == '/')) {
        memmove(p, p + 3, strlen(p + 3) + 1);
        continue;
      }
      while (old_p != path && !(*old_p == '/'))
        old_p--;
      if (old_p != p) {
        memmove(old_p, p + 2, strlen(p + 2) + 1);
        p = old_p;
      }
      continue;
    } else if (strncmp(p,
                       "."
                       "/",
                       2) == 0 ||
               strncmp(p, ".", 2) == 0) {
      memmove(p, p + 2, strlen(p + 2) + 1);
      continue;
    }
    p++;
  }
  return path;
}


x86 assembly (clang, -O0):
<sp_fix_p_cdpp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <sp_make_system_slash@plt>
mov    -0x8(%rbp),%rdi
call   1030 <sp_fix_slash_repeated@plt>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1188 <sp_fix_p_cdpp+0x38>
jmp    1396 <sp_fix_p_cdpp+0x246>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11a4 <sp_fix_p_cdpp+0x54>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11b6 <sp_fix_p_cdpp+0x66>
jmp    1396 <sp_fix_p_cdpp+0x246>
mov    -0x10(%rbp),%rdi
lea    0xe3f(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     11f4 <sp_fix_p_cdpp+0xa4>
mov    -0x10(%rbp),%rdi
lea    0xe24(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1308 <sp_fix_p_cdpp+0x1b8>
mov    -0x10(%rbp),%rax
add    $0xfffffffffffffffe,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     1233 <sp_fix_p_cdpp+0xe3>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
jne    126d <sp_fix_p_cdpp+0x11d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    126d <sp_fix_p_cdpp+0x11d>
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   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1060 <memmove@plt>
jmp    1176 <sp_fix_p_cdpp+0x26>
jmp    1272 <sp_fix_p_cdpp+0x122>
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x29(%rbp)
je     1297 <sp_fix_p_cdpp+0x147>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
sete   %al
xor    $0xff,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    12a7 <sp_fix_p_cdpp+0x157>
jmp    12b8 <sp_fix_p_cdpp+0x168>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1272 <sp_fix_p_cdpp+0x122>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1303 <sp_fix_p_cdpp+0x1b3>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1060 <memmove@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1176 <sp_fix_p_cdpp+0x26>
mov    -0x10(%rbp),%rdi
lea    0xcee(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1346 <sp_fix_p_cdpp+0x1f6>
mov    -0x10(%rbp),%rdi
lea    0xcd3(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1380 <sp_fix_p_cdpp+0x230>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1060 <memmove@plt>
jmp    1176 <sp_fix_p_cdpp+0x26>
jmp    1385 <sp_fix_p_cdpp+0x235>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1176 <sp_fix_p_cdpp+0x26>
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sp_fix_p_cdpp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
call   1070 <sp_make_system_slash@plt>
mov    %r13,%rdi
call   1030 <sp_fix_slash_repeated@plt>
xor    %r15d,%r15d
lea    0xe8b(%rip),%r14
jmp    119b <sp_fix_p_cdpp+0x4b>
nopw   0x0(%rax,%rax,1)
lea    0x3(%rbp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1060 <memmove@plt>
mov    0x0(%r13,%r15,1),%al
cmp    $0x2f,%al
je     11c0 <sp_fix_p_cdpp+0x70>
test   %al,%al
je     12e3 <sp_fix_p_cdpp+0x193>
test   %al,%al
jne    11d1 <sp_fix_p_cdpp+0x81>
jmp    12e3 <sp_fix_p_cdpp+0x193>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x1(%r13,%r15,1),%al
add    $0x1,%r15
test   %al,%al
je     12e3 <sp_fix_p_cdpp+0x193>
lea    (%r15,%r13,1),%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1240 <sp_fix_p_cdpp+0xf0>
mov    %rbp,%rdi
lea    0xe10(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1240 <sp_fix_p_cdpp+0xf0>
mov    %rbp,%rdi
lea    0xdf4(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1270 <sp_fix_p_cdpp+0x120>
mov    %rbp,%rdi
lea    0xddf(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1270 <sp_fix_p_cdpp+0x120>
add    $0x1,%r15
jmp    119b <sp_fix_p_cdpp+0x4b>
xchg   %ax,%ax
test   %r15,%r15
je     1180 <sp_fix_p_cdpp+0x30>
lea    -0x2(%r15),%r12
cmp    $0x1,%r15
jne    1279 <sp_fix_p_cdpp+0x129>
cmpb   $0x2f,0x0(%r13)
je     1180 <sp_fix_p_cdpp+0x30>
lea    (%r12,%r13,1),%rbx
jmp    1290 <sp_fix_p_cdpp+0x140>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x2(%rbp),%rbx
jmp    1184 <sp_fix_p_cdpp+0x34>
lea    (%r12,%r13,1),%rbx
test   %r12,%r12
je     12b4 <sp_fix_p_cdpp+0x164>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmpb   $0x2f,(%rbx)
je     12a9 <sp_fix_p_cdpp+0x159>
lea    (%r12,%r13,1),%rbx
add    $0xffffffffffffffff,%rbx
add    $0xffffffffffffffff,%r12
jne    1290 <sp_fix_p_cdpp+0x140>
xor    %r12d,%r12d
mov    %r13,%rbx
cmp    %r15,%r12
je     119b <sp_fix_p_cdpp+0x4b>
jmp    12c0 <sp_fix_p_cdpp+0x170>
xor    %r12d,%r12d
cmp    %r15,%r12
je     119b <sp_fix_p_cdpp+0x4b>
add    $0x2,%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <memmove@plt>
mov    %r12,%r15
jmp    119b <sp_fix_p_cdpp+0x4b>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"../\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [3 x i8] c"./\00"
@.str.3 = [2 x i8] c".\00"
define i8* @sp_fix_p_cdpp(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
store i8* %5, i8** %3
%6 = load i8*, i8** %2
%7 = call i32 @sp_make_system_slash(i8* %6)
%8 = load i8*, i8** %2
%9 = call i32 @sp_fix_slash_repeated(i8* %8)
br label %10
10: ; preds = %1, %52, %91, %100, %110
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %10
br label %113
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 47
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %3
br label %23
23: ; preds = %20, %15
%24 = load i8*, i8** %3
%25 = load i8, i8* %24
%26 = icmp ne i8 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %23
br label %113
28: ; preds = %23
%29 = load i8*, i8** %3
%30 = call i64 @strncmp(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%31 = icmp eq i64 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %28
%33 = load i8*, i8** %3
%34 = call i64 @strncmp(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 3)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %92
36: ; preds = %32, %28
%37 = load i8*, i8** %3
%38 = getelementptr inbounds i8, i8* %37, i64 -2
store i8* %38, i8** %4
%39 = load i8*, i8** %3
%40 = load i8*, i8** %2
%41 = icmp eq i8* %39, %40
br i1 %41, label %52, label %42
42: ; preds = %36
%43 = load i8*, i8** %3
%44 = load i8*, i8** %2
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = icmp eq i8* %43, %45
br i1 %46, label %47, label %61
47: ; preds = %42
%48 = load i8*, i8** %2
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 47
br i1 %51, label %52, label %61
52: ; preds = %47, %36
%53 = load i8*, i8** %3
%54 = load i8*, i8** %3
%55 = getelementptr inbounds i8, i8* %54, i64 3
%56 = load i8*, i8** %3
%57 = getelementptr inbounds i8, i8* %56, i64 3
%58 = call i64 @strlen(i8* %57)
%59 = add nsw i64 %58, 1
%60 = call i32 @memmove(i8* %53, i8* %55, i64 %59)
br label %10
61: ; preds = %47, %42
br label %62
62: ; preds = %74, %61
%63 = load i8*, i8** %4
%64 = load i8*, i8** %2
%65 = icmp ne i8* %63, %64
br i1 %65, label %66, label %72
66: ; preds = %62
%67 = load i8*, i8** %4
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = icmp eq i32 %69, 47
%71 = xor i1 %70, true
br label %72
72: ; preds = %66, %62
%73 = phi i1 [ false, %62 ], [ %71, %66 ]
br i1 %73, label %74, label %77
74: ; preds = %72
%75 = load i8*, i8** %4
%76 = getelementptr inbounds i8, i8* %75, i32 -1
store i8* %76, i8** %4
br label %62
77: ; preds = %72
%78 = load i8*, i8** %4
%79 = load i8*, i8** %3
%80 = icmp ne i8* %78, %79
br i1 %80, label %81, label %91
81: ; preds = %77
%82 = load i8*, i8** %4
%83 = load i8*, i8** %3
%84 = getelementptr inbounds i8, i8* %83, i64 2
%85 = load i8*, i8** %3
%86 = getelementptr inbounds i8, i8* %85, i64 2
%87 = call i64 @strlen(i8* %86)
%88 = add nsw i64 %87, 1
%89 = call i32 @memmove(i8* %82, i8* %84, i64 %88)
%90 = load i8*, i8** %4
store i8* %90, i8** %3
br label %91
91: ; preds = %81, %77
br label %10
92: ; preds = %32
%93 = load i8*, i8** %3
%94 = call i64 @strncmp(i8* %93, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%95 = icmp eq i64 %94, 0
br i1 %95, label %100, label %96
96: ; preds = %92
%97 = load i8*, i8** %3
%98 = call i64 @strncmp(i8* %97, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 2)
%99 = icmp eq i64 %98, 0
br i1 %99, label %100, label %109
100: ; preds = %96, %92
%101 = load i8*, i8** %3
%102 = load i8*, i8** %3
%103 = getelementptr inbounds i8, i8* %102, i64 2
%104 = load i8*, i8** %3
%105 = getelementptr inbounds i8, i8* %104, i64 2
%106 = call i64 @strlen(i8* %105)
%107 = add nsw i64 %106, 1
%108 = call i32 @memmove(i8* %101, i8* %103, i64 %107)
br label %10
109: ; preds = %96
br label %110
110: ; preds = %109
%111 = load i8*, i8** %3
%112 = getelementptr inbounds i8, i8* %111, i32 1
store i8* %112, i8** %3
br label %10
113: ; preds = %27, %14
%114 = load i8*, i8** %2
ret i8* %114
}

LLVM IR (-O2):
@.str = [4 x i8] c"../\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [3 x i8] c"./\00"
@.str.3 = [2 x i8] c".\00"
define i8* @sp_fix_p_cdpp(i8* returned %0) {
%2 = tail call i32 @sp_make_system_slash(i8* %0)
%3 = tail call i32 @sp_fix_slash_repeated(i8* %0)
br label %4
4: ; preds = %35, %1
%5 = phi i64 [ 0, %1 ], [ %36, %35 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
switch i8 %7, label %12 [
i8 0, label %73
i8 47, label %8
]
8: ; preds = %4
%9 = add nsw i64 %5, 1
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
br label %12
12: ; preds = %4, %8
%13 = phi i8 [ %11, %8 ], [ %7, %4 ]
%14 = phi i64 [ %9, %8 ], [ %5, %4 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = icmp eq i8 %13, 0
br i1 %16, label %73, label %17
17: ; preds = %12
%18 = tail call i64 @strncmp(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = tail call i64 @strncmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 3)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %60
23: ; preds = %20, %17
%24 = add nsw i64 %14, -2
switch i64 %14, label %37 [
i64 0, label %30
i64 1, label %25
]
25: ; preds = %23
%26 = load i8, i8* %0
%27 = icmp eq i8 %26, 47
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = getelementptr inbounds i8, i8* %0, i64 %24
br label %40
30: ; preds = %23, %25
%31 = getelementptr inbounds i8, i8* %15, i64 3
%32 = tail call i64 @strlen(i8* %31)
%33 = add nsw i64 %32, 1
%34 = tail call i32 @memmove(i8* %15, i8* %31, i64 %33)
br label %35
35: ; preds = %30, %55, %51, %66, %71
%36 = phi i64 [ %14, %66 ], [ %72, %71 ], [ %14, %30 ], [ %52, %55 ], [ %14, %51 ]
br label %4
37: ; preds = %23
%38 = getelementptr inbounds i8, i8* %0, i64 %24
%39 = icmp eq i64 %24, 0
br i1 %39, label %51, label %40
40: ; preds = %28, %37
%41 = phi i8* [ %38, %37 ], [ %29, %28 ]
br label %42
42: ; preds = %40, %47
%43 = phi i8* [ %49, %47 ], [ %41, %40 ]
%44 = phi i64 [ %48, %47 ], [ %24, %40 ]
%45 = load i8, i8* %43
%46 = icmp eq i8 %45, 47
br i1 %46, label %51, label %47
47: ; preds = %42
%48 = add nsw i64 %44, -1
%49 = getelementptr inbounds i8, i8* %0, i64 %48
%50 = icmp eq i64 %48, 0
br i1 %50, label %51, label %42
51: ; preds = %42, %47, %37
%52 = phi i64 [ 0, %37 ], [ 0, %47 ], [ %44, %42 ]
%53 = phi i8* [ %38, %37 ], [ %0, %47 ], [ %43, %42 ]
%54 = icmp eq i64 %52, %14
br i1 %54, label %35, label %55
55: ; preds = %51
%56 = getelementptr inbounds i8, i8* %15, i64 2
%57 = tail call i64 @strlen(i8* %56)
%58 = add nsw i64 %57, 1
%59 = tail call i32 @memmove(i8* %53, i8* %56, i64 %58)
br label %35
60: ; preds = %20
%61 = tail call i64 @strncmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%62 = icmp eq i64 %61, 0
br i1 %62, label %66, label %63
63: ; preds = %60
%64 = tail call i64 @strncmp(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 2)
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %71
66: ; preds = %63, %60
%67 = getelementptr inbounds i8, i8* %15, i64 2
%68 = tail call i64 @strlen(i8* %67)
%69 = add nsw i64 %68, 1
%70 = tail call i32 @memmove(i8* %15, i8* %67, i64 %69)
br label %35
71: ; preds = %63
%72 = add nsw i64 %14, 1
br label %35
73: ; preds = %4, %12
ret i8* %0
}