#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 *);
int omb_utils_is_mounted(const char *mountpoint) {
  FILE *mtab = NULL;
  struct mntent *part = NULL;
  int is_mounted = 0;
  if ((mtab = setmntent("/etc/mtab", "r")) != NULL) {
    while ((part = getmntent(mtab)) != NULL) {
      if (part->mnt_dir != NULL && strcmp(part->mnt_dir, mountpoint) == 0) {
        is_mounted = 1;
      }
    }
    endmntent(mtab);
  }
  return is_mounted;
}


x86 assembly (clang, -O0):
<omb_utils_is_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    0xe99(%rip),%rsi
call   1060 <setmntent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11dd <omb_utils_is_mounted+0x9d>
jmp    1189 <omb_utils_is_mounted+0x49>
mov    -0x10(%rbp),%rdi
call   1050 <getmntent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11d4 <omb_utils_is_mounted+0x94>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     11cf <omb_utils_is_mounted+0x8f>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11cf <omb_utils_is_mounted+0x8f>
movl   $0x1,-0x1c(%rbp)
jmp    1189 <omb_utils_is_mounted+0x49>
mov    -0x10(%rbp),%rdi
call   1030 <endmntent@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<omb_utils_is_mounted>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeaf(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1060 <setmntent@plt>
test   %rax,%rax
je     11b0 <omb_utils_is_mounted+0x70>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <getmntent@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11a6 <omb_utils_is_mounted+0x66>
mov    $0x1,%r15d
jmp    118d <omb_utils_is_mounted+0x4d>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <getmntent@plt>
test   %rax,%rax
je     11a6 <omb_utils_is_mounted+0x66>
mov    (%rax),%rdi
test   %rdi,%rdi
je     1180 <omb_utils_is_mounted+0x40>
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
cmove  %r15d,%ebp
jmp    1180 <omb_utils_is_mounted+0x40>
mov    %rbx,%rdi
call   1030 <endmntent@plt>
jmp    11b2 <omb_utils_is_mounted+0x72>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
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 @omb_utils_is_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 ([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** %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 %26
26: ; preds = %25, %18, %13
br label %9
27: ; preds = %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 = [10 x i8] c"/etc/mtab\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @omb_utils_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))
%3 = icmp eq i32* %2, null
br i1 %3, label %24, label %4
4: ; preds = %1
%5 = tail call %struct.mntent* @getmntent(i32* %2)
%6 = icmp eq %struct.mntent* %5, null
br i1 %6, label %21, label %7
7: ; preds = %4, %17
%8 = phi %struct.mntent* [ %19, %17 ], [ %5, %4 ]
%9 = phi i32 [ %18, %17 ], [ 0, %4 ]
%10 = getelementptr inbounds %struct.mntent, %struct.mntent* %8, i64 0, i32 0
%11 = load i32*, i32** %10
%12 = icmp eq i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %7
%14 = tail call i64 @strcmp(i32* %11, i8* %0)
%15 = icmp eq i64 %14, 0
%16 = select i1 %15, i32 1, i32 %9
br label %17
17: ; preds = %13, %7
%18 = phi i32 [ %9, %7 ], [ %16, %13 ]
%19 = tail call %struct.mntent* @getmntent(i32* %2)
%20 = icmp eq %struct.mntent* %19, null
br i1 %20, label %21, label %7
21: ; preds = %17, %4
%22 = phi i32 [ 0, %4 ], [ %18, %17 ]
%23 = tail call i32 @endmntent(i32* %2)
br label %24
24: ; preds = %21, %1
%25 = phi i32 [ %22, %21 ], [ 0, %1 ]
ret i32 %25
}