#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 /*<<< orphan*/ buf;

/* Variables and functions */
int PATH_MAX;
scalar_t__ readlink(char *, char *, int);
int /*<<< orphan*/ strlen(char const *);
scalar_t__ strncmp(char *, char const *, int /*<<< orphan*/);
int facilityBelongsToUs(char *facility, const char *altDir) {
  char buf[PATH_MAX];
  if (readlink(facility, buf, sizeof(buf)) <= 0)
    return 0;
  return strncmp(buf, altDir, strlen(altDir)) ? 0 : 1;
}


x86 assembly (clang, -O0):
<facilityBelongsToUs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2ea9(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x38(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    %eax,%edx
call   1040 <readlink@plt>
cmp    $0x0,%rax
jg     1194 <facilityBelongsToUs+0x64>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    11cf <facilityBelongsToUs+0x9f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
mov    %rax,%rdx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<facilityBelongsToUs>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    0x2eaf(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rsi
call   1040 <readlink@plt>
test   %rax,%rax
jle    1186 <facilityBelongsToUs+0x56>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    1188 <facilityBelongsToUs+0x58>
xor    %eax,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
define i32 @facilityBelongsToUs(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = load i8*, i8** %4
%14 = trunc i64 %10 to i32
%15 = call i64 @readlink(i8* %13, i8* %12, i32 %14)
%16 = icmp sle i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 0, i32* %3
store i32 1, i32* %8
br label %26
18: ; preds = %2
%19 = load i8*, i8** %5
%20 = load i8*, i8** %5
%21 = call i32 @strlen(i8* %20)
%22 = call i64 @strncmp(i8* %12, i8* %19, i32 %21)
%23 = icmp ne i64 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 0, i32 1
store i32 %25, i32* %3
store i32 1, i32* %8
br label %26
26: ; preds = %18, %17
%27 = load i8*, i8** %6
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
define i32 @facilityBelongsToUs(i8* nocapture %0, i8* %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i64 @readlink(i8* %0, i8* %5, i32 %3)
%7 = icmp slt i64 %6, 1
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = tail call i32 @strlen(i8* %1)
%10 = call i64 @strncmp(i8* %5, i8* %1, i32 %9)
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %2, %8
%14 = phi i32 [ %12, %8 ], [ 0, %2 ]
ret i32 %14
}