#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 */
typedef int /*<<< orphan*/ uint64_t;
struct label {
  int dummy;
};
typedef int /*<<< orphan*/ label;

/* Variables and functions */
int create_section_label_name(char *, int, char const *, char const *);
int l_append(struct label *, char *, int /*<<< orphan*/);
struct label *l_find(struct label *, char *);
int add_section_label(struct label *l, const char *name, const char *attribute,
                      uint64_t value, struct label **length) {
  char label[255];
  int errcode;
  errcode = create_section_label_name(label, sizeof(label), name, attribute);
  if (errcode < 0)
    return errcode;
  errcode = l_append(l, label, value);
  if (errcode < 0)
    return errcode;
  if (length)
    *length = l_find(l, label);
  return 0;
}


x86 assembly (clang, -O0):
<add_section_label>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0xff,%esi
call   1040 <create_section_label_name@plt>
mov    %eax,-0x134(%rbp)
cmpl   $0x0,-0x134(%rbp)
jge    1188 <add_section_label+0x58>
mov    -0x134(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e8 <add_section_label+0xb8>
mov    -0x10(%rbp),%rdi
lea    -0x130(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <l_append@plt>
mov    %eax,-0x134(%rbp)
cmpl   $0x0,-0x134(%rbp)
jge    11bc <add_section_label+0x8c>
mov    -0x134(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e8 <add_section_label+0xb8>
cmpq   $0x0,-0x30(%rbp)
je     11e1 <add_section_label+0xb1>
mov    -0x10(%rbp),%rdi
lea    -0x130(%rbp),%rsi
call   1030 <l_find@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_section_label>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %r8,%r14
mov    %ecx,%ebx
mov    %rdx,%rcx
mov    %rsi,%rdx
mov    %rdi,%r15
mov    %rsp,%rdi
mov    $0xff,%esi
call   1040 <create_section_label_name@plt>
test   %eax,%eax
js     1184 <add_section_label+0x54>
mov    %rsp,%rsi
mov    %r15,%rdi
mov    %ebx,%edx
call   1050 <l_append@plt>
test   %eax,%eax
js     1184 <add_section_label+0x54>
xor    %ebp,%ebp
test   %r14,%r14
je     1186 <add_section_label+0x56>
mov    %rsp,%rsi
mov    %r15,%rdi
call   1030 <l_find@plt>
mov    %rax,(%r14)
jmp    1186 <add_section_label+0x56>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.label = type { i32 }
define i32 @add_section_label(%struct.label* %0, i8* %1, i8* %2, i32 %3, %struct.label** %4) {
%6 = alloca i32
%7 = alloca %struct.label*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca %struct.label**
%12 = alloca [255 x i8]
%13 = alloca i32
store %struct.label* %0, %struct.label** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store %struct.label** %4, %struct.label*** %11
%14 = getelementptr inbounds [255 x i8], [255 x i8]* %12, i64 0, i64 0
%15 = load i8*, i8** %8
%16 = load i8*, i8** %9
%17 = call i32 @create_section_label_name(i8* %14, i32 255, i8* %15, i8* %16)
store i32 %17, i32* %13
%18 = load i32, i32* %13
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %5
%21 = load i32, i32* %13
store i32 %21, i32* %6
br label %40
22: ; preds = %5
%23 = load %struct.label*, %struct.label** %7
%24 = getelementptr inbounds [255 x i8], [255 x i8]* %12, i64 0, i64 0
%25 = load i32, i32* %10
%26 = call i32 @l_append(%struct.label* %23, i8* %24, i32 %25)
store i32 %26, i32* %13
%27 = load i32, i32* %13
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = load i32, i32* %13
store i32 %30, i32* %6
br label %40
31: ; preds = %22
%32 = load %struct.label**, %struct.label*** %11
%33 = icmp ne %struct.label** %32, null
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load %struct.label*, %struct.label** %7
%36 = getelementptr inbounds [255 x i8], [255 x i8]* %12, i64 0, i64 0
%37 = call %struct.label* @l_find(%struct.label* %35, i8* %36)
%38 = load %struct.label**, %struct.label*** %11
store %struct.label* %37, %struct.label** %38
br label %39
39: ; preds = %34, %31
store i32 0, i32* %6
br label %40
40: ; preds = %39, %29, %20
%41 = load i32, i32* %6
ret i32 %41
}

LLVM IR (-O2):
%struct.label = type { i32 }
define i32 @add_section_label(%struct.label* %0, i8* %1, i8* %2, i32 %3, %struct.label** writeonly %4) {
%6 = alloca [255 x i8]
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%8 = call i32 @create_section_label_name(i8* %7, i32 255, i8* %1, i8* %2)
%9 = icmp slt i32 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %5
%11 = call i32 @l_append(%struct.label* %0, i8* %7, i32 %3)
%12 = icmp slt i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = icmp eq %struct.label** %4, null
br i1 %14, label %17, label %15
15: ; preds = %13
%16 = call %struct.label* @l_find(%struct.label* %0, i8* %7)
store %struct.label* %16, %struct.label** %4
br label %17
17: ; preds = %13, %15, %10, %5
%18 = phi i32 [ %8, %5 ], [ %11, %10 ], [ 0, %15 ], [ 0, %13 ]
ret i32 %18
}