#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;
int /*<<< orphan*/ O_RDWR;
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int strlen(char *);
int smackfs_open(char *entry) {
  char *path;
  int fd;
  fd = strlen(entry);
  if ((path = calloc(1, fd + 20)) == NULL)
    return -1;
  sprintf(path, "/sys/fs/smackfs/%s", entry);
  if ((fd = open(path, O_RDWR)) >= 0) {
    free(path);
    return fd;
  }
  if ((fd = open(path, O_RDONLY)) >= 0) {
    free(path);
    return fd;
  }
  sprintf(path, "/smack/%s", entry);
  if ((fd = open(path, O_RDWR)) >= 0) {
    free(path);
    return fd;
  }
  if ((fd = open(path, O_RDONLY)) >= 0) {
    free(path);
    return fd;
  }
  sprintf(path, "/sys/fs/smack/%s", entry);
  if ((fd = open(path, O_RDWR)) >= 0) {
    free(path);
    return fd;
  }
  if ((fd = open(path, O_RDONLY)) >= 0) {
    free(path);
    return fd;
  }
  sprintf(path, "/proc/self/attr/%s", entry);
  if ((fd = open(path, O_RDWR)) >= 0) {
    free(path);
    return fd;
  }
  if ((fd = open(path, O_RDONLY)) >= 0) {
    free(path);
    return fd;
  }
  free(path);
  return -1;
}


