#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 lsetxattr(char const *, char const *, char const *, int,
              int /*<<< orphan*/);
int setxattr(char const *, char const *, char const *, int, int /*<<< orphan*/);
scalar_t__ smack_label_length(char const *);
int smack_set_label_for_path(const char *path, const char *xattr, int follow,
                             const char *label) {
  int len;
  len = (int)smack_label_length(label);
  if (len < 0)
    return -2;
  return follow ? setxattr(path, xattr, label, len, 0)
                : lsetxattr(path, xattr, label, len, 0);
}


x86 assembly (clang, -O0):
<smack_set_label_for_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <smack_label_length@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1169 <smack_set_label_for_path+0x39>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11b2 <smack_set_label_for_path+0x82>
cmpl   $0x0,-0x1c(%rbp)
je     1192 <smack_set_label_for_path+0x62>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
xor    %r8d,%r8d
call   1040 <setxattr@plt>
mov    %eax,-0x30(%rbp)
jmp    11ac <smack_set_label_for_path+0x7c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
xor    %r8d,%r8d
call   1030 <lsetxattr@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smack_set_label_for_path>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rcx,%rdi
call   1050 <smack_label_length@plt>
test   %eax,%eax
js     116f <smack_set_label_for_path+0x3f>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
add    $0x8,%rsp
test   %ebp,%ebp
je     117f <smack_set_label_for_path+0x4f>
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <setxattr@plt>
mov    $0xfffffffe,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <lsetxattr@plt>

LLVM IR (-O0):
define i32 @smack_set_label_for_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 i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%11 = load i8*, i8** %9
%12 = call i64 @smack_label_length(i8* %11)
%13 = trunc i64 %12 to i32
store i32 %13, i32* %10
%14 = load i32, i32* %10
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 -2, i32* %5
br label %34
17: ; preds = %4
%18 = load i32, i32* %8
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %17
%21 = load i8*, i8** %6
%22 = load i8*, i8** %7
%23 = load i8*, i8** %9
%24 = load i32, i32* %10
%25 = call i32 @setxattr(i8* %21, i8* %22, i8* %23, i32 %24, i32 0)
br label %32
26: ; preds = %17
%27 = load i8*, i8** %6
%28 = load i8*, i8** %7
%29 = load i8*, i8** %9
%30 = load i32, i32* %10
%31 = call i32 @lsetxattr(i8* %27, i8* %28, i8* %29, i32 %30, i32 0)
br label %32
32: ; preds = %26, %20
%33 = phi i32 [ %25, %20 ], [ %31, %26 ]
store i32 %33, i32* %5
br label %34
34: ; preds = %32, %16
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
define i32 @smack_set_label_for_path(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = tail call i64 @smack_label_length(i8* %3)
%6 = trunc i64 %5 to i32
%7 = icmp slt i32 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %4
%9 = icmp eq i32 %2, 0
br i1 %9, label %12, label %10
10: ; preds = %8
%11 = tail call i32 @setxattr(i8* %0, i8* %1, i8* %3, i32 %6, i32 0)
br label %14
12: ; preds = %8
%13 = tail call i32 @lsetxattr(i8* %0, i8* %1, i8* %3, i32 %6, i32 0)
br label %14
14: ; preds = %10, %12, %4
%15 = phi i32 [ -2, %4 ], [ %11, %10 ], [ %13, %12 ]
ret i32 %15
}