#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ ENOENT;
scalar_t__ EROFS;
scalar_t__ S_ISLNK(int /*<<< orphan*/);
int /*<<< orphan*/ W_OK;
char *_PATH_MOUNTED;
int access(char *, int /*<<< orphan*/);
scalar_t__ errno;
int lstat(char *, struct stat *);
size_t strlen(char const *);
scalar_t__ strncmp(char const *, char *, size_t);
int mtab_needs_update(const char *mnt) {
  int res;
  struct stat stbuf;
  if (strncmp(mnt, _PATH_MOUNTED, strlen(mnt)) == 0 &&
      _PATH_MOUNTED[strlen(mnt)] == '/')
    return 0;
  res = lstat(_PATH_MOUNTED, &stbuf);
  if (res == -1) {
    if (errno == ENOENT)
      return 0;
  } else {
    if (S_ISLNK(stbuf.st_mode))
      return 0;
    res = access(_PATH_MOUNTED, W_OK);
    if (res == -1 && errno == EROFS)
      return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<mtab_needs_update>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11cc <mtab_needs_update+0x7c>
mov    0x2e44(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11cc <mtab_needs_update+0x7c>
movl   $0x0,-0x4(%rbp)
jmp    128c <mtab_needs_update+0x13c>
mov    0x2e0d(%rip),%rax
mov    (%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <lstat@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1217 <mtab_needs_update+0xc7>
mov    0x2dd5(%rip),%rax
mov    (%rax),%rax
mov    0x2dbb(%rip),%rcx
cmp    (%rcx),%rax
jne    1212 <mtab_needs_update+0xc2>
movl   $0x0,-0x4(%rbp)
jmp    128c <mtab_needs_update+0x13c>
jmp    1285 <mtab_needs_update+0x135>
mov    -0x18(%rbp),%edi
call   1040 <S_ISLNK@plt>
cmp    $0x0,%rax
je     1235 <mtab_needs_update+0xe5>
movl   $0x0,-0x4(%rbp)
jmp    128c <mtab_needs_update+0x13c>
mov    0x2da4(%rip),%rax
mov    (%rax),%rdi
mov    0x2d92(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1280 <mtab_needs_update+0x130>
mov    0x2d67(%rip),%rax
mov    (%rax),%rax
mov    0x2d7d(%rip),%rcx
cmp    (%rcx),%rax
jne    1280 <mtab_needs_update+0x130>
movl   $0x0,-0x4(%rbp)
jmp    128c <mtab_needs_update+0x13c>
jmp    1285 <mtab_needs_update+0x135>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mtab_needs_update>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2e7d(%rip),%r15
mov    (%r15),%r14
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
mov    (%r15),%r14
test   %rax,%rax
jne    1192 <mtab_needs_update+0x42>
mov    %rbx,%rdi
call   1050 <strlen@plt>
xor    %ebx,%ebx
cmpb   $0x2f,(%r14,%rax,1)
je     11ff <mtab_needs_update+0xaf>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1060 <lstat@plt>
cmp    $0xffffffff,%eax
je     11e2 <mtab_needs_update+0x92>
mov    0x8(%rsp),%edi
call   1040 <S_ISLNK@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    11ff <mtab_needs_update+0xaf>
mov    (%r15),%rdi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
jne    11fa <mtab_needs_update+0xaa>
mov    0x2df7(%rip),%rax
mov    (%rax),%rax
mov    0x2e0d(%rip),%rcx
cmp    (%rcx),%rax
jne    11fa <mtab_needs_update+0xaa>
jmp    11ff <mtab_needs_update+0xaf>
mov    0x2ddf(%rip),%rax
mov    (%rax),%rax
mov    0x2dc5(%rip),%rcx
xor    %ebx,%ebx
cmp    (%rcx),%rax
je     11ff <mtab_needs_update+0xaf>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@_PATH_MOUNTED = global i8* null
@errno = global i64 0
@ENOENT = global i64 0
@W_OK = global i32 0
@EROFS = global i64 0
define i32 @mtab_needs_update(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.stat
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = load i8*, i8** @_PATH_MOUNTED
%8 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
%10 = call i64 @strncmp(i8* %6, i8* %7, i64 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %1
%13 = load i8*, i8** @_PATH_MOUNTED
%14 = load i8*, i8** %3
%15 = call i64 @strlen(i8* %14)
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 47
br i1 %19, label %20, label %21
20: ; preds = %12
store i32 0, i32* %2
br label %51
21: ; preds = %12, %1
%22 = load i8*, i8** @_PATH_MOUNTED
%23 = call i32 @lstat(i8* %22, %struct.stat* %5)
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = load i64, i64* @errno
%28 = load i64, i64* @ENOENT
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 0, i32* %2
br label %51
31: ; preds = %26
br label %50
32: ; preds = %21
%33 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i64 @S_ISLNK(i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32
store i32 0, i32* %2
br label %51
38: ; preds = %32
%39 = load i8*, i8** @_PATH_MOUNTED
%40 = load i32, i32* @W_OK
%41 = call i32 @access(i8* %39, i32 %40)
store i32 %41, i32* %4
%42 = load i32, i32* %4
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %49
44: ; preds = %38
%45 = load i64, i64* @errno
%46 = load i64, i64* @EROFS
%47 = icmp eq i64 %45, %46
br i1 %47, label %48, label %49
48: ; preds = %44
store i32 0, i32* %2
br label %51
49: ; preds = %44, %38
br label %50
50: ; preds = %49, %31
store i32 1, i32* %2
br label %51
51: ; preds = %50, %48, %37, %30, %20
%52 = load i32, i32* %2
ret i32 %52
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@_PATH_MOUNTED = global i8* null
@errno = global i64 0
@ENOENT = global i64 0
@W_OK = global i32 0
@EROFS = global i64 0
define i32 @mtab_needs_update(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = load i8*, i8** @_PATH_MOUNTED
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = tail call i64 @strncmp(i8* %0, i8* %4, i64 %5)
%7 = icmp eq i64 %6, 0
%8 = load i8*, i8** @_PATH_MOUNTED
br i1 %7, label %9, label %14
9: ; preds = %1
%10 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 47
br i1 %13, label %36, label %14
14: ; preds = %1, %9
%15 = call i32 @lstat(i8* %8, %struct.stat* %2)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i64, i64* @errno
%19 = load i64, i64* @ENOENT
%20 = icmp eq i64 %18, %19
br i1 %20, label %36, label %35
21: ; preds = %14
%22 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%23 = load i32, i32* %22
%24 = tail call i64 @S_ISLNK(i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %36
26: ; preds = %21
%27 = load i8*, i8** @_PATH_MOUNTED
%28 = load i32, i32* @W_OK
%29 = tail call i32 @access(i8* %27, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = load i64, i64* @errno
%33 = load i64, i64* @EROFS
%34 = icmp eq i64 %32, %33
br i1 %34, label %36, label %35
35: ; preds = %26, %31, %17
br label %36
36: ; preds = %31, %21, %17, %9, %35
%37 = phi i32 [ 1, %35 ], [ 0, %9 ], [ 0, %17 ], [ 0, %21 ], [ 0, %31 ]
ret i32 %37
}