#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*/ LC_ALL;
scalar_t__ isalnum(char const);
char *setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ toupper(char const);
void strip(char *wp, const char *s) {
  int slash_count = 0;
  char old_locale[20], *old_locale_p;
  old_locale_p = setlocale(LC_ALL, "C");
  strncpy(old_locale, old_locale_p, 20);
  while (*s != '\0') {
    if (isalnum(*s) || *s == '_' || *s == '-' || *s == '.')
      *wp++ = toupper(*s);
    else if (*s == '/') {
      if (++slash_count == 3)
        break;
      *wp++ = '/';
    }
    ++s;
  }
  while (slash_count++ < 2)
    *wp++ = '/';
  *wp = '\0';
  setlocale(LC_ALL, old_locale);
}


x86 assembly (clang, -O0):
<strip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
lea    0xe99(%rip),%rsi
call   1060 <setlocale@plt>
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    $0x14,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     124b <strip+0x10b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isalnum@plt>
cmp    $0x0,%rax
jne    11d8 <strip+0x98>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
je     11d8 <strip+0x98>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     11d8 <strip+0x98>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11fc <strip+0xbc>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    123a <strip+0xfa>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1235 <strip+0xf5>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x3,%eax
jne    1223 <strip+0xe3>
jmp    124b <strip+0x10b>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x2f,(%rax)
jmp    123a <strip+0xfa>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1182 <strip+0x42>
jmp    1250 <strip+0x110>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x2,%eax
jge    127b <strip+0x13b>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x2f,(%rax)
jmp    1250 <strip+0x110>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1060 <setlocale@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e79(%rip),%r15
mov    (%r15),%edi
lea    0xe8f(%rip),%rsi
call   1070 <setlocale@plt>
mov    %rsp,%rdi
mov    %rax,%rsi
mov    $0x14,%edx
call   1030 <strncpy@plt>
mov    (%rbx),%al
test   %al,%al
je     11f6 <strip+0xa6>
add    $0x1,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl %al,%edi
call   1050 <isalnum@plt>
movzbl -0x1(%rbx),%ecx
test   %rax,%rax
je     11d0 <strip+0x80>
movsbl %cl,%edi
call   1040 <toupper@plt>
mov    %al,(%r14)
add    $0x1,%r14
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11a0 <strip+0x50>
jmp    11ef <strip+0x9f>
nopl   (%rax)
lea    -0x2d(%rcx),%eax
cmp    $0x2,%al
jb     11b1 <strip+0x61>
cmp    $0x2f,%cl
je     11e3 <strip+0x93>
cmp    $0x5f,%cl
je     11b1 <strip+0x61>
jmp    11c0 <strip+0x70>
add    $0x1,%ebp
mov    $0x2f,%al
cmp    $0x3,%ebp
jne    11b9 <strip+0x69>
jmp    1217 <strip+0xc7>
cmp    $0x1,%ebp
jle    11f8 <strip+0xa8>
jmp    1217 <strip+0xc7>
xor    %ebp,%ebp
mov    $0x1,%ebx
sub    %ebp,%ebx
lea    0x1(%rbx),%rdx
mov    %r14,%rdi
mov    $0x2f,%esi
call   1060 <memset@plt>
add    %rbx,%r14
add    $0x1,%r14
movb   $0x0,(%r14)
mov    (%r15),%edi
mov    %rsp,%rsi
call   1070 <setlocale@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@LC_ALL = global i32 0
@.str = [2 x i8] c"C\00"
define void @strip(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [20 x i8]
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%8 = load i32, i32* @LC_ALL
%9 = call i8* @setlocale(i32 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %7
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%11 = load i8*, i8** %7
%12 = call i32 @strncpy(i8* %10, i8* %11, i32 20)
br label %13
13: ; preds = %59, %2
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %62
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = call i64 @isalnum(i8 signext %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %38, label %23
23: ; preds = %18
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 95
br i1 %27, label %38, label %28
28: ; preds = %23
%29 = load i8*, i8** %4
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 45
br i1 %32, label %38, label %33
33: ; preds = %28
%34 = load i8*, i8** %4
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 46
br i1 %37, label %38, label %45
38: ; preds = %33, %28, %23, %18
%39 = load i8*, i8** %4
%40 = load i8, i8* %39
%41 = call i32 @toupper(i8 signext %40)
%42 = trunc i32 %41 to i8
%43 = load i8*, i8** %3
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %3
store i8 %42, i8* %43
br label %59
45: ; preds = %33
%46 = load i8*, i8** %4
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 47
br i1 %49, label %50, label %58
50: ; preds = %45
%51 = load i32, i32* %5
%52 = add nsw i32 %51, 1
store i32 %52, i32* %5
%53 = icmp eq i32 %52, 3
br i1 %53, label %54, label %55
54: ; preds = %50
br label %62
55: ; preds = %50
%56 = load i8*, i8** %3
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %3
store i8 47, i8* %56
br label %58
58: ; preds = %55, %45
br label %59
59: ; preds = %58, %38
%60 = load i8*, i8** %4
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %4
br label %13
62: ; preds = %54, %13
br label %63
63: ; preds = %67, %62
%64 = load i32, i32* %5
%65 = add nsw i32 %64, 1
store i32 %65, i32* %5
%66 = icmp slt i32 %64, 2
br i1 %66, label %67, label %70
67: ; preds = %63
%68 = load i8*, i8** %3
%69 = getelementptr inbounds i8, i8* %68, i32 1
store i8* %69, i8** %3
store i8 47, i8* %68
br label %63
70: ; preds = %63
%71 = load i8*, i8** %3
store i8 0, i8* %71
%72 = load i32, i32* @LC_ALL
%73 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%74 = call i8* @setlocale(i32 %72, i8* %73)
ret void
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str = [2 x i8] c"C\00"
define void @strip(i8* nocapture writeonly %0, i8* nocapture %1) {
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @LC_ALL
%6 = tail call i8* @setlocale(i32 %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @strncpy(i8* %4, i8* %6, i32 20)
%8 = load i8, i8* %1
%9 = icmp eq i8 %8, 0
br i1 %9, label %37, label %10
10: ; preds = %2, %29
%11 = phi i8 [ %33, %29 ], [ %8, %2 ]
%12 = phi i8* [ %31, %29 ], [ %0, %2 ]
%13 = phi i32 [ %30, %29 ], [ 0, %2 ]
%14 = phi i8* [ %32, %29 ], [ %1, %2 ]
%15 = call i64 @isalnum(i8 signext %11)
%16 = icmp eq i64 %15, 0
%17 = load i8, i8* %14
br i1 %16, label %18, label %19
18: ; preds = %10
switch i8 %17, label %29 [
i8 95, label %19
i8 45, label %19
i8 46, label %19
i8 47, label %22
]
19: ; preds = %10, %18, %18, %18
%20 = call i32 @toupper(i8 signext %17)
%21 = trunc i32 %20 to i8
br label %25
22: ; preds = %18
%23 = add nsw i32 %13, 1
%24 = icmp eq i32 %23, 3
br i1 %24, label %44, label %25
25: ; preds = %22, %19
%26 = phi i8 [ %21, %19 ], [ 47, %22 ]
%27 = phi i32 [ %13, %19 ], [ %23, %22 ]
%28 = getelementptr inbounds i8, i8* %12, i64 1
store i8 %26, i8* %12
br label %29
29: ; preds = %25, %18
%30 = phi i32 [ %13, %18 ], [ %27, %25 ]
%31 = phi i8* [ %12, %18 ], [ %28, %25 ]
%32 = getelementptr inbounds i8, i8* %14, i64 1
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 0
br i1 %34, label %35, label %10
35: ; preds = %29
%36 = icmp slt i32 %30, 2
br i1 %36, label %37, label %44
37: ; preds = %2, %35
%38 = phi i32 [ %30, %35 ], [ 0, %2 ]
%39 = phi i8* [ %31, %35 ], [ %0, %2 ]
%40 = sub i32 1, %38
%41 = zext i32 %40 to i64
%42 = add nuw nsw i64 %41, 1
%43 = getelementptr i8, i8* %39, i64 %42
br label %44
44: ; preds = %22, %37, %35
%45 = phi i8* [ %31, %35 ], [ %43, %37 ], [ %12, %22 ]
store i8 0, i8* %45
%46 = load i32, i32* @LC_ALL
%47 = call i8* @setlocale(i32 %46, i8* %4)
ret void
}