#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 */
scalar_t__ compareThruSlash(char *, char *);
int /*<<< orphan*/ copyThruSlash(char **, char **);
char *nextSlash(char *);
char *prevSlash(char *);
int compressPathname(char *pathname) {
  char *inPtr, *outPtr;
  inPtr = &pathname[1];
  outPtr = &pathname[1];
  while (1) {
    if (compareThruSlash(inPtr, "../")) {
      if (outPtr == &pathname[1])
        return 0;
      outPtr = prevSlash(outPtr);
      inPtr = nextSlash(inPtr);
    } else if (compareThruSlash(inPtr, "./")) {
      inPtr = nextSlash(inPtr);
    } else {
      copyThruSlash(&outPtr, &inPtr);
    }
    if (inPtr == NULL) {
      return 1;
    }
  }
}


x86 assembly (clang, -O0):
<compressPathname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1030 <compareThruSlash@plt>
cmp    $0x0,%rax
je     11be <compressPathname+0x7e>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
jne    119f <compressPathname+0x5f>
movl   $0x0,-0x4(%rbp)
jmp    1218 <compressPathname+0xd8>
mov    -0x20(%rbp),%rdi
call   1050 <prevSlash@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <nextSlash@plt>
mov    %rax,-0x18(%rbp)
jmp    11fc <compressPathname+0xbc>
mov    -0x18(%rbp),%rdi
lea    0xe38(%rip),%rsi
call   1030 <compareThruSlash@plt>
cmp    $0x0,%rax
je     11ea <compressPathname+0xaa>
mov    -0x18(%rbp),%rdi
call   1040 <nextSlash@plt>
mov    %rax,-0x18(%rbp)
jmp    11f7 <compressPathname+0xb7>
lea    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <copyThruSlash@plt>
jmp    11fc <compressPathname+0xbc>
cmpq   $0x0,-0x18(%rbp)
jne    1213 <compressPathname+0xd3>
movl   $0x1,-0x4(%rbp)
jmp    1218 <compressPathname+0xd8>
jmp    1164 <compressPathname+0x24>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compressPathname>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
add    $0x1,%rbx
mov    %rbx,(%rsp)
mov    %rbx,0x8(%rsp)
lea    0xe9c(%rip),%r14
lea    0xe96(%rip),%r15
lea    0x8(%rsp),%r12
mov    %rsp,%r13
mov    %rbx,%rdi
jmp    11a6 <compressPathname+0x66>
nopl   0x0(%rax,%rax,1)
mov    (%rsp),%rdi
mov    %r15,%rsi
call   1030 <compareThruSlash@plt>
test   %rax,%rax
je     11c9 <compressPathname+0x89>
mov    (%rsp),%rdi
call   1040 <nextSlash@plt>
mov    %rax,%rdi
mov    %rax,(%rsp)
test   %rdi,%rdi
je     11dd <compressPathname+0x9d>
mov    %r14,%rsi
call   1030 <compareThruSlash@plt>
test   %rax,%rax
je     1180 <compressPathname+0x40>
mov    0x8(%rsp),%rdi
cmp    %rbx,%rdi
je     11e4 <compressPathname+0xa4>
call   1050 <prevSlash@plt>
mov    %rax,0x8(%rsp)
jmp    1191 <compressPathname+0x51>
mov    %r12,%rdi
mov    %r13,%rsi
call   1060 <copyThruSlash@plt>
mov    (%rsp),%rdi
test   %rdi,%rdi
jne    11a6 <compressPathname+0x66>
mov    $0x1,%eax
jmp    11e6 <compressPathname+0xa6>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"../\00"
@.str.1 = [3 x i8] c"./\00"
define i32 @compressPathname(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = bitcast i8** %2 to i8*
%5 = bitcast i8** %3 to i8*
%6 = getelementptr inbounds i8, i8* %0, i64 1
store i8* %6, i8** %2
store i8* %6, i8** %3
br label %7
7: ; preds = %28, %1
%8 = phi i8* [ %29, %28 ], [ %6, %1 ]
%9 = call i64 @compareThruSlash(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = icmp eq i8* %12, %6
br i1 %13, label %31, label %14
14: ; preds = %11
%15 = call i8* @prevSlash(i8* %12)
store i8* %15, i8** %3
%16 = load i8*, i8** %2
%17 = call i8* @nextSlash(i8* %16)
store i8* %17, i8** %2
br label %28
18: ; preds = %7
%19 = load i8*, i8** %2
%20 = call i64 @compareThruSlash(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i8*, i8** %2
%24 = call i8* @nextSlash(i8* %23)
store i8* %24, i8** %2
br label %28
25: ; preds = %18
%26 = call i32 @copyThruSlash(i8** %3, i8** %2)
%27 = load i8*, i8** %2
br label %28
28: ; preds = %22, %25, %14
%29 = phi i8* [ %24, %22 ], [ %27, %25 ], [ %17, %14 ]
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %7
31: ; preds = %28, %11
%32 = phi i32 [ 0, %11 ], [ 1, %28 ]
ret i32 %32
}