#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__ isalnum(char);
int strlen(char *);
void SanitizeFilename(char *filename) {
  int i;
  for (i = 0; i < strlen(filename); ++i) {
    if (!(isalnum(filename[i]) || (filename[i] == '.') ||
          (filename[i] == '\\') || (filename[i] == '/'))) {
      filename[i] = '_';
    }
  }
}


x86 assembly (clang, -O0):
<SanitizeFilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jge    11c8 <SanitizeFilename+0xa8>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%rax
jne    11b5 <SanitizeFilename+0x95>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     11b5 <SanitizeFilename+0x95>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
je     11b5 <SanitizeFilename+0x95>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     11b5 <SanitizeFilename+0x95>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x5f,(%rax,%rcx,1)
jmp    11ba <SanitizeFilename+0x9a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1133 <SanitizeFilename+0x13>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SanitizeFilename>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    1188 <SanitizeFilename+0x68>
xor    %ebx,%ebx
movabs $0x400000000003,%r15
jmp    1163 <SanitizeFilename+0x43>
movb   $0x5f,(%r14,%rbx,1)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    1188 <SanitizeFilename+0x68>
movsbl (%r14,%rbx,1),%edi
call   1040 <isalnum@plt>
test   %rax,%rax
jne    1150 <SanitizeFilename+0x30>
movzbl (%r14,%rbx,1),%eax
add    $0xd2,%al
cmp    $0x2e,%al
ja     113f <SanitizeFilename+0x1f>
movzbl %al,%eax
bt     %rax,%r15
jb     1150 <SanitizeFilename+0x30>
jmp    113f <SanitizeFilename+0x1f>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @SanitizeFilename(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
br label %4
4: ; preds = %47, %1
%5 = load i32, i32* %3
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = icmp slt i32 %5, %7
br i1 %8, label %9, label %50
9: ; preds = %4
%10 = load i8*, i8** %2
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = call i64 @isalnum(i8 signext %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %46, label %17
17: ; preds = %9
%18 = load i8*, i8** %2
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 46
br i1 %24, label %46, label %25
25: ; preds = %17
%26 = load i8*, i8** %2
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 92
br i1 %32, label %46, label %33
33: ; preds = %25
%34 = load i8*, i8** %2
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 47
br i1 %40, label %46, label %41
41: ; preds = %33
%42 = load i8*, i8** %2
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 95, i8* %45
br label %46
46: ; preds = %41, %33, %25, %17, %9
br label %47
47: ; preds = %46
%48 = load i32, i32* %3
%49 = add nsw i32 %48, 1
store i32 %49, i32* %3
br label %4
50: ; preds = %4
ret void
}

LLVM IR (-O2):
define void @SanitizeFilename(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %18
4: ; preds = %1, %13
%5 = phi i64 [ %14, %13 ], [ 0, %1 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = tail call i64 @isalnum(i8 signext %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %4
%11 = load i8, i8* %6
switch i8 %11, label %12 [
i8 46, label %13
i8 92, label %13
i8 47, label %13
]
12: ; preds = %10
store i8 95, i8* %6
br label %13
13: ; preds = %10, %10, %10, %4, %12
%14 = add nuw nsw i64 %5, 1
%15 = tail call i32 @strlen(i8* %0)
%16 = sext i32 %15 to i64
%17 = icmp slt i64 %14, %16
br i1 %17, label %4, label %18
18: ; preds = %13, %1
ret void
}