#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 /*<<< orphan*/ free(char *);
int get_label(char *, char *, int /*<<< orphan*/ *);
int getxattr(char const *, char const *, char *, int);
int lgetxattr(char const *, char const *, char *, int);
ssize_t smack_new_label_from_path(const char *path, const char *xattr,
                                  int follow, char **label) {
  char buf[255 + 1];
  char *result;
  ssize_t ret = 0;
  ret = follow ? getxattr(path, xattr, buf, 255 + 1)
               : lgetxattr(path, 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_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x13c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11a2 <smack_new_label_from_path+0x52>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x130(%rbp),%rdx
mov    $0x100,%ecx
call   1070 <getxattr@plt>
mov    %eax,-0x140(%rbp)
jmp    11c1 <smack_new_label_from_path+0x71>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x130(%rbp),%rdx
mov    $0x100,%ecx
call   1040 <lgetxattr@plt>
mov    %eax,-0x140(%rbp)
mov    -0x140(%rbp),%eax
mov    %eax,-0x13c(%rbp)
cmpl   $0x0,-0x13c(%rbp)
jge    11e6 <smack_new_label_from_path+0x96>
movl   $0xffffffff,-0x4(%rbp)
jmp    1282 <smack_new_label_from_path+0x132>
movslq -0x13c(%rbp),%rax
movb   $0x0,-0x130(%rbp,%rax,1)
mov    -0x13c(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x138(%rbp)
cmpq   $0x0,-0x138(%rbp)
jne    1229 <smack_new_label_from_path+0xd9>
movl   $0xffffffff,-0x4(%rbp)
jmp    1282 <smack_new_label_from_path+0x132>
mov    -0x138(%rbp),%rdi
lea    -0x130(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <get_label@plt>
mov    %eax,-0x13c(%rbp)
cmpl   $0x0,-0x13c(%rbp)
jge    126b <smack_new_label_from_path+0x11b>
mov    -0x138(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1282 <smack_new_label_from_path+0x132>
mov    -0x138(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x13c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smack_new_label_from_path>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rcx,%r14
test   %edx,%edx
je     1171 <smack_new_label_from_path+0x21>
mov    %rsp,%rdx
mov    $0x100,%ecx
call   1070 <getxattr@plt>
jmp    117e <smack_new_label_from_path+0x2e>
mov    %rsp,%rdx
mov    $0x100,%ecx
call   1040 <lgetxattr@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
js     11c4 <smack_new_label_from_path+0x74>
mov    %eax,%ecx
movb   $0x0,(%rsp,%rcx,1)
add    $0x1,%eax
mov    %eax,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     11c4 <smack_new_label_from_path+0x74>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1060 <get_label@plt>
test   %eax,%eax
js     11bc <smack_new_label_from_path+0x6c>
mov    %rbx,(%r14)
mov    %eax,%ebp
jmp    11c4 <smack_new_label_from_path+0x74>
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_path(i8* %0, i8* %1, i32 %2, i8** %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8**
%10 = alloca [256 x i8]
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8** %3, i8*** %9
store i32 0, i32* %12
%13 = load i32, i32* %8
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %4
%16 = load i8*, i8** %6
%17 = load i8*, i8** %7
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%19 = call i32 @getxattr(i8* %16, i8* %17, i8* %18, i32 256)
br label %25
20: ; preds = %4
%21 = load i8*, i8** %6
%22 = load i8*, i8** %7
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%24 = call i32 @lgetxattr(i8* %21, i8* %22, i8* %23, i32 256)
br label %25
25: ; preds = %20, %15
%26 = phi i32 [ %19, %15 ], [ %24, %20 ]
store i32 %26, i32* %12
%27 = load i32, i32* %12
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 -1, i32* %5
br label %53
30: ; preds = %25
%31 = load i32, i32* %12
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %32
store i8 0, i8* %33
%34 = load i32, i32* %12
%35 = add nsw i32 %34, 1
%36 = call i8* @calloc(i32 %35, i32 1)
store i8* %36, i8** %11
%37 = load i8*, i8** %11
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %40
39: ; preds = %30
store i32 -1, i32* %5
br label %53
40: ; preds = %30
%41 = load i8*, i8** %11
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%43 = call i32 @get_label(i8* %41, i8* %42, i32* null)
store i32 %43, i32* %12
%44 = load i32, i32* %12
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %40
%47 = load i8*, i8** %11
%48 = call i32 @free(i8* %47)
store i32 -1, i32* %5
br label %53
49: ; preds = %40
%50 = load i8*, i8** %11
%51 = load i8**, i8*** %9
store i8* %50, i8** %51
%52 = load i32, i32* %12
store i32 %52, i32* %5
br label %53
53: ; preds = %49, %46, %39, %29
%54 = load i32, i32* %5
ret i32 %54
}

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