#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 *calloc(int, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int strlen(char *);
char *labelalloc(char *name) {
  char *buf;
  int i;
  if (name[0] == '%') {
    buf = calloc(strlen(name) + 1 + 8, 1);
    sprintf(buf, "__label_%s", &name[1]);
  } else {
    buf = calloc(strlen(name) + 1 + 8, 1);
    sprintf(buf, "__label_%s", name);
  }
  for (i = 0; i < strlen(buf); i++) {
    if (buf[i] == '.')
      buf[i] = '_';
  }
  return buf;
}


x86 assembly (clang, -O0):
<labelalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    1188 <labelalloc+0x58>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
add    $0x8,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
add    $0x1,%rdx
lea    0xe82(%rip),%rsi
call   1050 <sprintf@plt>
jmp    11bb <labelalloc+0x8b>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
add    $0x8,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe4a(%rip),%rsi
call   1050 <sprintf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    1212 <labelalloc+0xe2>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    11ff <labelalloc+0xcf>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x5f,(%rax,%rcx,1)
jmp    1204 <labelalloc+0xd4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c2 <labelalloc+0x92>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<labelalloc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %r15d,%r15d
cmpb   $0x25,(%rdi)
sete   %r15b
call   1030 <strlen@plt>
lea    0x9(%rax),%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%r12
add    %r14,%r15
lea    0xe9c(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
call   1050 <sprintf@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11a1 <labelalloc+0x71>
xor    %ebx,%ebx
jmp    1193 <labelalloc+0x63>
nop
add    $0x1,%rbx
mov    %r12,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11a1 <labelalloc+0x71>
cmpb   $0x2e,(%r12,%rbx,1)
jne    1180 <labelalloc+0x50>
movb   $0x5f,(%r12,%rbx,1)
jmp    1180 <labelalloc+0x50>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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