#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 smack_have_access(char const *, char const *, char const *);
int smack_get_access(const char *subject, const char *object) {
  int access, ret, i;
  const char *accesses[] = {"r", "w", "x", "a", "t", "l", "b"};
  ret = 0;
  for (i = 0; i < 7; ++i) {
    access = smack_have_access(subject, object, accesses[i]);
    if (access == -1)
      return -1;
    if (access == 1)
      ret |= (1 << i);
  }
  return ret;
}


x86 assembly (clang, -O0):
<smack_get_access>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x60(%rbp),%rdi
lea    0x2ca5(%rip),%rsi
mov    $0x38,%edx
call   1030 <memcpy@plt>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x7,-0x24(%rbp)
jge    11b9 <smack_get_access+0x99>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x24(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rdx
call   1040 <smack_have_access@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    118c <smack_get_access+0x6c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bf <smack_get_access+0x9f>
cmpl   $0x1,-0x1c(%rbp)
jne    11a6 <smack_get_access+0x86>
mov    -0x24(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11ab <smack_get_access+0x8b>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1153 <smack_get_access+0x33>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smack_get_access>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xedf(%rip),%rdx
call   1030 <smack_have_access@plt>
cmp    $0xffffffff,%eax
je     1207 <smack_get_access+0xf7>
xor    %r14d,%r14d
cmp    $0x1,%eax
jne    113d <smack_get_access+0x2d>
mov    $0x1,%r14d
lea    0xebe(%rip),%rdx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <smack_have_access@plt>
cmp    $0xffffffff,%eax
je     1207 <smack_get_access+0xf7>
cmp    $0x1,%eax
jne    1161 <smack_get_access+0x51>
or     $0x2,%r14d
lea    0xe9c(%rip),%rdx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <smack_have_access@plt>
cmp    $0xffffffff,%eax
je     1207 <smack_get_access+0xf7>
cmp    $0x1,%eax
jne    1185 <smack_get_access+0x75>
or     $0x4,%r14d
lea    0xe7a(%rip),%rdx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <smack_have_access@plt>
cmp    $0xffffffff,%eax
je     1207 <smack_get_access+0xf7>
cmp    $0x1,%eax
jne    11a5 <smack_get_access+0x95>
or     $0x8,%r14d
lea    0xe5c(%rip),%rdx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <smack_have_access@plt>
cmp    $0xffffffff,%eax
je     1207 <smack_get_access+0xf7>
cmp    $0x1,%eax
jne    11c5 <smack_get_access+0xb5>
or     $0x10,%r14d
lea    0xe3e(%rip),%rdx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <smack_have_access@plt>
cmp    $0xffffffff,%eax
je     1207 <smack_get_access+0xf7>
cmp    $0x1,%eax
jne    11e5 <smack_get_access+0xd5>
or     $0x20,%r14d
lea    0xe20(%rip),%rdx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <smack_have_access@plt>
cmp    $0xffffffff,%eax
je     1207 <smack_get_access+0xf7>
cmp    $0x1,%eax
jne    120a <smack_get_access+0xfa>
or     $0x40,%r14d
jmp    120a <smack_get_access+0xfa>
mov    %eax,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [2 x i8] c"x\00"
@.str.3 = [2 x i8] c"a\00"
@.str.4 = [2 x i8] c"t\00"
@.str.5 = [2 x i8] c"l\00"
@.str.6 = [2 x i8] c"b\00"
@__const.smack_get_access.accesses = [7 x i8*] [i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0)]
define i32 @smack_get_access(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [7 x i8*]
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = bitcast [7 x i8*]* %9 to i8*
store i32 0, i32* %7
store i32 0, i32* %8
br label %11
11: ; preds = %34, %2
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 7
br i1 %13, label %14, label %37
14: ; preds = %11
%15 = load i8*, i8** %4
%16 = load i8*, i8** %5
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [7 x i8*], [7 x i8*]* %9, i64 0, i64 %18
%20 = load i8*, i8** %19
%21 = call i32 @smack_have_access(i8* %15, i8* %16, i8* %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %25
24: ; preds = %14
store i32 -1, i32* %3
br label %39
25: ; preds = %14
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i32, i32* %8
%30 = shl i32 1, %29
%31 = load i32, i32* %7
%32 = or i32 %31, %30
store i32 %32, i32* %7
br label %33
33: ; preds = %28, %25
br label %34
34: ; preds = %33
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
br label %11
37: ; preds = %11
%38 = load i32, i32* %7
store i32 %38, i32* %3
br label %39
39: ; preds = %37, %24
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [2 x i8] c"x\00"
@.str.3 = [2 x i8] c"a\00"
@.str.4 = [2 x i8] c"t\00"
@.str.5 = [2 x i8] c"l\00"
@.str.6 = [2 x i8] c"b\00"
define i32 @smack_get_access(i8* %0, i8* %1) {
%3 = tail call i32 @smack_have_access(i8* %0, i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
switch i32 %3, label %5 [
i32 -1, label %37
i32 1, label %4
]
4: ; preds = %2
br label %5
5: ; preds = %2, %4
%6 = phi i32 [ 1, %4 ], [ 0, %2 ]
%7 = tail call i32 @smack_have_access(i8* %0, i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
switch i32 %7, label %10 [
i32 -1, label %37
i32 1, label %8
]
8: ; preds = %5
%9 = or i32 %6, 2
br label %10
10: ; preds = %8, %5
%11 = phi i32 [ %9, %8 ], [ %6, %5 ]
%12 = tail call i32 @smack_have_access(i8* %0, i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
switch i32 %12, label %15 [
i32 -1, label %37
i32 1, label %13
]
13: ; preds = %10
%14 = or i32 %11, 4
br label %15
15: ; preds = %13, %10
%16 = phi i32 [ %14, %13 ], [ %11, %10 ]
%17 = tail call i32 @smack_have_access(i8* %0, i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
switch i32 %17, label %20 [
i32 -1, label %37
i32 1, label %18
]
18: ; preds = %15
%19 = or i32 %16, 8
br label %20
20: ; preds = %18, %15
%21 = phi i32 [ %19, %18 ], [ %16, %15 ]
%22 = tail call i32 @smack_have_access(i8* %0, i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
switch i32 %22, label %25 [
i32 -1, label %37
i32 1, label %23
]
23: ; preds = %20
%24 = or i32 %21, 16
br label %25
25: ; preds = %23, %20
%26 = phi i32 [ %24, %23 ], [ %21, %20 ]
%27 = tail call i32 @smack_have_access(i8* %0, i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
switch i32 %27, label %30 [
i32 -1, label %37
i32 1, label %28
]
28: ; preds = %25
%29 = or i32 %26, 32
br label %30
30: ; preds = %28, %25
%31 = phi i32 [ %29, %28 ], [ %26, %25 ]
%32 = tail call i32 @smack_have_access(i8* %0, i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
switch i32 %32, label %35 [
i32 -1, label %37
i32 1, label %33
]
33: ; preds = %30
%34 = or i32 %31, 64
br label %35
35: ; preds = %33, %30
%36 = phi i32 [ %34, %33 ], [ %31, %30 ]
br label %37
37: ; preds = %35, %30, %25, %20, %15, %10, %5, %2
%38 = phi i32 [ %3, %2 ], [ %7, %5 ], [ %12, %10 ], [ %17, %15 ], [ %22, %20 ], [ %27, %25 ], [ %32, %30 ], [ %36, %35 ]
ret i32 %38
}