#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 const *const, char);
void _dbx_sanitize_filename(char *filename) {
  char *c = NULL;
  static const char *const invalid_characters = "\\/?\"<>*|:";
  static const char valid_char = '_';
  if (!filename)
    return;
  for (c = filename; *c; c++)
    if ((unsigned char)*c < 32 || strchr(invalid_characters, *c))
      *c = valid_char;
}


x86 assembly (clang, -O0):
<_dbx_sanitize_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1134 <_dbx_sanitize_filename+0x24>
jmp    1193 <_dbx_sanitize_filename+0x83>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1193 <_dbx_sanitize_filename+0x83>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x20,%eax
jl     1176 <_dbx_sanitize_filename+0x66>
mov    -0x10(%rbp),%rax
lea    0xe9c(%rip),%rdi
movsbl (%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     117d <_dbx_sanitize_filename+0x6d>
mov    -0x10(%rbp),%rax
movb   $0x5f,(%rax)
jmp    1182 <_dbx_sanitize_filename+0x72>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    113c <_dbx_sanitize_filename+0x2c>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_dbx_sanitize_filename>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1155 <_dbx_sanitize_filename+0x45>
mov    %rdi,%rbx
mov    (%rdi),%al
test   %al,%al
je     1155 <_dbx_sanitize_filename+0x45>
add    $0x1,%rbx
lea    0xed3(%rip),%r14
jmp    113f <_dbx_sanitize_filename+0x2f>
nop
movb   $0x5f,-0x1(%rbx)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1155 <_dbx_sanitize_filename+0x45>
cmp    $0x20,%al
jb     1130 <_dbx_sanitize_filename+0x20>
movsbl %al,%esi
mov    %r14,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1130 <_dbx_sanitize_filename+0x20>
jmp    1134 <_dbx_sanitize_filename+0x24>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@_dbx_sanitize_filename.invalid_characters = internal constant i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0)
@.str = [10 x i8] c"\\/?\22<>*|:\00"
@_dbx_sanitize_filename.valid_char = internal constant i8 95
define void @_dbx_sanitize_filename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %3
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %7, label %6
6: ; preds = %1
br label %29
7: ; preds = %1
%8 = load i8*, i8** %2
store i8* %8, i8** %3
br label %9
9: ; preds = %26, %7
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %29
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = icmp slt i32 %16, 32
br i1 %17, label %23, label %18
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = load i8, i8* %19
%21 = call i64 @strchr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8 signext %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18, %13
%24 = load i8*, i8** %3
store i8 95, i8* %24
br label %25
25: ; preds = %23, %18
br label %26
26: ; preds = %25
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %3
br label %9
29: ; preds = %6, %9
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"\\/?\22<>*|:\00"
define void @_dbx_sanitize_filename(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %18, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %3, %14
%7 = phi i8 [ %16, %14 ], [ %4, %3 ]
%8 = phi i8* [ %15, %14 ], [ %0, %3 ]
%9 = icmp ult i8 %7, 32
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = tail call i64 @strchr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8 signext %7)
%12 = icmp eq i64 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %10, %6
store i8 95, i8* %8
br label %14
14: ; preds = %10, %13
%15 = getelementptr inbounds i8, i8* %8, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %6
18: ; preds = %14, %3, %1
ret void
}