#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 */
int /*<<< orphan*/ endmntent(int /*<<< orphan*/ *);
struct mntent *getmntent(int /*<<< orphan*/ *);
int /*<<< orphan*/ *setmntent(char *, char *);
scalar_t__ strcmp(int /*<<< orphan*/, char const *);
int dev_is_mounted(const char *dev) {
  struct mntent *ent;
  FILE *fhandle;
  fhandle = setmntent("/proc/mounts", "r");
  if (fhandle == NULL) {
    return 0;
  }
  while (NULL != (ent = getmntent(fhandle))) {
    if (strcmp(ent->mnt_fsname, dev) == 0) {
      endmntent(fhandle);
      return 1;
    }
  }
  endmntent(fhandle);
  return 0;
}


x86 assembly (clang, -O0):
<dev_is_mounted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xead(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1060 <setmntent@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117a <dev_is_mounted+0x3a>
movl   $0x0,-0x4(%rbp)
jmp    11dd <dev_is_mounted+0x9d>
jmp    117f <dev_is_mounted+0x3f>
mov    -0x20(%rbp),%rdi
call   1050 <getmntent@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     11cd <dev_is_mounted+0x8d>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11c8 <dev_is_mounted+0x88>
mov    -0x20(%rbp),%rdi
call   1030 <endmntent@plt>
movl   $0x1,-0x4(%rbp)
jmp    11dd <dev_is_mounted+0x9d>
jmp    117f <dev_is_mounted+0x3f>
mov    -0x20(%rbp),%rdi
call   1030 <endmntent@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dev_is_mounted>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xeb2(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1060 <setmntent@plt>
test   %rax,%rax
je     1193 <dev_is_mounted+0x53>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <getmntent@plt>
test   %rax,%rax
je     1197 <dev_is_mounted+0x57>
mov    (%rax),%edi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1170 <dev_is_mounted+0x30>
mov    $0x1,%ebp
jmp    1199 <dev_is_mounted+0x59>
xor    %ebp,%ebp
jmp    11a1 <dev_is_mounted+0x61>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <endmntent@plt>
mov    %ebp,%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 @dev_is_mounted(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.mntent*
%5 = alloca i32*
store i8* %0, i8** %3
%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** %5
%7 = load i32*, i32** %5
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %29
10: ; preds = %1
br label %11
11: ; preds = %25, %10
%12 = load i32*, i32** %5
%13 = call %struct.mntent* @getmntent(i32* %12)
store %struct.mntent* %13, %struct.mntent** %4
%14 = icmp ne %struct.mntent* null, %13
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = load %struct.mntent*, %struct.mntent** %4
%17 = getelementptr inbounds %struct.mntent, %struct.mntent* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = load i8*, i8** %3
%20 = call i64 @strcmp(i32 %18, i8* %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i32*, i32** %5
%24 = call i32 @endmntent(i32* %23)
store i32 1, i32* %2
br label %29
25: ; preds = %15
br label %11
26: ; preds = %11
%27 = load i32*, i32** %5
%28 = call i32 @endmntent(i32* %27)
store i32 0, i32* %2
br label %29
29: ; preds = %26, %22, %9
%30 = load i32, i32* %2
ret i32 %30
}

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 @dev_is_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 %15, label %4
4: ; preds = %1, %7
%5 = tail call %struct.mntent* @getmntent(i32* %2)
%6 = icmp eq %struct.mntent* %5, null
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = getelementptr inbounds %struct.mntent, %struct.mntent* %5, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i64 @strcmp(i32 %9, i8* %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %4
12: ; preds = %4, %7
%13 = phi i32 [ 1, %7 ], [ 0, %4 ]
%14 = tail call i32 @endmntent(i32* %2)
br label %15
15: ; preds = %12, %1
%16 = phi i32 [ 0, %1 ], [ %13, %12 ]
ret i32 %16
}