#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 strlen(char *);
int /*<<< orphan*/ strspn(char *, char const *);
int sanitizeInput(char *buf, int type) {
  int i = 0;
  char const safe_buf_chars[] = "abcdefghijklmnopqrstuvwxyz"
                                "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                                " _,.-/@()*~`&^%$#!?<>'\";:+=[]{}|"
                                "1234567890";
  char const safe_name_chars[] = "abcdefghijklmnopqrstuvwxyz"
                                 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                                 " _-"
                                 "1234567890";
  char *end = buf + strlen(buf);
  if (type == 0) {
    for (buf += strspn(buf, safe_buf_chars); buf != end;
         buf += strspn(buf, safe_buf_chars)) {
      *buf = '_';
      i++;
    }
  } else {
    for (buf += strspn(buf, safe_name_chars); buf != end;
         buf += strspn(buf, safe_name_chars)) {
      *buf = '_';
      i++;
    }
  }
  return i;
}


x86 assembly (clang, -O0):
<sanitizeInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xeac(%rip),%rsi
mov    $0x5f,%edx
call   1050 <memcpy@plt>
lea    -0xc0(%rbp),%rdi
lea    0xef4(%rip),%rsi
mov    $0x42,%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0xd0(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0xd0(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0xc8(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    120f <sanitizeInput+0xdf>
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1040 <strspn@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0xc8(%rbp),%rax
je     120a <sanitizeInput+0xda>
mov    -0x8(%rbp),%rax
movb   $0x5f,(%rax)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1040 <strspn@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11c7 <sanitizeInput+0x97>
jmp    127a <sanitizeInput+0x14a>
mov    -0x8(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
call   1040 <strspn@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0xc8(%rbp),%rax
je     1275 <sanitizeInput+0x145>
mov    -0x8(%rbp),%rax
movb   $0x5f,(%rax)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
call   1040 <strspn@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    122f <sanitizeInput+0xff>
jmp    127a <sanitizeInput+0x14a>
mov    -0x10(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sanitizeInput>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%r14d
movslq %eax,%r15
add    %rbx,%r15
test   %ebp,%ebp
je     118d <sanitizeInput+0x6d>
lea    0xf1b(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strspn@plt>
xor    %ebp,%ebp
cmp    %r14d,%eax
je     11db <sanitizeInput+0xbb>
cltq
add    %rax,%rbx
xor    %ebp,%ebp
lea    0xefa(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
movb   $0x5f,(%rbx)
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strspn@plt>
cltq
add    %rax,%rbx
cmp    %r15,%rbx
jne    1170 <sanitizeInput+0x50>
jmp    11db <sanitizeInput+0xbb>
lea    0xe6c(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strspn@plt>
xor    %ebp,%ebp
cmp    %r14d,%eax
je     11db <sanitizeInput+0xbb>
cltq
add    %rax,%rbx
xor    %ebp,%ebp
lea    0xe4f(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x5f,(%rbx)
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strspn@plt>
cltq
add    %rax,%rbx
cmp    %r15,%rbx
jne    11c0 <sanitizeInput+0xa0>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.sanitizeInput.safe_buf_chars = [95 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ _,.-/@()*~`&^%$#!?<>'\22;:+=[]{}|1234567890\00"
@__const.sanitizeInput.safe_name_chars = [66 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ _-1234567890\00"
define i32 @sanitizeInput(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [95 x i8]
%7 = alloca [66 x i8]
%8 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%9 = bitcast [95 x i8]* %6 to i8*
%10 = bitcast [66 x i8]* %7 to i8*
%11 = load i8*, i8** %3
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
store i8* %15, i8** %8
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %41
18: ; preds = %2
%19 = load i8*, i8** %3
%20 = getelementptr inbounds [95 x i8], [95 x i8]* %6, i64 0, i64 0
%21 = call i32 @strspn(i8* %19, i8* %20)
%22 = load i8*, i8** %3
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds i8, i8* %22, i64 %23
store i8* %24, i8** %3
br label %25
25: ; preds = %33, %18
%26 = load i8*, i8** %3
%27 = load i8*, i8** %8
%28 = icmp ne i8* %26, %27
br i1 %28, label %29, label %40
29: ; preds = %25
%30 = load i8*, i8** %3
store i8 95, i8* %30
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %33
33: ; preds = %29
%34 = load i8*, i8** %3
%35 = getelementptr inbounds [95 x i8], [95 x i8]* %6, i64 0, i64 0
%36 = call i32 @strspn(i8* %34, i8* %35)
%37 = load i8*, i8** %3
%38 = sext i32 %36 to i64
%39 = getelementptr inbounds i8, i8* %37, i64 %38
store i8* %39, i8** %3
br label %25
40: ; preds = %25
br label %64
41: ; preds = %2
%42 = load i8*, i8** %3
%43 = getelementptr inbounds [66 x i8], [66 x i8]* %7, i64 0, i64 0
%44 = call i32 @strspn(i8* %42, i8* %43)
%45 = load i8*, i8** %3
%46 = sext i32 %44 to i64
%47 = getelementptr inbounds i8, i8* %45, i64 %46
store i8* %47, i8** %3
br label %48
48: ; preds = %56, %41
%49 = load i8*, i8** %3
%50 = load i8*, i8** %8
%51 = icmp ne i8* %49, %50
br i1 %51, label %52, label %63
52: ; preds = %48
%53 = load i8*, i8** %3
store i8 95, i8* %53
%54 = load i32, i32* %5
%55 = add nsw i32 %54, 1
store i32 %55, i32* %5
br label %56
56: ; preds = %52
%57 = load i8*, i8** %3
%58 = getelementptr inbounds [66 x i8], [66 x i8]* %7, i64 0, i64 0
%59 = call i32 @strspn(i8* %57, i8* %58)
%60 = load i8*, i8** %3
%61 = sext i32 %59 to i64
%62 = getelementptr inbounds i8, i8* %60, i64 %61
store i8* %62, i8** %3
br label %48
63: ; preds = %48
br label %64
64: ; preds = %63, %40
%65 = load i32, i32* %5
ret i32 %65
}

LLVM IR (-O2):
@__const.sanitizeInput.safe_buf_chars = [95 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ _,.-/@()*~`&^%$#!?<>'\22;:+=[]{}|1234567890\00"
@__const.sanitizeInput.safe_name_chars = [66 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ _-1234567890\00"
define i32 @sanitizeInput(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = icmp eq i32 %1, 0
br i1 %6, label %7, label %21
7: ; preds = %2
%8 = tail call i32 @strspn(i8* %0, i8* getelementptr inbounds ([95 x i8], [95 x i8]* @__const.sanitizeInput.safe_buf_chars, i64 0, i64 0))
%9 = icmp eq i32 %8, %3
br i1 %9, label %35, label %10
10: ; preds = %7
%11 = sext i32 %8 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
br label %13
13: ; preds = %10, %13
%14 = phi i8* [ %19, %13 ], [ %12, %10 ]
%15 = phi i32 [ %16, %13 ], [ 0, %10 ]
store i8 95, i8* %14
%16 = add nuw nsw i32 %15, 1
%17 = tail call i32 @strspn(i8* %14, i8* getelementptr inbounds ([95 x i8], [95 x i8]* @__const.sanitizeInput.safe_buf_chars, i64 0, i64 0))
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %14, i64 %18
%20 = icmp eq i8* %19, %5
br i1 %20, label %35, label %13
21: ; preds = %2
%22 = tail call i32 @strspn(i8* %0, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @__const.sanitizeInput.safe_name_chars, i64 0, i64 0))
%23 = icmp eq i32 %22, %3
br i1 %23, label %35, label %24
24: ; preds = %21
%25 = sext i32 %22 to i64
%26 = getelementptr inbounds i8, i8* %0, i64 %25
br label %27
27: ; preds = %24, %27
%28 = phi i8* [ %33, %27 ], [ %26, %24 ]
%29 = phi i32 [ %30, %27 ], [ 0, %24 ]
store i8 95, i8* %28
%30 = add nuw nsw i32 %29, 1
%31 = tail call i32 @strspn(i8* %28, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @__const.sanitizeInput.safe_name_chars, i64 0, i64 0))
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %28, i64 %32
%34 = icmp eq i8* %33, %5
br i1 %34, label %35, label %27
35: ; preds = %27, %13, %21, %7
%36 = phi i32 [ 0, %7 ], [ 0, %21 ], [ %16, %13 ], [ %30, %27 ]
ret i32 %36
}