#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);
scalar_t__ isascii(char);
int strlen(char *);
char *cify_name(char *name) {
  int length = name ? strlen(name) : 0;
  int i;
  for (i = 0; i < length; i++) {
    char c = name[i];
    if (!((isascii(c) && isalnum(c)) || c == '_'))
      name[i] = '_';
  }
  return name;
}


x86 assembly (clang, -O0):
<cify_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1158 <cify_name+0x28>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
jmp    1162 <cify_name+0x32>
xor    %eax,%eax
mov    %eax,-0x18(%rbp)
jmp    1162 <cify_name+0x32>
mov    -0x18(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11db <cify_name+0xab>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%edi
call   1050 <isascii@plt>
cmp    $0x0,%rax
je     11af <cify_name+0x7f>
movsbl -0x11(%rbp),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%rax
jne    11c8 <cify_name+0x98>
movsbl -0x11(%rbp),%eax
cmp    $0x5f,%eax
je     11c8 <cify_name+0x98>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x5f,(%rax,%rcx,1)
jmp    11cd <cify_name+0x9d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116f <cify_name+0x3f>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cify_name>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
test   %rdi,%rdi
je     11a8 <cify_name+0x78>
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11a8 <cify_name+0x78>
mov    %eax,%r14d
xor    %ebx,%ebx
jmp    116e <cify_name+0x3e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x5f,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r14
je     11a8 <cify_name+0x78>
movzbl (%r15,%rbx,1),%r12d
movsbl %r12b,%ebp
mov    %ebp,%edi
call   1050 <isascii@plt>
test   %rax,%rax
je     11a0 <cify_name+0x70>
mov    %ebp,%edi
call   1040 <isalnum@plt>
cmp    $0x5f,%bpl
je     1165 <cify_name+0x35>
test   %rax,%rax
je     1160 <cify_name+0x30>
jmp    1165 <cify_name+0x35>
nopw   0x0(%rax,%rax,1)
cmp    $0x5f,%r12b
jne    1160 <cify_name+0x30>
jmp    1165 <cify_name+0x35>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @cify_name(i8* returned %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %25, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %25
6: ; preds = %3
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %6, %22
%9 = phi i64 [ 0, %6 ], [ %23, %22 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = tail call i64 @isascii(i8 signext %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %8
%15 = tail call i64 @isalnum(i8 signext %11)
%16 = icmp ne i64 %15, 0
%17 = icmp eq i8 %11, 95
%18 = or i1 %17, %16
br i1 %18, label %22, label %21
19: ; preds = %8
%20 = icmp eq i8 %11, 95
br i1 %20, label %22, label %21
21: ; preds = %14, %19
store i8 95, i8* %10
br label %22
22: ; preds = %21, %19, %14
%23 = add nuw nsw i64 %9, 1
%24 = icmp eq i64 %23, %7
br i1 %24, label %25, label %8
25: ; preds = %22, %1, %3
ret i8* %0
}