#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 */
char *calloc(int, int);
int fgetxattr(int, char const *, char *, int);
int /*<<< orphan*/ free(char *);
int get_label(char *, char *, int /*<<< orphan*/ *);
ssize_t smack_new_label_from_file(int fd, const char *xattr, char **label) {
  char buf[255 + 1];
  char *result;
  ssize_t ret = 0;
  ret = fgetxattr(fd, xattr, buf, 255 + 1);
  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_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x12c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x120(%rbp),%rdx
mov    $0x100,%ecx
call   1050 <fgetxattr@plt>
mov    %eax,-0x12c(%rbp)
cmpl   $0x0,-0x12c(%rbp)
jge    1197 <smack_new_label_from_file+0x57>
movl   $0xffffffff,-0x4(%rbp)
jmp    1233 <smack_new_label_from_file+0xf3>
movslq -0x12c(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
mov    -0x12c(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    11da <smack_new_label_from_file+0x9a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1233 <smack_new_label_from_file+0xf3>
mov    -0x128(%rbp),%rdi
lea    -0x120(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <get_label@plt>
mov    %eax,-0x12c(%rbp)
cmpl   $0x0,-0x12c(%rbp)
jge    121c <smack_new_label_from_file+0xdc>
mov    -0x128(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1233 <smack_new_label_from_file+0xf3>
mov    -0x128(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x12c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smack_new_label_from_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rdx,%r14
mov    %rsp,%rdx
mov    $0x100,%ecx
call   1050 <fgetxattr@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
js     11a1 <smack_new_label_from_file+0x61>
mov    %eax,%ecx
movb   $0x0,(%rsp,%rcx,1)
add    $0x1,%eax
mov    %eax,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     11a1 <smack_new_label_from_file+0x61>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1060 <get_label@plt>
test   %eax,%eax
js     1199 <smack_new_label_from_file+0x59>
mov    %rbx,(%r14)
mov    %eax,%ebp
jmp    11a1 <smack_new_label_from_file+0x61>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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