#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 *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int strlen(char *);
char *get_symbol_name_prefix(char *original) {
  char *prefix = "_binary__";
  char *r = malloc(strlen(prefix) + strlen(original) + 1);
  sprintf(r, "%s%s", prefix, original);
  for (int i = 0; i < strlen(r); i++) {
    if (r[i] == '/') {
      r[i] = '_';
    }
  }
  return r;
}


x86 assembly (clang, -O0):
<get_symbol_name_prefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xebd(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe8a(%rip),%rsi
call   1050 <sprintf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    11dc <get_symbol_name_prefix+0xac>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11c9 <get_symbol_name_prefix+0x99>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x5f,(%rax,%rcx,1)
jmp    11ce <get_symbol_name_prefix+0x9e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118c <get_symbol_name_prefix+0x5c>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_symbol_name_prefix>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xebe(%rip),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,%r12
lea    0xea1(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1050 <sprintf@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11b1 <get_symbol_name_prefix+0x81>
xor    %ebx,%ebx
jmp    11a3 <get_symbol_name_prefix+0x73>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %r12,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11b1 <get_symbol_name_prefix+0x81>
cmpb   $0x2f,(%r12,%rbx,1)
jne    1190 <get_symbol_name_prefix+0x60>
movb   $0x5f,(%r12,%rbx,1)
jmp    1190 <get_symbol_name_prefix+0x60>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"_binary__\00"
@.str.1 = [5 x i8] c"%s%s\00"
define i8* @get_symbol_name_prefix(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %7, %9
%11 = add nsw i32 %10, 1
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = load i8*, i8** %3
%15 = load i8*, i8** %2
%16 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* %15)
store i32 0, i32* %5
br label %17
17: ; preds = %36, %1
%18 = load i32, i32* %5
%19 = load i8*, i8** %4
%20 = call i32 @strlen(i8* %19)
%21 = icmp slt i32 %18, %20
br i1 %21, label %22, label %39
22: ; preds = %17
%23 = load i8*, i8** %4
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 47
br i1 %29, label %30, label %35
30: ; preds = %22
%31 = load i8*, i8** %4
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 95, i8* %34
br label %35
35: ; preds = %30, %22
br label %36
36: ; preds = %35
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %17
39: ; preds = %17
%40 = load i8*, i8** %4
ret i8* %40
}

LLVM IR (-O2):
@.str = [10 x i8] c"_binary__\00"
@.str.1 = [5 x i8] c"%s%s\00"
define i8* @get_symbol_name_prefix(i8* %0) {
%2 = tail call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @strlen(i8* %0)
%4 = add i32 %2, 1
%5 = add i32 %4, %3
%6 = tail call i8* @malloc(i32 %5)
%7 = tail call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = tail call i32 @strlen(i8* %6)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %17, %1
ret i8* %6
11: ; preds = %1, %17
%12 = phi i64 [ %18, %17 ], [ 0, %1 ]
%13 = getelementptr inbounds i8, i8* %6, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 47
br i1 %15, label %16, label %17
16: ; preds = %11
store i8 95, i8* %13
br label %17
17: ; preds = %11, %16
%18 = add nuw nsw i64 %12, 1
%19 = tail call i32 @strlen(i8* %6)
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %18, %20
br i1 %21, label %11, label %10
}