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

/* Variables and functions */
scalar_t__ EXIT_SUCCESS;
scalar_t__ check_mounts(int /*<<< orphan*/, int /*<<< orphan*/,
                        int /*<<< orphan*/, int /*<<< orphan*/,
                        int /*<<< orphan*/, int /*<<< orphan*/, char *);
int /*<<< orphan*/ endmntent(int /*<<< orphan*/ *);
struct mntent *getmntent(int /*<<< orphan*/ *);
int /*<<< orphan*/ *setmntent(char *, char *);
int mnt_cnt(char *fs_type) {
  FILE *ft = setmntent("/etc/fstab", "r");
  FILE *mt = setmntent("/etc/mtab", "r");
  int mounted = 0;
  struct mntent *f;
  struct mntent *m;
  while ((f = getmntent(ft))) {
    while ((m = getmntent(mt))) {
      if (check_mounts(f->mnt_fsname, f->mnt_dir, f->mnt_type, m->mnt_fsname,
                       m->mnt_dir, m->mnt_type, fs_type) == EXIT_SUCCESS) {
        mounted++;
      }
    }
  }
  endmntent(ft);
  endmntent(mt);
  return (mounted);
}


x86 assembly (clang, -O0):
<mnt_cnt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xead(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1050 <setmntent@plt>
mov    %rax,-0x10(%rbp)
lea    0xea3(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1050 <setmntent@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <getmntent@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     120e <mnt_cnt+0xce>
jmp    119d <mnt_cnt+0x5d>
mov    -0x18(%rbp),%rdi
call   1040 <getmntent@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1209 <mnt_cnt+0xc9>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%r8d
mov    -0x30(%rbp),%rax
mov    (%rax),%r9d
mov    -0x8(%rbp),%rax
mov    %rax,(%rsp)
call   1060 <check_mounts@plt>
mov    0x2dee(%rip),%rcx
cmp    (%rcx),%rax
jne    1204 <mnt_cnt+0xc4>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119d <mnt_cnt+0x5d>
jmp    1181 <mnt_cnt+0x41>
mov    -0x10(%rbp),%rdi
call   1030 <endmntent@plt>
mov    -0x18(%rbp),%rdi
call   1030 <endmntent@plt>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mnt_cnt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
lea    0xeab(%rip),%rdi
lea    0xeaf(%rip),%rbx
mov    %rbx,%rsi
call   1050 <setmntent@plt>
mov    %rax,%r14
lea    0xe9f(%rip),%rdi
mov    %rbx,%rsi
call   1050 <setmntent@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1040 <getmntent@plt>
test   %rax,%rax
je     11e5 <mnt_cnt+0xa5>
mov    %rax,%rbx
xor    %ebp,%ebp
mov    0x2e4e(%rip),%r13
jmp    11c6 <mnt_cnt+0x86>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x8(%rbx),%edi
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    0x8(%rax),%ecx
mov    (%rax),%r9d
mov    0x4(%rax),%r8d
mov    %r15,(%rsp)
call   1060 <check_mounts@plt>
xor    %ecx,%ecx
cmp    0x0(%r13),%rax
sete   %cl
add    %ecx,%ebp
mov    %r12,%rdi
call   1040 <getmntent@plt>
test   %rax,%rax
jne    11a0 <mnt_cnt+0x60>
mov    %r14,%rdi
call   1040 <getmntent@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11c6 <mnt_cnt+0x86>
jmp    11e7 <mnt_cnt+0xa7>
xor    %ebp,%ebp
mov    %r14,%rdi
call   1030 <endmntent@plt>
mov    %r12,%rdi
call   1030 <endmntent@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.mntent = type { i32, i32, i32 }
@.str = [11 x i8] c"/etc/fstab\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"/etc/mtab\00"
@EXIT_SUCCESS = global i64 0
define i32 @mnt_cnt(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca %struct.mntent*
%7 = alloca %struct.mntent*
store i8* %0, i8** %2
%8 = call i32* @setmntent(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %3
%9 = call i32* @setmntent(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %4
store i32 0, i32* %5
br label %10
10: ; preds = %46, %1
%11 = load i32*, i32** %3
%12 = call %struct.mntent* @getmntent(i32* %11)
store %struct.mntent* %12, %struct.mntent** %6
%13 = icmp ne %struct.mntent* %12, null
br i1 %13, label %14, label %47
14: ; preds = %10
br label %15
15: ; preds = %45, %14
%16 = load i32*, i32** %4
%17 = call %struct.mntent* @getmntent(i32* %16)
store %struct.mntent* %17, %struct.mntent** %7
%18 = icmp ne %struct.mntent* %17, null
br i1 %18, label %19, label %46
19: ; preds = %15
%20 = load %struct.mntent*, %struct.mntent** %6
%21 = getelementptr inbounds %struct.mntent, %struct.mntent* %20, i32 0, i32 2
%22 = load i32, i32* %21
%23 = load %struct.mntent*, %struct.mntent** %6
%24 = getelementptr inbounds %struct.mntent, %struct.mntent* %23, i32 0, i32 1
%25 = load i32, i32* %24
%26 = load %struct.mntent*, %struct.mntent** %6
%27 = getelementptr inbounds %struct.mntent, %struct.mntent* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = load %struct.mntent*, %struct.mntent** %7
%30 = getelementptr inbounds %struct.mntent, %struct.mntent* %29, i32 0, i32 2
%31 = load i32, i32* %30
%32 = load %struct.mntent*, %struct.mntent** %7
%33 = getelementptr inbounds %struct.mntent, %struct.mntent* %32, i32 0, i32 1
%34 = load i32, i32* %33
%35 = load %struct.mntent*, %struct.mntent** %7
%36 = getelementptr inbounds %struct.mntent, %struct.mntent* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = load i8*, i8** %2
%39 = call i64 @check_mounts(i32 %22, i32 %25, i32 %28, i32 %31, i32 %34, i32 %37, i8* %38)
%40 = load i64, i64* @EXIT_SUCCESS
%41 = icmp eq i64 %39, %40
br i1 %41, label %42, label %45
42: ; preds = %19
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %45
45: ; preds = %42, %19
br label %15
46: ; preds = %15
br label %10
47: ; preds = %10
%48 = load i32*, i32** %3
%49 = call i32 @endmntent(i32* %48)
%50 = load i32*, i32** %4
%51 = call i32 @endmntent(i32* %50)
%52 = load i32, i32* %5
ret i32 %52
}

LLVM IR (-O2):
%struct.mntent = type { i32, i32, i32 }
@.str = [11 x i8] c"/etc/fstab\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"/etc/mtab\00"
@EXIT_SUCCESS = global i64 0
define i32 @mnt_cnt(i8* %0) {
%2 = tail call i32* @setmntent(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32* @setmntent(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call %struct.mntent* @getmntent(i32* %2)
%5 = icmp eq %struct.mntent* %4, null
br i1 %5, label %38, label %10
6: ; preds = %19, %10
%7 = phi i32 [ %12, %10 ], [ %35, %19 ]
%8 = tail call %struct.mntent* @getmntent(i32* %2)
%9 = icmp eq %struct.mntent* %8, null
br i1 %9, label %38, label %10
10: ; preds = %1, %6
%11 = phi %struct.mntent* [ %8, %6 ], [ %4, %1 ]
%12 = phi i32 [ %7, %6 ], [ 0, %1 ]
%13 = tail call %struct.mntent* @getmntent(i32* %3)
%14 = icmp eq %struct.mntent* %13, null
br i1 %14, label %6, label %15
15: ; preds = %10
%16 = getelementptr inbounds %struct.mntent, %struct.mntent* %11, i64 0, i32 2
%17 = getelementptr inbounds %struct.mntent, %struct.mntent* %11, i64 0, i32 1
%18 = getelementptr inbounds %struct.mntent, %struct.mntent* %11, i64 0, i32 0
br label %19
19: ; preds = %15, %19
%20 = phi %struct.mntent* [ %13, %15 ], [ %36, %19 ]
%21 = phi i32 [ %12, %15 ], [ %35, %19 ]
%22 = load i32, i32* %16
%23 = load i32, i32* %17
%24 = load i32, i32* %18
%25 = getelementptr inbounds %struct.mntent, %struct.mntent* %20, i64 0, i32 2
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.mntent, %struct.mntent* %20, i64 0, i32 1
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.mntent, %struct.mntent* %20, i64 0, i32 0
%30 = load i32, i32* %29
%31 = tail call i64 @check_mounts(i32 %22, i32 %23, i32 %24, i32 %26, i32 %28, i32 %30, i8* %0)
%32 = load i64, i64* @EXIT_SUCCESS
%33 = icmp eq i64 %31, %32
%34 = zext i1 %33 to i32
%35 = add nsw i32 %21, %34
%36 = tail call %struct.mntent* @getmntent(i32* %3)
%37 = icmp eq %struct.mntent* %36, null
br i1 %37, label %6, label %19
38: ; preds = %6, %1
%39 = phi i32 [ 0, %1 ], [ %7, %6 ]
%40 = tail call i32 @endmntent(i32* %2)
%41 = tail call i32 @endmntent(i32* %3)
ret i32 %39
}