#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 {
  char *mnt_dir;
  int /*<<< orphan*/ mnt_fsname;
  int /*<<< orphan*/ mnt_type;
};
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ add_place_places(int /*<<< orphan*/ *, char *, char *);
scalar_t__ check_mount(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
struct mntent *getmntent(int /*<<< orphan*/ *);
char *strrchr(char *, char);
int read_mtab(Display *dpy, const char *mtab) {
  FILE *mt = fopen(mtab, "r");
  if (!mt)
    return -1;
  int found = 0;
  struct mntent *mntent;
  while ((mntent = getmntent(mt)) != NULL) {
    char *s;
    if (check_mount(mntent->mnt_dir, mntent->mnt_type, mntent->mnt_fsname))
      continue;
    if ((s = strrchr(mntent->mnt_dir, '/'))) {
      ++s;
    } else {
      s = mntent->mnt_dir;
    }
    if (!add_place_places(dpy, s, mntent->mnt_dir)) {
      ++found;
    }
  }
  fclose(mt);
  return found;
}


x86 assembly (clang, -O0):
<read_mtab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119b <read_mtab+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1257 <read_mtab+0xf7>
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <getmntent@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1248 <read_mtab+0xe8>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%edx
call   1030 <check_mount@plt>
cmp    $0x0,%rax
je     11e2 <read_mtab+0x82>
jmp    11a2 <read_mtab+0x42>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1212 <read_mtab+0xb2>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    121d <read_mtab+0xbd>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    (%rax),%rdx
call   1070 <add_place_places@plt>
cmp    $0x0,%eax
jne    1243 <read_mtab+0xe3>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a2 <read_mtab+0x42>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_mtab>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xe8c(%rip),%rsi
mov    %rax,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11f4 <read_mtab+0x94>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <getmntent@plt>
test   %rax,%rax
je     11fc <read_mtab+0x9c>
mov    %rax,%rbp
xor    %r15d,%r15d
jmp    11b0 <read_mtab+0x50>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <getmntent@plt>
mov    %rax,%rbp
test   %rax,%rax
je     11ff <read_mtab+0x9f>
mov    0x0(%rbp),%rdi
mov    0xc(%rbp),%esi
mov    0x8(%rbp),%edx
call   1030 <check_mount@plt>
test   %rax,%rax
jne    11a0 <read_mtab+0x40>
mov    0x0(%rbp),%rbp
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
lea    0x1(%rax),%rsi
test   %rax,%rax
cmove  %rbp,%rsi
mov    %r14,%rdi
mov    %rbp,%rdx
call   1070 <add_place_places@plt>
cmp    $0x1,%eax
adc    $0x0,%r15d
jmp    11a0 <read_mtab+0x40>
mov    $0xffffffff,%r15d
jmp    1207 <read_mtab+0xa7>
xor    %r15d,%r15d
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.mntent = type { i8*, i32, i32 }
@.str = [2 x i8] c"r\00"
define i32 @read_mtab(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca %struct.mntent*
%9 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %5
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
store i32 -1, i32* %3
br label %62
15: ; preds = %2
store i32 0, i32* %7
br label %16
16: ; preds = %57, %32, %15
%17 = load i32*, i32** %6
%18 = call %struct.mntent* @getmntent(i32* %17)
store %struct.mntent* %18, %struct.mntent** %8
%19 = icmp ne %struct.mntent* %18, null
br i1 %19, label %20, label %58
20: ; preds = %16
%21 = load %struct.mntent*, %struct.mntent** %8
%22 = getelementptr inbounds %struct.mntent, %struct.mntent* %21, i32 0, i32 0
%23 = load i8*, i8** %22
%24 = load %struct.mntent*, %struct.mntent** %8
%25 = getelementptr inbounds %struct.mntent, %struct.mntent* %24, i32 0, i32 2
%26 = load i32, i32* %25
%27 = load %struct.mntent*, %struct.mntent** %8
%28 = getelementptr inbounds %struct.mntent, %struct.mntent* %27, i32 0, i32 1
%29 = load i32, i32* %28
%30 = call i64 @check_mount(i8* %23, i32 %26, i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %20
br label %16
33: ; preds = %20
%34 = load %struct.mntent*, %struct.mntent** %8
%35 = getelementptr inbounds %struct.mntent, %struct.mntent* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i8* @strrchr(i8* %36, i8 signext 47)
store i8* %37, i8** %9
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %42
39: ; preds = %33
%40 = load i8*, i8** %9
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %9
br label %46
42: ; preds = %33
%43 = load %struct.mntent*, %struct.mntent** %8
%44 = getelementptr inbounds %struct.mntent, %struct.mntent* %43, i32 0, i32 0
%45 = load i8*, i8** %44
store i8* %45, i8** %9
br label %46
46: ; preds = %42, %39
%47 = load i32*, i32** %4
%48 = load i8*, i8** %9
%49 = load %struct.mntent*, %struct.mntent** %8
%50 = getelementptr inbounds %struct.mntent, %struct.mntent* %49, i32 0, i32 0
%51 = load i8*, i8** %50
%52 = call i32 @add_place_places(i32* %47, i8* %48, i8* %51)
%53 = icmp ne i32 %52, 0
br i1 %53, label %57, label %54
54: ; preds = %46
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %57
57: ; preds = %54, %46
br label %16
58: ; preds = %16
%59 = load i32*, i32** %6
%60 = call i32 @fclose(i32* %59)
%61 = load i32, i32* %7
store i32 %61, i32* %3
br label %62
62: ; preds = %58, %14
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
%struct.mntent = type { i8*, i32, i32 }
@.str = [2 x i8] c"r\00"
define i32 @read_mtab(i32* %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %36, label %5
5: ; preds = %2
%6 = tail call %struct.mntent* @getmntent(i32* %3)
%7 = icmp eq %struct.mntent* %6, null
br i1 %7, label %33, label %8
8: ; preds = %5, %29
%9 = phi %struct.mntent* [ %31, %29 ], [ %6, %5 ]
%10 = phi i32 [ %30, %29 ], [ 0, %5 ]
%11 = getelementptr inbounds %struct.mntent, %struct.mntent* %9, i64 0, i32 0
%12 = load i8*, i8** %11
%13 = getelementptr inbounds %struct.mntent, %struct.mntent* %9, i64 0, i32 2
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.mntent, %struct.mntent* %9, i64 0, i32 1
%16 = load i32, i32* %15
%17 = tail call i64 @check_mount(i8* %12, i32 %14, i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %29
19: ; preds = %8
%20 = load i8*, i8** %11
%21 = tail call i8* @strrchr(i8* dereferenceable(1) %20, i8 signext 47)
%22 = icmp eq i8* %21, null
%23 = getelementptr inbounds i8, i8* %21, i64 1
%24 = select i1 %22, i8* %20, i8* %23
%25 = tail call i32 @add_place_places(i32* %0, i8* %24, i8* %20)
%26 = icmp eq i32 %25, 0
%27 = zext i1 %26 to i32
%28 = add nsw i32 %10, %27
br label %29
29: ; preds = %8, %19
%30 = phi i32 [ %28, %19 ], [ %10, %8 ]
%31 = tail call %struct.mntent* @getmntent(i32* %3)
%32 = icmp eq %struct.mntent* %31, null
br i1 %32, label %33, label %8
33: ; preds = %29, %5
%34 = phi i32 [ 0, %5 ], [ %30, %29 ]
%35 = tail call i32 @fclose(i32* %3)
br label %36
36: ; preds = %2, %33
%37 = phi i32 [ %34, %33 ], [ -1, %2 ]
ret i32 %37
}