#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 */
int /*<<< orphan*/ dcl_entry(char *, int);
int /*<<< orphan*/ error(char *);
int get_symbol(char *, int *);
int set_symbol(char *, int);
int strlen(char *);
int set_label(char *name, int value, int checkflag) {
  int length, temp;
  if ((length = strlen(name)) == 0)
    error("internal error - null symbol name in set_label()");
  if (name[length - 1] == ':') {
    name[length - 1] = '\0';
    if (checkflag) {
      if (get_symbol(name, &temp) != -1)
        error("symbol already defined");
    }
    dcl_entry(name, value);
  }
  if (checkflag) {
    if (get_symbol(name, &temp) != -1)
      error("symbol already defined");
  }
  return set_symbol(name, value);
}


x86 assembly (clang, -O0):
<set_label>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    1183 <set_label+0x33>
lea    0xe82(%rip),%rdi
call   1060 <error@plt>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    11eb <set_label+0x9b>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x10(%rbp)
je     11df <set_label+0x8f>
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <get_symbol@plt>
cmp    $0xffffffff,%eax
je     11da <set_label+0x8a>
lea    0xe5c(%rip),%rdi
call   1060 <error@plt>
jmp    11df <set_label+0x8f>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <dcl_entry@plt>
cmpl   $0x0,-0x10(%rbp)
je     121c <set_label+0xcc>
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <get_symbol@plt>
cmp    $0xffffffff,%eax
je     1217 <set_label+0xc7>
lea    0xe1f(%rip),%rdi
call   1060 <error@plt>
jmp    121c <set_label+0xcc>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <set_symbol@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_label>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1177 <set_label+0x27>
lea    0xe8e(%rip),%rdi
call   1060 <error@plt>
movslq %ebp,%rax
cmpb   $0x3a,-0x1(%rax,%rbx,1)
jne    11b4 <set_label+0x64>
movb   $0x0,-0x1(%rbx,%rax,1)
test   %r15d,%r15d
je     11a9 <set_label+0x59>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <get_symbol@plt>
cmp    $0xffffffff,%eax
je     11a9 <set_label+0x59>
lea    0xe8d(%rip),%rdi
call   1060 <error@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1070 <dcl_entry@plt>
test   %r15d,%r15d
je     11d7 <set_label+0x87>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <get_symbol@plt>
cmp    $0xffffffff,%eax
je     11d7 <set_label+0x87>
lea    0xe5f(%rip),%rdi
call   1060 <error@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1040 <set_symbol@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [49 x i8] c"internal error - null symbol name in set_label()\00"
@.str.1 = [23 x i8] c"symbol already defined\00"
define i32 @set_label(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %7
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 @error(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %3
%15 = load i8*, i8** %4
%16 = load i32, i32* %7
%17 = sub nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 58
br i1 %22, label %23, label %42
23: ; preds = %14
%24 = load i8*, i8** %4
%25 = load i32, i32* %7
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
store i8 0, i8* %28
%29 = load i32, i32* %6
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %23
%32 = load i8*, i8** %4
%33 = call i32 @get_symbol(i8* %32, i32* %8)
%34 = icmp ne i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %31
br label %38
38: ; preds = %37, %23
%39 = load i8*, i8** %4
%40 = load i32, i32* %5
%41 = call i32 @dcl_entry(i8* %39, i32 %40)
br label %42
42: ; preds = %38, %14
%43 = load i32, i32* %6
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %52
45: ; preds = %42
%46 = load i8*, i8** %4
%47 = call i32 @get_symbol(i8* %46, i32* %8)
%48 = icmp ne i32 %47, -1
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %51
51: ; preds = %49, %45
br label %52
52: ; preds = %51, %42
%53 = load i8*, i8** %4
%54 = load i32, i32* %5
%55 = call i32 @set_symbol(i8* %53, i32 %54)
ret i32 %55
}

LLVM IR (-O2):
@.str = [49 x i8] c"internal error - null symbol name in set_label()\00"
@.str.1 = [23 x i8] c"symbol already defined\00"
define i32 @set_label(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @error(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %3
%11 = add nsw i32 %6, -1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 58
br i1 %15, label %16, label %25
16: ; preds = %10
store i8 0, i8* %13
%17 = icmp eq i32 %2, 0
br i1 %17, label %23, label %18
18: ; preds = %16
%19 = call i32 @get_symbol(i8* %0, i32* %4)
%20 = icmp eq i32 %19, -1
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %18, %21, %16
%24 = call i32 @dcl_entry(i8* %0, i32 %1)
br label %25
25: ; preds = %23, %10
%26 = icmp eq i32 %2, 0
br i1 %26, label %32, label %27
27: ; preds = %25
%28 = call i32 @get_symbol(i8* %0, i32* %4)
%29 = icmp eq i32 %28, -1
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %27, %30, %25
%33 = call i32 @set_symbol(i8* %0, i32 %1)
ret i32 %33
}