#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*/ O_RDONLY;
char *calloc(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ free(char *);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int smack_new_label_from_self(char **label) {
  char *result;
  int fd;
  int ret;
  result = calloc(23 + 1, 1);
  if (result == NULL)
    return -1;
  fd = open("/proc/self/attr/current", O_RDONLY);
  if (fd < 0) {
    free(result);
    return -1;
  }
  ret = read(fd, result, 23);
  close(fd);
  if (ret < 0) {
    free(result);
    return -1;
  }
  *label = result;
  return 0;
}


x86 assembly (clang, -O0):
<smack_new_label_from_self>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x18,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1186 <smack_new_label_from_self+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <smack_new_label_from_self+0xba>
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
lea    0xe6a(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11bd <smack_new_label_from_self+0x6d>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <smack_new_label_from_self+0xba>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x17,%edx
call   1050 <read@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x0,-0x20(%rbp)
jge    11f8 <smack_new_label_from_self+0xa8>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <smack_new_label_from_self+0xba>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smack_new_label_from_self>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
mov    $0x18,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
je     11c1 <smack_new_label_from_self+0x71>
mov    %rax,%rbx
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11b9 <smack_new_label_from_self+0x69>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x17,%edx
call   1050 <read@plt>
mov    %eax,%r12d
mov    %ebp,%edi
call   1040 <close@plt>
test   %r12d,%r12d
js     11b9 <smack_new_label_from_self+0x69>
mov    %rbx,(%r14)
xor    %r15d,%r15d
jmp    11c1 <smack_new_label_from_self+0x71>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"/proc/self/attr/current\00"
@O_RDONLY = global i32 0
define i32 @smack_new_label_from_self(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8** %0, i8*** %3
%7 = call i8* @calloc(i32 24, i32 1)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %33
11: ; preds = %1
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = call i32 @free(i8* %17)
store i32 -1, i32* %2
br label %33
19: ; preds = %11
%20 = load i32, i32* %5
%21 = load i8*, i8** %4
%22 = call i32 @read(i32 %20, i8* %21, i32 23)
store i32 %22, i32* %6
%23 = load i32, i32* %5
%24 = call i32 @close(i32 %23)
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %19
%28 = load i8*, i8** %4
%29 = call i32 @free(i8* %28)
store i32 -1, i32* %2
br label %33
30: ; preds = %19
%31 = load i8*, i8** %4
%32 = load i8**, i8*** %3
store i8* %31, i8** %32
store i32 0, i32* %2
br label %33
33: ; preds = %30, %27, %16, %10
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@.str = [24 x i8] c"/proc/self/attr/current\00"
@O_RDONLY = global i32 0
define i32 @smack_new_label_from_self(i8** nocapture writeonly %0) {
%2 = tail call dereferenceable_or_null(24) i8* @calloc(i32 24, i32 1)
%3 = icmp eq i8* %2, null
br i1 %3, label %17, label %4
4: ; preds = %1
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @free(i8* %2)
br label %17
10: ; preds = %4
%11 = tail call i32 @read(i32 %6, i8* %2, i32 23)
%12 = tail call i32 @close(i32 %6)
%13 = icmp slt i32 %11, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 @free(i8* %2)
br label %17
16: ; preds = %10
store i8* %2, i8** %0
br label %17
17: ; preds = %1, %16, %14, %8
%18 = phi i32 [ -1, %8 ], [ -1, %14 ], [ 0, %16 ], [ -1, %1 ]
ret i32 %18
}