#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(int);
scalar_t__ isalpha(int);
int /*<<< orphan*/ putchar(char);
void emit_name(const char *name) {
  int ch = *name;
  if (!ch) {
    putchar('_');
    return;
  }
  if (isalpha(ch))
    putchar(ch);
  else
    putchar('_');
  for (;;) {
    ch = *++name;
    if (!ch)
      return;
    if (isalnum(ch))
      putchar(ch);
    else
      putchar('_');
  }
}


x86 assembly (clang, -O0):
<emit_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    115f <emit_name+0x2f>
mov    $0x5f,%edi
call   1030 <putchar@plt>
jmp    11e6 <emit_name+0xb6>
mov    -0xc(%rbp),%edi
call   1050 <isalpha@plt>
cmp    $0x0,%rax
je     1181 <emit_name+0x51>
mov    -0xc(%rbp),%eax
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    118b <emit_name+0x5b>
mov    $0x5f,%edi
call   1030 <putchar@plt>
jmp    1190 <emit_name+0x60>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl 0x1(%rax),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11b5 <emit_name+0x85>
jmp    11e6 <emit_name+0xb6>
mov    -0xc(%rbp),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%rax
je     11d7 <emit_name+0xa7>
mov    -0xc(%rbp),%eax
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    11e1 <emit_name+0xb1>
mov    $0x5f,%edi
call   1030 <putchar@plt>
jmp    1190 <emit_name+0x60>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emit_name>:
push   %rbp
push   %r14
push   %rbx
movsbl (%rdi),%ebp
test   %ebp,%ebp
je     119d <emit_name+0x6d>
mov    %rdi,%rbx
mov    %ebp,%edi
call   1050 <isalpha@plt>
test   %rax,%rax
mov    $0x5f,%r14d
cmove  %r14d,%ebp
mov    %ebp,%edi
call   1030 <putchar@plt>
mov    0x1(%rbx),%al
test   %al,%al
je     1198 <emit_name+0x68>
add    $0x2,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl %al,%ebp
mov    %ebp,%edi
call   1040 <isalnum@plt>
test   %rax,%rax
movzbl %bpl,%eax
cmove  %r14d,%eax
movsbl %al,%edi
call   1030 <putchar@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1170 <emit_name+0x40>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0x5f,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
define void @emit_name(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @putchar(i8 signext 95)
br label %26
6: ; preds = %1
%7 = sext i8 %2 to i32
%8 = tail call i64 @isalpha(i32 %7)
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i8 95, i8 %2
%11 = tail call i32 @putchar(i8 signext %10)
%12 = getelementptr inbounds i8, i8* %0, i64 1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %26, label %15
15: ; preds = %6, %15
%16 = phi i8 [ %24, %15 ], [ %13, %6 ]
%17 = phi i8* [ %23, %15 ], [ %12, %6 ]
%18 = sext i8 %16 to i32
%19 = tail call i64 @isalnum(i32 %18)
%20 = icmp eq i64 %19, 0
%21 = select i1 %20, i8 95, i8 %16
%22 = tail call i32 @putchar(i8 signext %21)
%23 = getelementptr inbounds i8, i8* %17, i64 1
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %26, label %15
26: ; preds = %15, %6, %4
ret void
}