#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 const *, char *);
int /*<<< orphan*/ strcmp(char const *, int /*<<< orphan*/);
int is_mounted(const char *mpt, const char *device) {
  FILE *file = NULL;
  struct mntent *mnt = NULL;
  file = setmntent(mpt, "r");
  if (file == NULL)
    return 0;
  while ((mnt = getmntent(file)) != NULL) {
    if (!strcmp(device, mnt->mnt_fsname))
      break;
  }
  endmntent(file);
  return mnt ? 1 : 0;
}


x86 assembly (clang, -O0):
<is_mounted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <setmntent@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118b <is_mounted+0x4b>
movl   $0x0,-0x4(%rbp)
jmp    11e7 <is_mounted+0xa7>
jmp    1190 <is_mounted+0x50>
mov    -0x20(%rbp),%rdi
call   1050 <getmntent@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11c9 <is_mounted+0x89>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11c4 <is_mounted+0x84>
jmp    11c9 <is_mounted+0x89>
jmp    1190 <is_mounted+0x50>
mov    -0x20(%rbp),%rdi
call   1030 <endmntent@plt>
mov    -0x28(%rbp),%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_mounted>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xeaf(%rip),%rsi
call   1060 <setmntent@plt>
test   %rax,%rax
je     1191 <is_mounted+0x51>
mov    %rax,%r15
xchg   %ax,%ax
mov    %r15,%rdi
call   1050 <getmntent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     117e <is_mounted+0x3e>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    1160 <is_mounted+0x20>
xor    %ebp,%ebp
test   %rbx,%rbx
setne  %bpl
mov    %r15,%rdi
call   1030 <endmntent@plt>
jmp    1193 <is_mounted+0x53>
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 = [2 x i8] c"r\00"
define i32 @is_mounted(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca %struct.mntent*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* null, i32** %6
store %struct.mntent* null, %struct.mntent** %7
%8 = load i8*, i8** %4
%9 = call i32* @setmntent(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %34
13: ; preds = %2
br label %14
14: ; preds = %26, %13
%15 = load i32*, i32** %6
%16 = call %struct.mntent* @getmntent(i32* %15)
store %struct.mntent* %16, %struct.mntent** %7
%17 = icmp ne %struct.mntent* %16, null
br i1 %17, label %18, label %27
18: ; preds = %14
%19 = load i8*, i8** %5
%20 = load %struct.mntent*, %struct.mntent** %7
%21 = getelementptr inbounds %struct.mntent, %struct.mntent* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i32 @strcmp(i8* %19, i32 %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %18
br label %27
26: ; preds = %18
br label %14
27: ; preds = %25, %14
%28 = load i32*, i32** %6
%29 = call i32 @endmntent(i32* %28)
%30 = load %struct.mntent*, %struct.mntent** %7
%31 = icmp ne %struct.mntent* %30, null
%32 = zext i1 %31 to i64
%33 = select i1 %31, i32 1, i32 0
store i32 %33, i32* %3
br label %34
34: ; preds = %27, %12
%35 = load i32, i32* %3
ret i32 %35
}

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