#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*/ memcmp(char *, char *, int);
void _cancel_relative(char *base, char **ref_cursor, char **ref_cursor_out,
                      char *end) {
  char *cursor = *ref_cursor;
  char *cursor_out = *ref_cursor_out;
  do {
    cursor += 3;
    while (cursor_out > base && cursor_out[-1] == '/')
      cursor_out--;
    while (cursor_out > base && *--cursor_out != '/')
      ;
  } while (cursor + 3 < end && !memcmp(cursor, "/../", 4));
  *ref_cursor = cursor;
  *ref_cursor_out = cursor_out;
}


x86 assembly (clang, -O0):
<_cancel_relative>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x31(%rbp)
jbe    116e <_cancel_relative+0x5e>
mov    -0x30(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x2f,%eax
sete   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    117e <_cancel_relative+0x6e>
jmp    118f <_cancel_relative+0x7f>
mov    -0x30(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
jmp    114a <_cancel_relative+0x3a>
jmp    1194 <_cancel_relative+0x84>
mov    -0x30(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x32(%rbp)
jbe    11c3 <_cancel_relative+0xb3>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x30(%rbp)
movsbl -0x1(%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x32(%rbp)
mov    -0x32(%rbp),%al
test   $0x1,%al
jne    11d3 <_cancel_relative+0xc3>
jmp    11d8 <_cancel_relative+0xc8>
jmp    1194 <_cancel_relative+0x84>
jmp    11dd <_cancel_relative+0xcd>
mov    -0x28(%rbp),%rcx
add    $0x3,%rcx
xor    %eax,%eax
cmp    -0x20(%rbp),%rcx
mov    %al,-0x33(%rbp)
jae    1214 <_cancel_relative+0x104>
mov    -0x28(%rbp),%rdi
lea    0xe01(%rip),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x33(%rbp)
mov    -0x33(%rbp),%al
test   $0x1,%al
jne    113e <_cancel_relative+0x2e>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_cancel_relative>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rsi,%r15
mov    %rdi,%rbx
mov    (%rsi),%rcx
mov    %rdx,(%rsp)
mov    (%rdx),%r14
lea    0xecb(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x3(%rcx),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rax
cmp    %rbx,%r14
jbe    1170 <_cancel_relative+0x60>
lea    -0x1(%rax),%r14
cmpb   $0x2f,-0x1(%rax)
je     1150 <_cancel_relative+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    %rbx,%rax
jbe    1190 <_cancel_relative+0x80>
lea    -0x1(%rax),%r14
cmpb   $0x2f,-0x1(%rax)
mov    %r14,%rax
jne    1170 <_cancel_relative+0x60>
jmp    1193 <_cancel_relative+0x83>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rax,%r14
add    $0x6,%rcx
cmp    %r12,%rcx
jae    11b3 <_cancel_relative+0xa3>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
mov    %rbp,%rcx
test   %eax,%eax
je     1140 <_cancel_relative+0x30>
mov    %rbp,(%r15)
mov    (%rsp),%rax
mov    %r14,(%rax)
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 @_cancel_relative(i8* %0, i8** %1, i8** %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i8* %3, i8** %8
%11 = load i8**, i8*** %6
%12 = load i8*, i8** %11
store i8* %12, i8** %9
%13 = load i8**, i8*** %7
%14 = load i8*, i8** %13
store i8* %14, i8** %10
br label %15
15: ; preds = %58, %4
%16 = load i8*, i8** %9
%17 = getelementptr inbounds i8, i8* %16, i64 3
store i8* %17, i8** %9
br label %18
18: ; preds = %30, %15
%19 = load i8*, i8** %10
%20 = load i8*, i8** %5
%21 = icmp ugt i8* %19, %20
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = load i8*, i8** %10
%24 = getelementptr inbounds i8, i8* %23, i64 -1
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 47
br label %28
28: ; preds = %22, %18
%29 = phi i1 [ false, %18 ], [ %27, %22 ]
br i1 %29, label %30, label %33
30: ; preds = %28
%31 = load i8*, i8** %10
%32 = getelementptr inbounds i8, i8* %31, i32 -1
store i8* %32, i8** %10
br label %18
33: ; preds = %28
br label %34
34: ; preds = %46, %33
%35 = load i8*, i8** %10
%36 = load i8*, i8** %5
%37 = icmp ugt i8* %35, %36
br i1 %37, label %38, label %44
38: ; preds = %34
%39 = load i8*, i8** %10
%40 = getelementptr inbounds i8, i8* %39, i32 -1
store i8* %40, i8** %10
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 47
br label %44
44: ; preds = %38, %34
%45 = phi i1 [ false, %34 ], [ %43, %38 ]
br i1 %45, label %46, label %47
46: ; preds = %44
br label %34
47: ; preds = %44
br label %48
48: ; preds = %47
%49 = load i8*, i8** %9
%50 = getelementptr inbounds i8, i8* %49, i64 3
%51 = load i8*, i8** %8
%52 = icmp ult i8* %50, %51
br i1 %52, label %53, label %58
53: ; preds = %48
%54 = load i8*, i8** %9
%55 = call i32 @memcmp(i8* %54, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%56 = icmp ne i32 %55, 0
%57 = xor i1 %56, true
br label %58
58: ; preds = %53, %48
%59 = phi i1 [ false, %48 ], [ %57, %53 ]
br i1 %59, label %15, label %60
60: ; preds = %58
%61 = load i8*, i8** %9
%62 = load i8**, i8*** %6
store i8* %61, i8** %62
%63 = load i8*, i8** %10
%64 = load i8**, i8*** %7
store i8* %63, i8** %64
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"/../\00"
define void @_cancel_relative(i8* readnone %0, i8** nocapture %1, i8** nocapture %2, i8* readnone %3) {
%5 = load i8*, i8** %1
%6 = load i8*, i8** %2
br label %7
7: ; preds = %30, %4
%8 = phi i8* [ %5, %4 ], [ %10, %30 ]
%9 = phi i8* [ %6, %4 ], [ %27, %30 ]
%10 = getelementptr inbounds i8, i8* %8, i64 3
br label %11
11: ; preds = %14, %7
%12 = phi i8* [ %9, %7 ], [ %15, %14 ]
%13 = icmp ugt i8* %12, %0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = getelementptr inbounds i8, i8* %12, i64 -1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 47
br i1 %17, label %11, label %18
18: ; preds = %11, %14
br label %19
19: ; preds = %18, %22
%20 = phi i8* [ %23, %22 ], [ %12, %18 ]
%21 = icmp ugt i8* %20, %0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = getelementptr inbounds i8, i8* %20, i64 -1
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 47
br i1 %25, label %26, label %19
26: ; preds = %22, %19
%27 = phi i8* [ %23, %22 ], [ %20, %19 ]
%28 = getelementptr inbounds i8, i8* %8, i64 6
%29 = icmp ult i8* %28, %3
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = tail call i32 @memcmp(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%32 = icmp eq i32 %31, 0
br i1 %32, label %7, label %33
33: ; preds = %26, %30
store i8* %10, i8** %1
store i8* %27, i8** %2
ret void
}