#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 {
  scalar_t__ st_dev;
  scalar_t__ st_ino;
};
struct mntent {
  char const *mnt_dir;
};
typedef int /*<<< orphan*/ linebuf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ endmntent(int /*<<< orphan*/ *);
int /*<<< orphan*/ eprintf(char *, char *);
struct mntent *getmntent_r(int /*<<< orphan*/ *, struct mntent *, char *, int);
int /*<<< orphan*/ *setmntent(char *, char *);
scalar_t__ stat(char const *, struct stat *);
int /*<<< orphan*/ weprintf(char *, char const *);
int mounted(const char *dir) {
  FILE *fp;
  struct mntent *me, mebuf;
  struct stat st1, st2;
  char linebuf[256];
  if (stat(dir, &st1) < 0) {
    weprintf("stat %s:", dir);
    return 0;
  }
  if (!(fp = setmntent("/proc/mounts", "r")))
    eprintf("setmntent %s:", "/proc/mounts");
  while ((me = getmntent_r(fp, &mebuf, linebuf, sizeof(linebuf)))) {
    if (stat(me->mnt_dir, &st2) < 0) {
      weprintf("stat %s:", me->mnt_dir);
      continue;
    }
    if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino)
      return 1;
  }
  endmntent(fp);
  return 0;
}


