#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__ strchr(char *, char);
int powerscrub_filepath(char *path, int tolerate_dirsep) {
  char *d = path;
  char *s = path;
  for (;;) {
    switch (*s++) {
    case 0:
      break;
    case '%':
      *d++ = '!';
      continue;
    case ':':
    case '.':
      if (d > path && !strchr("/.", d[-1]))
        *d++ = '.';
      continue;
    case '/':
    case '\\':
      if (d > path && strchr("/.", d[-1]))
        d[-1] = (tolerate_dirsep ? '/' : '.');
      else
        *d++ = (tolerate_dirsep ? '/' : '.');
      continue;
    default:
      if (strchr(
              "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-",
              s[-1]))
        *d++ = s[-1];
      else if (d == path || d[-1] != '_')
        *d++ = '_';
      continue;
    }
    break;
  }
  while (d > path && strchr("/.", d[-1]))
    d--;
  *d = 0;
  return (int)(d - path);
}


x86 assembly (clang, -O0):
<powerscrub_filepath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
test   %eax,%eax
je     11a6 <powerscrub_filepath+0x96>
jmp    1151 <powerscrub_filepath+0x41>
mov    -0x24(%rbp),%eax
sub    $0x25,%eax
je     11ab <powerscrub_filepath+0x9b>
jmp    1162 <powerscrub_filepath+0x52>
mov    -0x24(%rbp),%eax
sub    $0x2e,%eax
je     11c2 <powerscrub_filepath+0xb2>
jmp    1173 <powerscrub_filepath+0x63>
mov    -0x24(%rbp),%eax
sub    $0x2f,%eax
je     1205 <powerscrub_filepath+0xf5>
jmp    1184 <powerscrub_filepath+0x74>
mov    -0x24(%rbp),%eax
sub    $0x3a,%eax
je     11c2 <powerscrub_filepath+0xb2>
jmp    1195 <powerscrub_filepath+0x85>
mov    -0x24(%rbp),%eax
sub    $0x5c,%eax
je     1205 <powerscrub_filepath+0xf5>
jmp    127d <powerscrub_filepath+0x16d>
jmp    12f3 <powerscrub_filepath+0x1e3>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x21,(%rax)
jmp    112f <powerscrub_filepath+0x1f>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jbe    1200 <powerscrub_filepath+0xf0>
mov    -0x18(%rbp),%rax
lea    0xe25(%rip),%rdi
movsbl -0x1(%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
jne    1200 <powerscrub_filepath+0xf0>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2e,(%rax)
jmp    112f <powerscrub_filepath+0x1f>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jbe    1252 <powerscrub_filepath+0x142>
mov    -0x18(%rbp),%rax
lea    0xde2(%rip),%rdi
movsbl -0x1(%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     1252 <powerscrub_filepath+0x142>
mov    -0xc(%rbp),%edx
mov    $0x2e,%eax
mov    $0x2f,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,-0x1(%rax)
jmp    1278 <powerscrub_filepath+0x168>
mov    -0xc(%rbp),%edx
mov    $0x2e,%eax
mov    $0x2f,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    112f <powerscrub_filepath+0x1f>
mov    -0x20(%rbp),%rax
lea    0xd7b(%rip),%rdi
movsbl -0x1(%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     12b8 <powerscrub_filepath+0x1a8>
mov    -0x20(%rbp),%rax
mov    -0x1(%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    12ee <powerscrub_filepath+0x1de>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     12d7 <powerscrub_filepath+0x1c7>
mov    -0x18(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x5f,%eax
je     12e9 <powerscrub_filepath+0x1d9>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5f,(%rax)
jmp    12ee <powerscrub_filepath+0x1de>
jmp    112f <powerscrub_filepath+0x1f>
jmp    12f8 <powerscrub_filepath+0x1e8>
jmp    12fd <powerscrub_filepath+0x1ed>
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x25(%rbp)
jbe    132e <powerscrub_filepath+0x21e>
mov    -0x18(%rbp),%rax
lea    0xce5(%rip),%rdi
movsbl -0x1(%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    133e <powerscrub_filepath+0x22e>
jmp    134f <powerscrub_filepath+0x23f>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    12fd <powerscrub_filepath+0x1ed>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<powerscrub_filepath>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%esi
mov    $0x2f,%r13b
sbb    $0x0,%r13b
mov    %rdi,%r12
lea    0xed1(%rip),%rbp
mov    %rdi,%rbx
mov    %rdi,%r15
jmp    114a <powerscrub_filepath+0x3a>
nopw   0x0(%rax,%rax,1)
mov    %r13b,(%rbx)
add    $0x1,%rbx
mov    %r14,%r15
lea    0x1(%r15),%r14
movsbl (%r15),%esi
lea    -0x25(%rsi),%eax
cmp    $0x15,%eax
ja     1190 <powerscrub_filepath+0x80>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
mov    %r14,%r15
cmp    %r12,%rbx
jbe    114a <powerscrub_filepath+0x3a>
movsbl -0x1(%rbx),%esi
lea    0xee1(%rip),%rdi
call   1030 <strchr@plt>
mov    %r14,%r15
test   %rax,%rax
jne    114a <powerscrub_filepath+0x3a>
movb   $0x2e,(%rbx)
jmp    1143 <powerscrub_filepath+0x33>
nopl   0x0(%rax)
cmp    $0x5c,%esi
je     11c0 <powerscrub_filepath+0xb0>
test   %esi,%esi
je     1210 <powerscrub_filepath+0x100>
lea    0xebb(%rip),%rdi
call   1030 <strchr@plt>
test   %rax,%rax
je     11f6 <powerscrub_filepath+0xe6>
movzbl (%r15),%eax
mov    %al,(%rbx)
jmp    1143 <powerscrub_filepath+0x33>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    %r12,%rbx
jbe    1140 <powerscrub_filepath+0x30>
movsbl -0x1(%rbx),%esi
lea    0xe84(%rip),%rdi
call   1030 <strchr@plt>
test   %rax,%rax
je     1140 <powerscrub_filepath+0x30>
mov    %r13b,-0x1(%rbx)
mov    %r14,%r15
jmp    114a <powerscrub_filepath+0x3a>
movb   $0x21,(%rbx)
jmp    1143 <powerscrub_filepath+0x33>
cmp    %r12,%rbx
je     1208 <powerscrub_filepath+0xf8>
cmpb   $0x5f,-0x1(%rbx)
mov    %r14,%r15
je     114a <powerscrub_filepath+0x3a>
movb   $0x5f,(%rbx)
jmp    1143 <powerscrub_filepath+0x33>
mov    %ebx,%ecx
sub    %r12d,%ecx
lea    0xe3c(%rip),%r14
nopl   0x0(%rax)
mov    %rbx,%rbp
mov    %ecx,%r15d
cmp    %r12,%rbx
jbe    1244 <powerscrub_filepath+0x134>
lea    -0x1(%rbp),%rbx
movsbl -0x1(%rbp),%esi
mov    %r14,%rdi
call   1030 <strchr@plt>
lea    -0x1(%r15),%ecx
test   %rax,%rax
jne    1220 <powerscrub_filepath+0x110>
movb   $0x0,0x0(%rbp)
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"/.\00"
@.str.1 = [64 x i8] c"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-\00"
define i32 @powerscrub_filepath(i8* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
%4 = select i1 %3, i8 46, i8 47
br label %5
5: ; preds = %38, %2
%6 = phi i8* [ %0, %2 ], [ %39, %38 ]
%7 = phi i8* [ %0, %2 ], [ %8, %38 ]
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = load i8, i8* %7
%10 = sext i8 %9 to i32
switch i32 %10, label %32 [
i32 0, label %48
i32 37, label %11
i32 58, label %13
i32 46, label %13
i32 47, label %22
i32 92, label %22
]
11: ; preds = %5
%12 = getelementptr inbounds i8, i8* %6, i64 1
store i8 33, i8* %6
br label %38
13: ; preds = %5, %5
%14 = icmp ugt i8* %6, %0
br i1 %14, label %15, label %38
15: ; preds = %13
%16 = getelementptr inbounds i8, i8* %6, i64 -1
%17 = load i8, i8* %16
%18 = tail call i64 @strchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %38
20: ; preds = %15
%21 = getelementptr inbounds i8, i8* %6, i64 1
store i8 46, i8* %6
br label %38
22: ; preds = %5, %5
%23 = icmp ugt i8* %6, %0
br i1 %23, label %24, label %30
24: ; preds = %22
%25 = getelementptr inbounds i8, i8* %6, i64 -1
%26 = load i8, i8* %25
%27 = tail call i64 @strchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %24
store i8 %4, i8* %25
br label %38
30: ; preds = %24, %22
%31 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %4, i8* %6
br label %38
32: ; preds = %5
%33 = tail call i64 @strchr(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0), i8 signext %9)
%34 = icmp eq i64 %33, 0
br i1 %34, label %40, label %35
35: ; preds = %32
%36 = load i8, i8* %7
%37 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %36, i8* %6
br label %38
38: ; preds = %35, %46, %42, %29, %30, %13, %15, %20, %11
%39 = phi i8* [ %12, %11 ], [ %6, %15 ], [ %21, %20 ], [ %6, %13 ], [ %6, %29 ], [ %31, %30 ], [ %37, %35 ], [ %47, %46 ], [ %6, %42 ]
br label %5
40: ; preds = %32
%41 = icmp eq i8* %6, %0
br i1 %41, label %46, label %42
42: ; preds = %40
%43 = getelementptr inbounds i8, i8* %6, i64 -1
%44 = load i8, i8* %43
%45 = icmp eq i8 %44, 95
br i1 %45, label %38, label %46
46: ; preds = %42, %40
%47 = getelementptr inbounds i8, i8* %6, i64 1
store i8 95, i8* %6
br label %38
48: ; preds = %5, %51
%49 = phi i8* [ %52, %51 ], [ %6, %5 ]
%50 = icmp ugt i8* %49, %0
br i1 %50, label %51, label %56
51: ; preds = %48
%52 = getelementptr inbounds i8, i8* %49, i64 -1
%53 = load i8, i8* %52
%54 = tail call i64 @strchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %53)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %48
56: ; preds = %48, %51
store i8 0, i8* %49
%57 = ptrtoint i8* %49 to i64
%58 = ptrtoint i8* %0 to i64
%59 = sub i64 %57, %58
%60 = trunc i64 %59 to i32
ret i32 %60
}