#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;
scalar_t__ apply_cipso(char *);
scalar_t__ apply_rules(char *, int /*<<< orphan*/);
scalar_t__ clear();
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
scalar_t__ smack_set_onlycap_from_file(int);
int /*<<< orphan*/ smack_smackfs_path();
int /*<<< orphan*/ stderr;
int smack_load_policy(void) {
  if (!smack_smackfs_path()) {
    fprintf(stderr, "SmackFS is not mounted.\n");
    return -1;
  }
  if (clear())
    return -1;
  if (apply_rules("/etc/smack/accesses.d", 0))
    return -1;
  if (apply_cipso("/etc/smack/cipso.d"))
    return -1;
  int fd = open("/etc/smack/onlycap", O_RDONLY);
  if (fd < 0) {
    return -1;
  }
  if (smack_set_onlycap_from_file(fd)) {
    close(fd);
    return -1;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<smack_load_policy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1090 <smack_smackfs_path@plt>
cmp    $0x0,%eax
jne    11b9 <smack_load_policy+0x39>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    127f <smack_load_policy+0xff>
mov    $0x0,%al
call   1080 <clear@plt>
cmp    $0x0,%rax
je     11d6 <smack_load_policy+0x56>
movl   $0xffffffff,-0x4(%rbp)
jmp    127f <smack_load_policy+0xff>
lea    0xe3c(%rip),%rdi
xor    %esi,%esi
call   10a0 <apply_rules@plt>
cmp    $0x0,%rax
je     11fa <smack_load_policy+0x7a>
movl   $0xffffffff,-0x4(%rbp)
jmp    127f <smack_load_policy+0xff>
lea    0xe2e(%rip),%rdi
call   1060 <apply_cipso@plt>
cmp    $0x0,%rax
je     121c <smack_load_policy+0x9c>
movl   $0xffffffff,-0x4(%rbp)
jmp    127f <smack_load_policy+0xff>
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
lea    0xe16(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    124a <smack_load_policy+0xca>
movl   $0xffffffff,-0x4(%rbp)
jmp    127f <smack_load_policy+0xff>
mov    -0x8(%rbp),%edi
call   1030 <smack_set_onlycap_from_file@plt>
cmp    $0x0,%rax
je     1270 <smack_load_policy+0xf0>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    127f <smack_load_policy+0xff>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smack_load_policy>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1090 <smack_smackfs_path@plt>
test   %eax,%eax
je     11f6 <smack_load_policy+0x76>
xor    %eax,%eax
call   1080 <clear@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jne    1210 <smack_load_policy+0x90>
lea    0xe73(%rip),%rdi
xor    %esi,%esi
call   10a0 <apply_rules@plt>
test   %rax,%rax
jne    1210 <smack_load_policy+0x90>
lea    0xe76(%rip),%rdi
call   1060 <apply_cipso@plt>
test   %rax,%rax
jne    1210 <smack_load_policy+0x90>
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
lea    0xe6f(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     1210 <smack_load_policy+0x90>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <smack_set_onlycap_from_file@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1040 <close@plt>
neg    %rbx
sbb    %ebx,%ebx
jmp    1210 <smack_load_policy+0x90>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"SmackFS is not mounted.\0A\00"
@.str.1 = [22 x i8] c"/etc/smack/accesses.d\00"
@.str.2 = [19 x i8] c"/etc/smack/cipso.d\00"
@.str.3 = [19 x i8] c"/etc/smack/onlycap\00"
@O_RDONLY = global i32 0
define i32 @smack_load_policy() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @smack_smackfs_path()
%4 = icmp ne i32 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %36
8: ; preds = %0
%9 = call i64 (...) @clear()
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %8
store i32 -1, i32* %1
br label %36
12: ; preds = %8
%13 = call i64 @apply_rules(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 0)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 -1, i32* %1
br label %36
16: ; preds = %12
%17 = call i64 @apply_cipso(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 -1, i32* %1
br label %36
20: ; preds = %16
%21 = load i32, i32* @O_RDONLY
%22 = call i32 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %21)
store i32 %22, i32* %2
%23 = load i32, i32* %2
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 -1, i32* %1
br label %36
26: ; preds = %20
%27 = load i32, i32* %2
%28 = call i64 @smack_set_onlycap_from_file(i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32, i32* %2
%32 = call i32 @close(i32 %31)
store i32 -1, i32* %1
br label %36
33: ; preds = %26
%34 = load i32, i32* %2
%35 = call i32 @close(i32 %34)
store i32 0, i32* %1
br label %36
36: ; preds = %33, %30, %25, %19, %15, %11, %5
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"SmackFS is not mounted.\0A\00"
@.str.1 = [22 x i8] c"/etc/smack/accesses.d\00"
@.str.2 = [19 x i8] c"/etc/smack/cipso.d\00"
@.str.3 = [19 x i8] c"/etc/smack/onlycap\00"
@O_RDONLY = global i32 0
define i32 @smack_load_policy() {
%1 = tail call i32 (...) @smack_smackfs_path()
%2 = icmp eq i32 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %24
6: ; preds = %0
%7 = tail call i64 (...) @clear()
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %24
9: ; preds = %6
%10 = tail call i64 @apply_rules(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %9
%13 = tail call i64 @apply_cipso(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = load i32, i32* @O_RDONLY
%17 = tail call i32 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = icmp slt i32 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %15
%20 = tail call i64 @smack_set_onlycap_from_file(i32 %17)
%21 = icmp ne i64 %20, 0
%22 = tail call i32 @close(i32 %17)
%23 = sext i1 %21 to i32
br label %24
24: ; preds = %19, %15, %12, %9, %6, %3
%25 = phi i32 [ -1, %3 ], [ -1, %6 ], [ -1, %9 ], [ -1, %12 ], [ -1, %15 ], [ %23, %19 ]
ret i32 %25
}