#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 *);
int mounted(char *device) {
  FILE *mtab = setmntent("/etc/mtab", "r");
  struct mntent *fs;
  while ((fs = getmntent(mtab)) && strcmp(fs->mnt_fsname, device))
    ;
  endmntent(mtab);
  return fs != 0;
}


x86 assembly (clang, -O0):
<mounted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xead(%rip),%rdi
lea    0xeb0(%rip),%rsi
call   1060 <setmntent@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <getmntent@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     119b <mounted+0x5b>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11ab <mounted+0x6b>
jmp    11b0 <mounted+0x70>
jmp    1163 <mounted+0x23>
mov    -0x10(%rbp),%rdi
call   1030 <endmntent@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<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>
mov    %rax,%r15
mov    %r15,%rdi
call   1050 <getmntent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     117f <mounted+0x3f>
mov    (%rbx),%edi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1160 <mounted+0x20>
xor    %ebp,%ebp
test   %rbx,%rbx
setne  %bpl
mov    %r15,%rdi
call   1030 <endmntent@plt>
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 @mounted(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.mntent*
store i8* %0, i8** %2
%5 = 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* %5, i32** %3
br label %6
6: ; preds = %19, %1
%7 = load i32*, i32** %3
%8 = call %struct.mntent* @getmntent(i32* %7)
store %struct.mntent* %8, %struct.mntent** %4
%9 = icmp ne %struct.mntent* %8, null
br i1 %9, label %10, label %17
10: ; preds = %6
%11 = load %struct.mntent*, %struct.mntent** %4
%12 = getelementptr inbounds %struct.mntent, %struct.mntent* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = load i8*, i8** %2
%15 = call i64 @strcmp(i32 %13, i8* %14)
%16 = icmp ne i64 %15, 0
br label %17
17: ; preds = %10, %6
%18 = phi i1 [ false, %6 ], [ %16, %10 ]
br i1 %18, label %19, label %20
19: ; preds = %17
br label %6
20: ; preds = %17
%21 = load i32*, i32** %3
%22 = call i32 @endmntent(i32* %21)
%23 = load %struct.mntent*, %struct.mntent** %4
%24 = icmp ne %struct.mntent* %23, null
%25 = zext i1 %24 to i32
ret i32 %25
}

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 @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 i64 @strcmp(i32 %8, i8* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %3
11: ; preds = %3, %6
%12 = xor i1 %5, true
%13 = tail call i32 @endmntent(i32* %2)
%14 = zext i1 %12 to i32
ret i32 %14
}