#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 */
char *Alloc(unsigned int);
scalar_t__ strlen(char *);
char *Name2Symbol(char *name) {
  char *base, *dst;
  char c;
  base = dst = Alloc((unsigned)(strlen(name) + 10));
  *dst++ = 's';
  *dst++ = '_';
  while ((c = *name++) != '\0') {
    if (c == '-')
      c = '_';
    *dst++ = c;
  }
  *dst++ = '_';
  *dst++ = '_';
  *dst = '\0';
  return base;
}


x86 assembly (clang, -O0):
<Name2Symbol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0xa,%rax
mov    %eax,%edi
call   1030 <Alloc@plt>
mov    %rax,-0x18(%rbp)
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x73,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5f,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     11b6 <Name2Symbol+0x96>
movsbl -0x19(%rbp),%eax
cmp    $0x2d,%eax
jne    119d <Name2Symbol+0x7d>
movb   $0x5f,-0x19(%rbp)
mov    -0x19(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    116c <Name2Symbol+0x4c>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5f,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5f,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Name2Symbol>:
push   %rbx
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    0xa(%rax),%edi
call   1030 <Alloc@plt>
movw   $0x5f73,(%rax)
mov    %rax,%rcx
add    $0x2,%rcx
mov    (%rbx),%dl
test   %dl,%dl
je     116a <Name2Symbol+0x4a>
add    $0x1,%rbx
mov    $0x5f,%esi
nopl   0x0(%rax)
cmp    $0x2d,%dl
movzbl %dl,%edx
cmove  %esi,%edx
mov    %dl,(%rcx)
add    $0x1,%rcx
movzbl (%rbx),%edx
add    $0x1,%rbx
test   %dl,%dl
jne    1150 <Name2Symbol+0x30>
movw   $0x5f5f,(%rcx)
movb   $0x0,0x2(%rcx)
pop    %rbx
ret

LLVM IR (-O0):
define i8* @Name2Symbol(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
%8 = add nsw i64 %7, 10
%9 = trunc i64 %8 to i32
%10 = call i8* @Alloc(i32 %9)
store i8* %10, i8** %4
store i8* %10, i8** %3
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %4
store i8 115, i8* %11
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %4
store i8 95, i8* %13
br label %15
15: ; preds = %26, %1
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %2
%18 = load i8, i8* %16
store i8 %18, i8* %5
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %15
%22 = load i8, i8* %5
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 45
br i1 %24, label %25, label %26
25: ; preds = %21
store i8 95, i8* %5
br label %26
26: ; preds = %25, %21
%27 = load i8, i8* %5
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %4
store i8 %27, i8* %28
br label %15
30: ; preds = %15
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %4
store i8 95, i8* %31
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %4
store i8 95, i8* %33
%35 = load i8*, i8** %4
store i8 0, i8* %35
%36 = load i8*, i8** %3
ret i8* %36
}

LLVM IR (-O2):
define i8* @Name2Symbol(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = trunc i64 %2 to i32
%4 = add i32 %3, 10
%5 = tail call i8* @Alloc(i32 %4)
%6 = getelementptr inbounds i8, i8* %5, i64 1
store i8 115, i8* %5
%7 = getelementptr inbounds i8, i8* %5, i64 2
store i8 95, i8* %6
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 0
br i1 %9, label %20, label %10
10: ; preds = %1, %10
%11 = phi i8 [ %18, %10 ], [ %8, %1 ]
%12 = phi i8* [ %17, %10 ], [ %7, %1 ]
%13 = phi i8* [ %14, %10 ], [ %0, %1 ]
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = icmp eq i8 %11, 45
%16 = select i1 %15, i8 95, i8 %11
%17 = getelementptr inbounds i8, i8* %12, i64 1
store i8 %16, i8* %12
%18 = load i8, i8* %14
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %10
20: ; preds = %10, %1
%21 = phi i8* [ %7, %1 ], [ %17, %10 ]
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8 95, i8* %21
%23 = getelementptr inbounds i8, i8* %21, i64 2
store i8 95, i8* %22
store i8 0, i8* %23
ret i8* %5
}