x86 assembly (clang, -O0):
<smackfs_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
add    $0x14,%esi
mov    $0x1,%edi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1192 <smackfs_open+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    1382 <smackfs_open+0x232>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe5f(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jl     11d8 <smackfs_open+0x88>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1382 <smackfs_open+0x232>
mov    -0x18(%rbp),%rdi
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jl     120a <smackfs_open+0xba>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1382 <smackfs_open+0x232>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe01(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jl     1250 <smackfs_open+0x100>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1382 <smackfs_open+0x232>
mov    -0x18(%rbp),%rdi
mov    0x2d85(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jl     1282 <smackfs_open+0x132>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1382 <smackfs_open+0x232>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xd82(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d47(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jl     12c8 <smackfs_open+0x178>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1382 <smackfs_open+0x232>
mov    -0x18(%rbp),%rdi
mov    0x2d0d(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jl     12fa <smackfs_open+0x1aa>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1382 <smackfs_open+0x232>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xd1b(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2ccf(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jl     1340 <smackfs_open+0x1f0>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1382 <smackfs_open+0x232>
mov    -0x18(%rbp),%rdi
mov    0x2c95(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jl     1372 <smackfs_open+0x222>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1382 <smackfs_open+0x232>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smackfs_open>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
lea    0x14(%rax),%esi
mov    $0x1,%edi
call   1050 <calloc@plt>
test   %rax,%rax
je     124f <smackfs_open+0xff>
mov    %rax,%rbx
lea    0xe80(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1070 <sprintf@plt>
mov    0x2e56(%rip),%r15
mov    (%r15),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
test   %eax,%eax
jns    1243 <smackfs_open+0xf3>
mov    0x2e34(%rip),%r12
mov    (%r12),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
test   %eax,%eax
jns    1243 <smackfs_open+0xf3>
lea    0xe53(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1070 <sprintf@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
test   %eax,%eax
jns    1243 <smackfs_open+0xf3>
mov    (%r12),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
test   %eax,%eax
jns    1243 <smackfs_open+0xf3>
lea    0xe1b(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1070 <sprintf@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
test   %eax,%eax
jns    1243 <smackfs_open+0xf3>
mov    (%r12),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
test   %eax,%eax
jns    1243 <smackfs_open+0xf3>
lea    0xdfb(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1070 <sprintf@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
test   %eax,%eax
js     125f <smackfs_open+0x10f>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1254 <smackfs_open+0x104>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r12),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r14d,%r14d
mov    $0xffffffff,%ebp
cmovns %r14d,%ebp
jmp    1254 <smackfs_open+0x104>

LLVM IR (-O0):
@.str = [19 x i8] c"/sys/fs/smackfs/%s\00"
@O_RDWR = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [10 x i8] c"/smack/%s\00"
@.str.2 = [17 x i8] c"/sys/fs/smack/%s\00"
@.str.3 = [19 x i8] c"/proc/self/attr/%s\00"
define i32 @smackfs_open(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = add nsw i32 %8, 20
%10 = call i8* @calloc(i32 1, i32 %9)
store i8* %10, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %100
13: ; preds = %1
%14 = load i8*, i8** %4
%15 = load i8*, i8** %3
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i8*, i8** %4
%18 = load i32, i32* @O_RDWR
%19 = call i32 @open(i8* %17, i32 %18)
store i32 %19, i32* %5
%20 = icmp sge i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %13
%22 = load i8*, i8** %4
%23 = call i32 @free(i8* %22)
%24 = load i32, i32* %5
store i32 %24, i32* %2
br label %100
25: ; preds = %13
%26 = load i8*, i8** %4
%27 = load i32, i32* @O_RDONLY
%28 = call i32 @open(i8* %26, i32 %27)
store i32 %28, i32* %5
%29 = icmp sge i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = load i8*, i8** %4
%32 = call i32 @free(i8* %31)
%33 = load i32, i32* %5
store i32 %33, i32* %2
br label %100
34: ; preds = %25
%35 = load i8*, i8** %4
%36 = load i8*, i8** %3
%37 = call i32 @sprintf(i8* %35, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = load i8*, i8** %4
%39 = load i32, i32* @O_RDWR
%40 = call i32 @open(i8* %38, i32 %39)
store i32 %40, i32* %5
%41 = icmp sge i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %34
%43 = load i8*, i8** %4
%44 = call i32 @free(i8* %43)
%45 = load i32, i32* %5
store i32 %45, i32* %2
br label %100
46: ; preds = %34
%47 = load i8*, i8** %4
%48 = load i32, i32* @O_RDONLY
%49 = call i32 @open(i8* %47, i32 %48)
store i32 %49, i32* %5
%50 = icmp sge i32 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %46
%52 = load i8*, i8** %4
%53 = call i32 @free(i8* %52)
%54 = load i32, i32* %5
store i32 %54, i32* %2
br label %100
55: ; preds = %46
%56 = load i8*, i8** %4
%57 = load i8*, i8** %3
%58 = call i32 @sprintf(i8* %56, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %57)
%59 = load i8*, i8** %4
%60 = load i32, i32* @O_RDWR
%61 = call i32 @open(i8* %59, i32 %60)
store i32 %61, i32* %5
%62 = icmp sge i32 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %55
%64 = load i8*, i8** %4
%65 = call i32 @free(i8* %64)
%66 = load i32, i32* %5
store i32 %66, i32* %2
br label %100
67: ; preds = %55
%68 = load i8*, i8** %4
%69 = load i32, i32* @O_RDONLY
%70 = call i32 @open(i8* %68, i32 %69)
store i32 %70, i32* %5
%71 = icmp sge i32 %70, 0
br i1 %71, label %72, label %76
72: ; preds = %67
%73 = load i8*, i8** %4
%74 = call i32 @free(i8* %73)
%75 = load i32, i32* %5
store i32 %75, i32* %2
br label %100
76: ; preds = %67
%77 = load i8*, i8** %4
%78 = load i8*, i8** %3
%79 = call i32 @sprintf(i8* %77, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %78)
%80 = load i8*, i8** %4
%81 = load i32, i32* @O_RDWR
%82 = call i32 @open(i8* %80, i32 %81)
store i32 %82, i32* %5
%83 = icmp sge i32 %82, 0
br i1 %83, label %84, label %88
84: ; preds = %76
%85 = load i8*, i8** %4
%86 = call i32 @free(i8* %85)
%87 = load i32, i32* %5
store i32 %87, i32* %2
br label %100
88: ; preds = %76
%89 = load i8*, i8** %4
%90 = load i32, i32* @O_RDONLY
%91 = call i32 @open(i8* %89, i32 %90)
store i32 %91, i32* %5
%92 = icmp sge i32 %91, 0
br i1 %92, label %93, label %97
93: ; preds = %88
%94 = load i8*, i8** %4
%95 = call i32 @free(i8* %94)
%96 = load i32, i32* %5
store i32 %96, i32* %2
br label %100
97: ; preds = %88
%98 = load i8*, i8** %4
%99 = call i32 @free(i8* %98)
store i32 -1, i32* %2
br label %100
100: ; preds = %97, %93, %84, %72, %63, %51, %42, %30, %21, %12
%101 = load i32, i32* %2
ret i32 %101
}

LLVM IR (-O2):
@.str = [19 x i8] c"/sys/fs/smackfs/%s\00"
@O_RDWR = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [10 x i8] c"/smack/%s\00"
@.str.2 = [17 x i8] c"/sys/fs/smack/%s\00"
@.str.3 = [19 x i8] c"/proc/self/attr/%s\00"
define i32 @smackfs_open(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 20
%4 = tail call i8* @calloc(i32 1, i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %58, label %6
6: ; preds = %1
%7 = tail call i32 @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = load i32, i32* @O_RDWR
%9 = tail call i32 @open(i8* %4, i32 %8)
%10 = icmp sgt i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @free(i8* %4)
br label %58
13: ; preds = %6
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @open(i8* %4, i32 %14)
%16 = icmp sgt i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call i32 @free(i8* %4)
br label %58
19: ; preds = %13
%20 = tail call i32 @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%21 = load i32, i32* @O_RDWR
%22 = tail call i32 @open(i8* %4, i32 %21)
%23 = icmp sgt i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = tail call i32 @free(i8* %4)
br label %58
26: ; preds = %19
%27 = load i32, i32* @O_RDONLY
%28 = tail call i32 @open(i8* %4, i32 %27)
%29 = icmp sgt i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = tail call i32 @free(i8* %4)
br label %58
32: ; preds = %26
%33 = tail call i32 @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%34 = load i32, i32* @O_RDWR
%35 = tail call i32 @open(i8* %4, i32 %34)
%36 = icmp sgt i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = tail call i32 @free(i8* %4)
br label %58
39: ; preds = %32
%40 = load i32, i32* @O_RDONLY
%41 = tail call i32 @open(i8* %4, i32 %40)
%42 = icmp sgt i32 %41, -1
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = tail call i32 @free(i8* %4)
br label %58
45: ; preds = %39
%46 = tail call i32 @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%47 = load i32, i32* @O_RDWR
%48 = tail call i32 @open(i8* %4, i32 %47)
%49 = icmp sgt i32 %48, -1
br i1 %49, label %50, label %52
50: ; preds = %45
%51 = tail call i32 @free(i8* %4)
br label %58
52: ; preds = %45
%53 = load i32, i32* @O_RDONLY
%54 = tail call i32 @open(i8* %4, i32 %53)
%55 = icmp sgt i32 %54, -1
%56 = tail call i32 @free(i8* %4)
%57 = select i1 %55, i32 %54, i32 -1
br label %58
58: ; preds = %52, %1, %50, %43, %37, %30, %24, %17, %11
%59 = phi i32 [ %9, %11 ], [ %15, %17 ], [ %22, %24 ], [ %28, %30 ], [ %35, %37 ], [ %41, %43 ], [ %48, %50 ], [ -1, %1 ], [ %57, %52 ]
ret i32 %59
}