#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__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strncmp(char *, char *, int);
sanitize(char *str) {
  char *src, *dest;
  src = dest = str;
  while (*src) {
    if (strncmp(src, "/../", 4) == 0)
      src + -3;
    else if (strncmp(src, "//", 2) == 0)
      src++;
    else
      *dest++ = *src++;
  }
  *dest = '\0';
  if (*str == '/')
    strcpy(str, str + 1);
  if (str[0] == '\0' || strcmp(str, "./") == 0 || strcmp(str, "./..") == 0)
    strcpy(str, ".");
}


x86 assembly (clang, -O0):
<sanitize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d5 <sanitize+0xa5>
mov    -0x18(%rbp),%rdi
lea    0xea0(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1179 <sanitize+0x49>
jmp    11d0 <sanitize+0xa0>
mov    -0x18(%rbp),%rdi
lea    0xe81(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11a9 <sanitize+0x79>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11cb <sanitize+0x9b>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    11d0 <sanitize+0xa0>
jmp    1148 <sanitize+0x18>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11fd <sanitize+0xcd>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1241 <sanitize+0x111>
mov    -0x10(%rbp),%rdi
lea    0xdea(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1241 <sanitize+0x111>
mov    -0x10(%rbp),%rdi
lea    0xdd6(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1251 <sanitize+0x121>
mov    -0x10(%rbp),%rdi
lea    0xdbf(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sanitize>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
cmpb   $0x0,(%rdi)
mov    %rdi,%r13
je     11a6 <sanitize+0x76>
lea    0xeb5(%rip),%r12
lea    0xeb3(%rip),%r15
mov    %r14,%r13
mov    %r14,%rbx
jmp    116b <sanitize+0x3b>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rcx
cmpb   $0x0,(%rcx)
mov    %rcx,%rbx
je     11a6 <sanitize+0x76>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1160 <sanitize+0x30>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
lea    0x1(%rbx),%rcx
test   %rax,%rax
je     1163 <sanitize+0x33>
movzbl (%rbx),%eax
mov    %al,0x0(%r13)
add    $0x1,%r13
jmp    1163 <sanitize+0x33>
movb   $0x0,0x0(%r13)
mov    (%r14),%al
cmp    $0x2f,%al
jne    11c1 <sanitize+0x91>
lea    0x1(%r14),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    (%r14),%al
test   %al,%al
je     11ed <sanitize+0xbd>
lea    0xe36(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11ed <sanitize+0xbd>
lea    0xe28(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11fc <sanitize+0xcc>
lea    0xe17(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"/../\00"
@.str.1 = [3 x i8] c"//\00"
@.str.2 = [3 x i8] c"./\00"
@.str.3 = [5 x i8] c"./..\00"
@.str.4 = [2 x i8] c".\00"
define i32 @sanitize(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
store i8* %6, i8** %5
store i8* %6, i8** %4
br label %7
7: ; preds = %32, %1
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %33
11: ; preds = %7
%12 = load i8*, i8** %4
%13 = call i64 @strncmp(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 -3
br label %32
18: ; preds = %11
%19 = load i8*, i8** %4
%20 = call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
br label %31
25: ; preds = %18
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %4
%28 = load i8, i8* %26
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %5
store i8 %28, i8* %29
br label %31
31: ; preds = %25, %22
br label %32
32: ; preds = %31, %15
br label %7
33: ; preds = %7
%34 = load i8*, i8** %5
store i8 0, i8* %34
%35 = load i8*, i8** %3
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 47
br i1 %38, label %39, label %44
39: ; preds = %33
%40 = load i8*, i8** %3
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i64 1
%43 = call i32 @strcpy(i8* %40, i8* %42)
br label %44
44: ; preds = %39, %33
%45 = load i8*, i8** %3
%46 = getelementptr inbounds i8, i8* %45, i64 0
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 0
br i1 %49, label %58, label %50
50: ; preds = %44
%51 = load i8*, i8** %3
%52 = call i64 @strcmp(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%53 = icmp eq i64 %52, 0
br i1 %53, label %58, label %54
54: ; preds = %50
%55 = load i8*, i8** %3
%56 = call i64 @strcmp(i8* %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %54, %50, %44
%59 = load i8*, i8** %3
%60 = call i32 @strcpy(i8* %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %61
61: ; preds = %58, %54
%62 = load i32, i32* %2
ret i32 %62
}

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