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

/* Variables and functions */
struct mntent *getmntent(int /*<<< orphan*/ *);
int /*<<< orphan*/ *setmntent(char *, char *);
int /*<<< orphan*/ strcmp(int /*<<< orphan*/, char const *);
bool is_mounted(const char *path) {
  FILE *fp = setmntent("/etc/mtab", "r");
  struct mntent *entry;
  while ((entry = getmntent(fp)) != NULL)
    if (!strcmp(entry->mnt_fsname, path))
      return true;
  return false;
}


x86 assembly (clang, -O0):
<is_mounted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xebd(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1050 <setmntent@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <getmntent@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1193 <is_mounted+0x63>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    118e <is_mounted+0x5e>
movl   $0x1,-0x4(%rbp)
jmp    119a <is_mounted+0x6a>
jmp    1153 <is_mounted+0x23>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_mounted>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xec2(%rip),%rdi
lea    0xec5(%rip),%rsi
call   1050 <setmntent@plt>
mov    %rax,%rbx
nopl   (%rax)
mov    %rbx,%rdi
call   1040 <getmntent@plt>
test   %rax,%rax
je     1172 <is_mounted+0x42>
mov    (%rax),%edi
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
jne    1150 <is_mounted+0x20>
mov    $0x1,%eax
jmp    1174 <is_mounted+0x44>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.mntent = type { i32 }
@.str = [10 x i8] c"/etc/mtab\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @is_mounted(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.mntent*
store i8* %0, i8** %3
%6 = call i32* @setmntent(i8* getelementptr inbounds ([10 x i8], [10 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** %4
br label %7
7: ; preds = %19, %1
%8 = load i32*, i32** %4
%9 = call %struct.mntent* @getmntent(i32* %8)
store %struct.mntent* %9, %struct.mntent** %5
%10 = icmp ne %struct.mntent* %9, null
br i1 %10, label %11, label %20
11: ; preds = %7
%12 = load %struct.mntent*, %struct.mntent** %5
%13 = getelementptr inbounds %struct.mntent, %struct.mntent* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = load i8*, i8** %3
%16 = call i32 @strcmp(i32 %14, i8* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %11
store i32 1, i32* %2
br label %21
19: ; preds = %11
br label %7
20: ; preds = %7
store i32 0, i32* %2
br label %21
21: ; preds = %20, %18
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
%struct.mntent = type { i32 }
@.str = [10 x i8] c"/etc/mtab\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @is_mounted(i8* %0) {
%2 = tail call i32* @setmntent(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %3
3: ; preds = %6, %1
%4 = tail call %struct.mntent* @getmntent(i32* %2)
%5 = icmp eq %struct.mntent* %4, null
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = getelementptr inbounds %struct.mntent, %struct.mntent* %4, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i32 @strcmp(i32 %8, i8* %0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %3
11: ; preds = %3, %6
%12 = phi i32 [ 1, %6 ], [ 0, %3 ]
ret i32 %12
}