x86 assembly (clang, -O0):
<mounted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    11a2 <mounted+0x42>
mov    -0x10(%rbp),%rsi
lea    0xe6f(%rip),%rdi
call   1070 <weprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1271 <mounted+0x111>
lea    0xe60(%rip),%rdi
lea    0xe66(%rip),%rsi
call   1060 <setmntent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11d6 <mounted+0x76>
lea    0xe4e(%rip),%rdi
lea    0xe38(%rip),%rsi
call   1080 <eprintf@plt>
jmp    11db <mounted+0x7b>
mov    -0x18(%rbp),%rdi
lea    -0x150(%rbp),%rdx
lea    -0x28(%rbp),%rsi
mov    $0x100,%ecx
call   1040 <getmntent_r@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1261 <mounted+0x101>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    -0x48(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    1234 <mounted+0xd4>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xdd6(%rip),%rdi
call   1070 <weprintf@plt>
jmp    11db <mounted+0x7b>
mov    -0x38(%rbp),%rax
cmp    -0x48(%rbp),%rax
jne    125c <mounted+0xfc>
mov    -0x30(%rbp),%rax
cmp    -0x40(%rbp),%rax
jne    125c <mounted+0xfc>
movl   $0x1,-0x4(%rbp)
jmp    1271 <mounted+0x111>
jmp    11db <mounted+0x7b>
mov    -0x18(%rbp),%rdi
call   1030 <endmntent@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mounted>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
mov    %rdi,%rbx
lea    0x20(%rsp),%rsi
call   1050 <stat@plt>
test   %rax,%rax
js     1251 <mounted+0xf1>
lea    0xe7b(%rip),%rdi
lea    0xe81(%rip),%rsi
call   1060 <setmntent@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11b5 <mounted+0x55>
lea    0xe6f(%rip),%rdi
lea    0xe59(%rip),%rsi
call   1080 <eprintf@plt>
lea    0x8(%rsp),%rsi
lea    0x30(%rsp),%rdx
mov    %rbx,%rdi
mov    $0x100,%ecx
call   1040 <getmntent_r@plt>
test   %rax,%rax
je     1247 <mounted+0xe7>
mov    %rax,%rbp
lea    0x10(%rsp),%r14
lea    0xe20(%rip),%r15
lea    0x8(%rsp),%r12
lea    0x30(%rsp),%r13
jmp    1217 <mounted+0xb7>
nopl   0x0(%rax)
mov    0x0(%rbp),%rsi
mov    %r15,%rdi
call   1070 <weprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    $0x100,%ecx
call   1040 <getmntent_r@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1247 <mounted+0xe7>
mov    0x0(%rbp),%rdi
mov    %r14,%rsi
call   1050 <stat@plt>
test   %rax,%rax
js     11f0 <mounted+0x90>
mov    0x20(%rsp),%rax
cmp    0x10(%rsp),%rax
jne    11fc <mounted+0x9c>
mov    0x28(%rsp),%rax
cmp    0x18(%rsp),%rax
jne    11fc <mounted+0x9c>
mov    $0x1,%eax
jmp    1262 <mounted+0x102>
mov    %rbx,%rdi
call   1030 <endmntent@plt>
jmp    1260 <mounted+0x100>
lea    0xda8(%rip),%rdi
mov    %rbx,%rsi
call   1070 <weprintf@plt>
xor    %eax,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.mntent = type { i8* }
%struct.stat = type { i64, i64 }
@.str = [9 x i8] c"stat %s:\00"
@.str.1 = [13 x i8] c"/proc/mounts\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [14 x i8] c"setmntent %s:\00"
define i32 @mounted(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.mntent*
%6 = alloca %struct.mntent
%7 = alloca %struct.stat
%8 = alloca %struct.stat
%9 = alloca [256 x i8]
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = call i64 @stat(i8* %10, %struct.stat* %7)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i32 @weprintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 0, i32* %2
br label %55
16: ; preds = %1
%17 = call i32* @setmntent(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %17, i32** %4
%18 = icmp ne i32* %17, null
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = call i32 @eprintf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
br label %22
22: ; preds = %51, %33, %21
%23 = load i32*, i32** %4
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%25 = call %struct.mntent* @getmntent_r(i32* %23, %struct.mntent* %6, i8* %24, i32 256)
store %struct.mntent* %25, %struct.mntent** %5
%26 = icmp ne %struct.mntent* %25, null
br i1 %26, label %27, label %52
27: ; preds = %22
%28 = load %struct.mntent*, %struct.mntent** %5
%29 = getelementptr inbounds %struct.mntent, %struct.mntent* %28, i32 0, i32 0
%30 = load i8*, i8** %29
%31 = call i64 @stat(i8* %30, %struct.stat* %8)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %27
%34 = load %struct.mntent*, %struct.mntent** %5
%35 = getelementptr inbounds %struct.mntent, %struct.mntent* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i32 @weprintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %36)
br label %22
38: ; preds = %27
%39 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%40 = load i64, i64* %39
%41 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%42 = load i64, i64* %41
%43 = icmp eq i64 %40, %42
br i1 %43, label %44, label %51
44: ; preds = %38
%45 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%46 = load i64, i64* %45
%47 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 1
%48 = load i64, i64* %47
%49 = icmp eq i64 %46, %48
br i1 %49, label %50, label %51
50: ; preds = %44
store i32 1, i32* %2
br label %55
51: ; preds = %44, %38
br label %22
52: ; preds = %22
%53 = load i32*, i32** %4
%54 = call i32 @endmntent(i32* %53)
store i32 0, i32* %2
br label %55
55: ; preds = %52, %50, %13
%56 = load i32, i32* %2
ret i32 %56
}

LLVM IR (-O2):
%struct.mntent = type { i8* }
%struct.stat = type { i64, i64 }
@.str = [9 x i8] c"stat %s:\00"
@.str.1 = [13 x i8] c"/proc/mounts\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [14 x i8] c"setmntent %s:\00"
define i32 @mounted(i8* %0) {
%2 = alloca %struct.mntent
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = alloca [256 x i8]
%6 = bitcast %struct.mntent* %2 to i8*
%7 = bitcast %struct.stat* %3 to i8*
%8 = bitcast %struct.stat* %4 to i8*
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = call i64 @stat(i8* %0, %struct.stat* %3)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @weprintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %49
14: ; preds = %1
%15 = call i32* @setmntent(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @eprintf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
%20 = call %struct.mntent* @getmntent_r(i32* %15, %struct.mntent* %2, i8* %9, i32 256)
%21 = icmp eq %struct.mntent* %20, null
br i1 %21, label %47, label %22
22: ; preds = %19
%23 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%24 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%25 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%26 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
br label %27
27: ; preds = %22, %36
%28 = phi %struct.mntent* [ %20, %22 ], [ %37, %36 ]
%29 = getelementptr inbounds %struct.mntent, %struct.mntent* %28, i64 0, i32 0
%30 = load i8*, i8** %29
%31 = call i64 @stat(i8* %30, %struct.stat* %4)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %27
%34 = load i8*, i8** %29
%35 = call i32 @weprintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %39, %43, %33
%37 = call %struct.mntent* @getmntent_r(i32* %15, %struct.mntent* %2, i8* %9, i32 256)
%38 = icmp eq %struct.mntent* %37, null
br i1 %38, label %47, label %27
39: ; preds = %27
%40 = load i64, i64* %23
%41 = load i64, i64* %24
%42 = icmp eq i64 %40, %41
br i1 %42, label %43, label %36
43: ; preds = %39
%44 = load i64, i64* %25
%45 = load i64, i64* %26
%46 = icmp eq i64 %44, %45
br i1 %46, label %49, label %36
47: ; preds = %36, %19
%48 = call i32 @endmntent(i32* %15)
br label %49
49: ; preds = %43, %47, %12
%50 = phi i32 [ 0, %12 ], [ 0, %47 ], [ 1, %43 ]
ret i32 %50
}