#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*/ isalnum(char);
int /*<<< orphan*/ isalpha(char);
char *strdup(char *);
scalar_t__ strrchr(char const *, char);
char *id(const char *s) {
  char *r;
  char *b = (char *)strrchr(s, '/');
  if (!b)
    b = (char *)strrchr(s, '\\');
  if (!b)
    b = (char *)s;
  else
    ++b;
  b = strdup(b);
  r = b;
  while (*r) {
    if (!isalnum(*r)) {
      *r = '_';
    }
    ++r;
  }
  if (!isalpha(*b)) {
    *b = '_';
  }
  return b;
}


x86 assembly (clang, -O0):
<id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117b <id+0x3b>
mov    -0x8(%rbp),%rdi
mov    $0x5c,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1193 <id+0x53>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    119f <id+0x5f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ee <id+0xae>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%eax
jne    11dd <id+0x9d>
mov    -0x10(%rbp),%rax
movb   $0x5f,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11b4 <id+0x74>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isalpha@plt>
cmp    $0x0,%eax
jne    120a <id+0xca>
mov    -0x18(%rbp),%rax
movb   $0x5f,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<id>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
jne    1163 <id+0x23>
mov    %rbx,%rdi
mov    $0x5c,%esi
call   1040 <strrchr@plt>
lea    0x1(%rax),%rdi
test   %rax,%rax
cmove  %rbx,%rdi
call   1060 <strdup@plt>
mov    %rax,%r14
mov    (%rax),%al
test   %al,%al
je     11b2 <id+0x72>
mov    %r14,%rbx
add    $0x1,%rbx
jmp    119b <id+0x5b>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11ad <id+0x6d>
movsbl %al,%edi
call   1030 <isalnum@plt>
test   %eax,%eax
jne    1190 <id+0x50>
movb   $0x5f,-0x1(%rbx)
jmp    1190 <id+0x50>
mov    (%r14),%al
jmp    11b4 <id+0x74>
xor    %eax,%eax
movsbl %al,%edi
call   1050 <isalpha@plt>
test   %eax,%eax
jne    11c4 <id+0x84>
movb   $0x5f,(%r14)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define noalias i8* @id(i8* %0) {
%2 = tail call i64 @strrchr(i8* %0, i8 signext 47)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i64 @strrchr(i8* %0, i8 signext 92)
br label %6
6: ; preds = %4, %1
%7 = phi i64 [ %2, %1 ], [ %5, %4 ]
%8 = icmp eq i64 %7, 0
%9 = inttoptr i64 %7 to i8*
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = select i1 %8, i8* %0, i8* %10
%12 = tail call i8* @strdup(i8* %11)
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %27, label %15
15: ; preds = %6, %21
%16 = phi i8 [ %23, %21 ], [ %13, %6 ]
%17 = phi i8* [ %22, %21 ], [ %12, %6 ]
%18 = tail call i32 @isalnum(i8 signext %16)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
store i8 95, i8* %17
br label %21
21: ; preds = %20, %15
%22 = getelementptr inbounds i8, i8* %17, i64 1
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %15
25: ; preds = %21
%26 = load i8, i8* %12
br label %27
27: ; preds = %25, %6
%28 = phi i8 [ %26, %25 ], [ 0, %6 ]
%29 = tail call i32 @isalpha(i8 signext %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
store i8 95, i8* %12
br label %32
32: ; preds = %31, %27
ret i8* %12
}