#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__);
scalar_t__ strlen(char *);
char *strrchr(char *, char);
char *strstr(char *, char *);
void simplify_path(char *f) {
  char *s;
  while ((s = strstr(f + 1, "/../"))) {
    char *rslash;
    *s = 0;
    rslash = strrchr(f, '/');
    *s = '/';
    if (!rslash)
      rslash = f - 1;
    memmove(rslash + 1, s + 4, strlen(s + 4) + 1);
  }
}


x86 assembly (clang, -O0):
<simplify_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
lea    0xea5(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11e3 <simplify_path+0xa3>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x2f,(%rax)
cmpq   $0x0,-0x18(%rbp)
jne    11a5 <simplify_path+0x65>
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x4,%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1050 <memmove@plt>
jmp    114c <simplify_path+0xc>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simplify_path>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
lea    0x1(%rdi),%r14
lea    0xea7(%rip),%rsi
mov    %r14,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
je     11cc <simplify_path+0x8c>
mov    %rax,%rbx
lea    -0x1(%r12),%rbp
lea    0xe8b(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x0,(%rbx)
mov    %r12,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
movb   $0x2f,(%rbx)
test   %rax,%rax
cmove  %rbp,%rax
lea    0x1(%rax),%r13
add    $0x4,%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r13,%rdi
mov    %rbx,%rsi
call   1050 <memmove@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1180 <simplify_path+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"/../\00"
define void @simplify_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
br label %5
5: ; preds = %20, %1
%6 = load i8*, i8** %2
%7 = getelementptr inbounds i8, i8* %6, i64 1
%8 = call i8* @strstr(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %30
10: ; preds = %5
%11 = load i8*, i8** %3
store i8 0, i8* %11
%12 = load i8*, i8** %2
%13 = call i8* @strrchr(i8* %12, i8 signext 47)
store i8* %13, i8** %4
%14 = load i8*, i8** %3
store i8 47, i8* %14
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %20, label %17
17: ; preds = %10
%18 = load i8*, i8** %2
%19 = getelementptr inbounds i8, i8* %18, i64 -1
store i8* %19, i8** %4
br label %20
20: ; preds = %17, %10
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 4
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i64 4
%27 = call i64 @strlen(i8* %26)
%28 = add nsw i64 %27, 1
%29 = call i32 @memmove(i8* %22, i8* %24, i64 %28)
br label %5
30: ; preds = %5
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"/../\00"
define void @simplify_path(i8* %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 1
%3 = tail call i8* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %19, label %5
5: ; preds = %1
%6 = getelementptr inbounds i8, i8* %0, i64 -1
br label %7
7: ; preds = %5, %7
%8 = phi i8* [ %3, %5 ], [ %17, %7 ]
store i8 0, i8* %8
%9 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
store i8 47, i8* %8
%10 = icmp eq i8* %9, null
%11 = select i1 %10, i8* %6, i8* %9
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = getelementptr inbounds i8, i8* %8, i64 4
%14 = tail call i64 @strlen(i8* %13)
%15 = add nsw i64 %14, 1
%16 = tail call i32 @memmove(i8* %12, i8* %13, i64 %15)
%17 = tail call i8* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %7
19: ; preds = %7, %1
ret void
}