#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
char *calloc(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ free(char *);
int get_label(char *, char *, int /*<<< orphan*/ *);
int open(char const *, int /*<<< orphan*/);
int read(int, char *, int);
ssize_t smack_new_label_from_proc(const char *proc_path, char **label) {
  char buf[255 + 1];
  char *result;
  int fd;
  int ret;
  fd = open(proc_path, O_RDONLY);
  if (fd < 0)
    return -1;
  ret = read(fd, buf, 255);
  close(fd);
  if (ret < 0)
    return -1;
  buf[ret] = '\0';
  result = calloc(ret + 1, 1);
  if (result == NULL)
    return -1;
  ret = get_label(result, buf, NULL);
  if (ret < 0) {
    free(result);
    return -1;
  }
  *label = result;
  return ret;
}


x86 assembly (clang, -O0):
<smack_new_label_from_proc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x12c(%rbp)
cmpl   $0x0,-0x12c(%rbp)
jge    11a4 <smack_new_label_from_proc+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    1281 <smack_new_label_from_proc+0x121>
mov    -0x12c(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0xff,%edx
call   1050 <read@plt>
mov    %eax,-0x130(%rbp)
mov    -0x12c(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x0,-0x130(%rbp)
jge    11e5 <smack_new_label_from_proc+0x85>
movl   $0xffffffff,-0x4(%rbp)
jmp    1281 <smack_new_label_from_proc+0x121>
movslq -0x130(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
mov    -0x130(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    1228 <smack_new_label_from_proc+0xc8>
movl   $0xffffffff,-0x4(%rbp)
jmp    1281 <smack_new_label_from_proc+0x121>
mov    -0x128(%rbp),%rdi
lea    -0x120(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1080 <get_label@plt>
mov    %eax,-0x130(%rbp)
cmpl   $0x0,-0x130(%rbp)
jge    126a <smack_new_label_from_proc+0x10a>
mov    -0x128(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1281 <smack_new_label_from_proc+0x121>
mov    -0x128(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x130(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smack_new_label_from_proc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r14
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    $0xffffffff,%r15d
test   %eax,%eax
js     11e4 <smack_new_label_from_proc+0x84>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0xff,%edx
call   1050 <read@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
test   %ebp,%ebp
js     11e4 <smack_new_label_from_proc+0x84>
mov    %ebp,%eax
movb   $0x0,(%rsp,%rax,1)
add    $0x1,%ebp
mov    %ebp,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
test   %rax,%rax
je     11e4 <smack_new_label_from_proc+0x84>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1080 <get_label@plt>
test   %eax,%eax
js     11dc <smack_new_label_from_proc+0x7c>
mov    %rbx,(%r14)
mov    %eax,%r15d
jmp    11e4 <smack_new_label_from_proc+0x84>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15d,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i32 @smack_new_label_from_proc(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
%10 = load i8*, i8** %4
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %48
16: ; preds = %2
%17 = load i32, i32* %8
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%19 = call i32 @read(i32 %17, i8* %18, i32 255)
store i32 %19, i32* %9
%20 = load i32, i32* %8
%21 = call i32 @close(i32 %20)
%22 = load i32, i32* %9
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %16
store i32 -1, i32* %3
br label %48
25: ; preds = %16
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %27
store i8 0, i8* %28
%29 = load i32, i32* %9
%30 = add nsw i32 %29, 1
%31 = call i8* @calloc(i32 %30, i32 1)
store i8* %31, i8** %7
%32 = load i8*, i8** %7
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %35
34: ; preds = %25
store i32 -1, i32* %3
br label %48
35: ; preds = %25
%36 = load i8*, i8** %7
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%38 = call i32 @get_label(i8* %36, i8* %37, i32* null)
store i32 %38, i32* %9
%39 = load i32, i32* %9
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %35
%42 = load i8*, i8** %7
%43 = call i32 @free(i8* %42)
store i32 -1, i32* %3
br label %48
44: ; preds = %35
%45 = load i8*, i8** %7
%46 = load i8**, i8*** %5
store i8* %45, i8** %46
%47 = load i32, i32* %9
store i32 %47, i32* %3
br label %48
48: ; preds = %44, %41, %34, %24, %15
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @smack_new_label_from_proc(i8* nocapture %0, i8** nocapture writeonly %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %24, label %8
8: ; preds = %2
%9 = call i32 @read(i32 %6, i8* %4, i32 255)
%10 = tail call i32 @close(i32 %6)
%11 = icmp slt i32 %9, 0
br i1 %11, label %24, label %12
12: ; preds = %8
%13 = zext i32 %9 to i64
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %13
store i8 0, i8* %14
%15 = add nuw nsw i32 %9, 1
%16 = tail call i8* @calloc(i32 %15, i32 1)
%17 = icmp eq i8* %16, null
br i1 %17, label %24, label %18
18: ; preds = %12
%19 = call i32 @get_label(i8* %16, i8* %4, i32* null)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @free(i8* %16)
br label %24
23: ; preds = %18
store i8* %16, i8** %1
br label %24
24: ; preds = %12, %8, %2, %23, %21
%25 = phi i32 [ -1, %21 ], [ %19, %23 ], [ -1, %2 ], [ -1, %8 ], [ -1, %12 ]
ret i32 %25
}