#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 mntent {
  int /*<<< orphan*/ *mnt_dir;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ endmntent(int /*<<< orphan*/ *);
struct mntent *getmntent(int /*<<< orphan*/ *);
int /*<<< orphan*/ *setmntent(char *, char *);
scalar_t__ strcmp(int /*<<< orphan*/ *, char const *);
bool is_target_mounted(const char *path) {
  FILE *mtab = NULL;
  struct mntent *part = NULL;
  bool is_mounted = false;
  if ((mtab = setmntent("/proc/mounts", "r")) != NULL) {
    while ((part = getmntent(mtab)) != NULL) {
      if ((part->mnt_dir != NULL) && (strcmp(part->mnt_dir, path)) == 0) {
        is_mounted = true;
        break;
      }
    }
    endmntent(mtab);
  }
  return is_mounted;
}


x86 assembly (clang, -O0):
<is_target_mounted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe96(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1060 <setmntent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11e2 <is_target_mounted+0xa2>
jmp    1189 <is_target_mounted+0x49>
mov    -0x10(%rbp),%rdi
call   1050 <getmntent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11d9 <is_target_mounted+0x99>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     11d4 <is_target_mounted+0x94>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11d4 <is_target_mounted+0x94>
movl   $0x1,-0x1c(%rbp)
jmp    11d9 <is_target_mounted+0x99>
jmp    1189 <is_target_mounted+0x49>
mov    -0x10(%rbp),%rdi
call   1030 <endmntent@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_target_mounted>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
lea    0xeb2(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1060 <setmntent@plt>
test   %rax,%rax
je     11a2 <is_target_mounted+0x62>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <getmntent@plt>
xor    %r14d,%r14d
jmp    1178 <is_target_mounted+0x38>
nop
mov    %rbx,%rdi
call   1050 <getmntent@plt>
test   %rax,%rax
je     1198 <is_target_mounted+0x58>
mov    (%rax),%rdi
test   %rdi,%rdi
je     1170 <is_target_mounted+0x30>
mov    %rbp,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1170 <is_target_mounted+0x30>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   1030 <endmntent@plt>
jmp    11a5 <is_target_mounted+0x65>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.mntent = type { i32* }
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @is_target_mounted(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.mntent*
%5 = alloca i32
store i8* %0, i8** %2
store i32* null, i32** %3
store %struct.mntent* null, %struct.mntent** %4
store i32 0, i32* %5
%6 = call i32* @setmntent(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %3
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %30
8: ; preds = %1
br label %9
9: ; preds = %26, %8
%10 = load i32*, i32** %3
%11 = call %struct.mntent* @getmntent(i32* %10)
store %struct.mntent* %11, %struct.mntent** %4
%12 = icmp ne %struct.mntent* %11, null
br i1 %12, label %13, label %27
13: ; preds = %9
%14 = load %struct.mntent*, %struct.mntent** %4
%15 = getelementptr inbounds %struct.mntent, %struct.mntent* %14, i32 0, i32 0
%16 = load i32*, i32** %15
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %26
18: ; preds = %13
%19 = load %struct.mntent*, %struct.mntent** %4
%20 = getelementptr inbounds %struct.mntent, %struct.mntent* %19, i32 0, i32 0
%21 = load i32*, i32** %20
%22 = load i8*, i8** %2
%23 = call i64 @strcmp(i32* %21, i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %18
store i32 1, i32* %5
br label %27
26: ; preds = %18, %13
br label %9
27: ; preds = %25, %9
%28 = load i32*, i32** %3
%29 = call i32 @endmntent(i32* %28)
br label %30
30: ; preds = %27, %1
%31 = load i32, i32* %5
ret i32 %31
}

LLVM IR (-O2):
%struct.mntent = type { i32* }
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @is_target_mounted(i8* %0) {
%2 = tail call i32* @setmntent(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %21, label %4
4: ; preds = %1
%5 = tail call %struct.mntent* @getmntent(i32* %2)
%6 = icmp eq %struct.mntent* %5, null
br i1 %6, label %18, label %7
7: ; preds = %4, %15
%8 = phi %struct.mntent* [ %16, %15 ], [ %5, %4 ]
%9 = getelementptr inbounds %struct.mntent, %struct.mntent* %8, i64 0, i32 0
%10 = load i32*, i32** %9
%11 = icmp eq i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %7
%13 = tail call i64 @strcmp(i32* %10, i8* %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12, %7
%16 = tail call %struct.mntent* @getmntent(i32* %2)
%17 = icmp eq %struct.mntent* %16, null
br i1 %17, label %18, label %7
18: ; preds = %15, %12, %4
%19 = phi i32 [ 0, %4 ], [ 1, %12 ], [ 0, %15 ]
%20 = tail call i32 @endmntent(i32* %2)
br label %21
21: ; preds = %18, %1
%22 = phi i32 [ %19, %18 ], [ 0, %1 ]
ret i32 %22
}