#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 MB_CUR_MAX;
int /*<<< orphan*/ free(char *);
char *mb_clean_name(char *);
size_t strcspn(char *, char *);
char *clean_name(char *src, bool mb_src) {
  if (mb_src && (MB_CUR_MAX > 1)) {
    char *cleaned = mb_clean_name(src);
    free(src);
    return cleaned;
  }
  char *c = src;
  while (*c) {
    size_t good = strcspn(c, " /:?\\");
    if (good)
      c += good;
    else
      *c++ = '-';
  }
  return src;
}


x86 assembly (clang, -O0):
<clean_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     117c <clean_name+0x4c>
mov    0x2ea8(%rip),%rax
cmpl   $0x1,(%rax)
jle    117c <clean_name+0x4c>
mov    -0x10(%rbp),%rdi
call   1050 <mb_clean_name@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e0 <clean_name+0xb0>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d8 <clean_name+0xa8>
mov    -0x28(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1040 <strcspn@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11c1 <clean_name+0x91>
mov    -0x30(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11d3 <clean_name+0xa3>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x2d,(%rax)
jmp    1184 <clean_name+0x54>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clean_name>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
test   %esi,%esi
je     1160 <clean_name+0x30>
mov    0x2eb5(%rip),%rax
cmpl   $0x1,(%rax)
jle    1160 <clean_name+0x30>
mov    %r14,%rdi
call   1050 <mb_clean_name@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
jmp    11a7 <clean_name+0x77>
cmpb   $0x0,(%r14)
je     11a4 <clean_name+0x74>
lea    0xe93(%rip),%r15
mov    %r14,%rbx
jmp    118c <clean_name+0x5c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x2d,(%rbx)
add    $0x1,%rbx
cmpb   $0x0,(%rbx)
je     11a4 <clean_name+0x74>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcspn@plt>
test   %rax,%rax
je     1180 <clean_name+0x50>
add    %rax,%rbx
cmpb   $0x0,(%rbx)
jne    118c <clean_name+0x5c>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@MB_CUR_MAX = global i32 0
@.str = [6 x i8] c" /:?\\\00"
define i8* @clean_name(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %2
%12 = load i32, i32* @MB_CUR_MAX
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i8*, i8** %4
%16 = call i8* @mb_clean_name(i8* %15)
store i8* %16, i8** %6
%17 = load i8*, i8** %4
%18 = call i32 @free(i8* %17)
%19 = load i8*, i8** %6
store i8* %19, i8** %3
br label %41
20: ; preds = %11, %2
%21 = load i8*, i8** %4
store i8* %21, i8** %7
br label %22
22: ; preds = %38, %20
%23 = load i8*, i8** %7
%24 = load i8, i8* %23
%25 = icmp ne i8 %24, 0
br i1 %25, label %26, label %39
26: ; preds = %22
%27 = load i8*, i8** %7
%28 = call i64 @strcspn(i8* %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i64 %28, i64* %8
%29 = load i64, i64* %8
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = load i64, i64* %8
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i64 %32
store i8* %34, i8** %7
br label %38
35: ; preds = %26
%36 = load i8*, i8** %7
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %7
store i8 45, i8* %36
br label %38
38: ; preds = %35, %31
br label %22
39: ; preds = %22
%40 = load i8*, i8** %4
store i8* %40, i8** %3
br label %41
41: ; preds = %39, %14
%42 = load i8*, i8** %3
ret i8* %42
}

LLVM IR (-O2):
@MB_CUR_MAX = global i32 0
@.str = [6 x i8] c" /:?\\\00"
define i8* @clean_name(i8* %0, i32 %1) {
%3 = icmp ne i32 %1, 0
%4 = load i32, i32* @MB_CUR_MAX
%5 = icmp sgt i32 %4, 1
%6 = select i1 %3, i1 %5, i1 false
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 0
br i1 %9, label %25, label %13
10: ; preds = %2
%11 = tail call i8* @mb_clean_name(i8* %0)
%12 = tail call i32 @free(i8* %0)
br label %25
13: ; preds = %7, %21
%14 = phi i8* [ %22, %21 ], [ %0, %7 ]
%15 = tail call i64 @strcspn(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = getelementptr inbounds i8, i8* %14, i64 %15
br label %21
19: ; preds = %13
%20 = getelementptr inbounds i8, i8* %14, i64 1
store i8 45, i8* %14
br label %21
21: ; preds = %19, %17
%22 = phi i8* [ %18, %17 ], [ %20, %19 ]
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %13
25: ; preds = %21, %7, %10
%26 = phi i8* [ %11, %10 ], [ %0, %7 ], [ %0, %21 ]
ret i8* %26
}