#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 stat {
  scalar_t__ st_dev;
  int /*<<< orphan*/ st_mode;
};
struct mntent {
  char const *mnt_fsname;
  char *mnt_dir;
};
typedef scalar_t__ dev_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ S_ISBLK(int /*<<< orphan*/);
scalar_t__ S_ISCHR(int /*<<< orphan*/);
int /*<<< orphan*/ endmntent(int /*<<< orphan*/ *);
struct mntent *getmntent(int /*<<< orphan*/ *);
int /*<<< orphan*/ *setmntent(char *, char *);
scalar_t__ stat(char const *, struct stat *);
int /*<<< orphan*/ strcmp(char const *, char *);
struct mntent *find_mount_point(const char *name) {
  struct mntent *ment;
  dev_t devno_of_name;
  struct stat s;
  FILE *mtab_fp;
  if (stat(name, &s) < 0)
    return NULL;
  devno_of_name = s.st_dev;
  if (S_ISBLK(s.st_mode) || S_ISCHR(s.st_mode))
    return NULL;
  mtab_fp = setmntent("/etc/mtab", "r");
  if (!mtab_fp)
    return NULL;
  while ((ment = getmntent(mtab_fp))) {
    if (!strcmp(ment->mnt_fsname, "rootfs"))
      continue;
    if (!strcmp(name, ment->mnt_dir))
      break;
    if (stat(ment->mnt_dir, &s) == 0 && s.st_dev == devno_of_name)
      break;
  }
  endmntent(mtab_fp);
  return ment;
}


x86 assembly (clang, -O0):
<find_mount_point>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    11a0 <find_mount_point+0x30>
movq   $0x0,-0x8(%rbp)
jmp    12a8 <find_mount_point+0x138>
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%edi
call   1090 <S_ISBLK@plt>
cmp    $0x0,%rax
jne    11cc <find_mount_point+0x5c>
mov    -0x28(%rbp),%edi
call   1080 <S_ISCHR@plt>
cmp    $0x0,%rax
je     11d9 <find_mount_point+0x69>
movq   $0x0,-0x8(%rbp)
jmp    12a8 <find_mount_point+0x138>
lea    0xe20(%rip),%rdi
lea    0xe23(%rip),%rsi
call   1070 <setmntent@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1208 <find_mount_point+0x98>
movq   $0x0,-0x8(%rbp)
jmp    12a8 <find_mount_point+0x138>
jmp    120d <find_mount_point+0x9d>
mov    -0x38(%rbp),%rdi
call   1060 <getmntent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1297 <find_mount_point+0x127>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xdda(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1245 <find_mount_point+0xd5>
jmp    120d <find_mount_point+0x9d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1264 <find_mount_point+0xf4>
jmp    1297 <find_mount_point+0x127>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jne    1292 <find_mount_point+0x122>
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    1292 <find_mount_point+0x122>
jmp    1297 <find_mount_point+0x127>
jmp    120d <find_mount_point+0x9d>
mov    -0x38(%rbp),%rdi
call   1030 <endmntent@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_mount_point>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
test   %rax,%rax
js     11b1 <find_mount_point+0x41>
mov    0x8(%rsp),%r13
mov    0x10(%rsp),%edi
call   1090 <S_ISBLK@plt>
test   %rax,%rax
jne    11b1 <find_mount_point+0x41>
mov    0x10(%rsp),%edi
call   1080 <S_ISCHR@plt>
test   %rax,%rax
je     11c5 <find_mount_point+0x55>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe34(%rip),%rdi
lea    0xe37(%rip),%rsi
call   1070 <setmntent@plt>
test   %rax,%rax
je     11b1 <find_mount_point+0x41>
mov    %rax,%r15
mov    %rax,%rdi
call   1060 <getmntent@plt>
test   %rax,%rax
je     124d <find_mount_point+0xdd>
mov    %rax,%rbx
lea    0xe15(%rip),%r12
jmp    1210 <find_mount_point+0xa0>
nopl   0x0(%rax)
mov    %r15,%rdi
call   1060 <getmntent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     124d <find_mount_point+0xdd>
mov    (%rbx),%rdi
mov    %r12,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1200 <find_mount_point+0x90>
mov    0x8(%rbx),%rbp
mov    %r14,%rdi
mov    %rbp,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     124f <find_mount_point+0xdf>
mov    %rbp,%rdi
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
test   %rax,%rax
jne    1200 <find_mount_point+0x90>
cmp    %r13,0x8(%rsp)
jne    1200 <find_mount_point+0x90>
jmp    124f <find_mount_point+0xdf>
xor    %ebx,%ebx
mov    %r15,%rdi
call   1030 <endmntent@plt>
jmp    11b3 <find_mount_point+0x43>

LLVM IR (-O0):
%struct.mntent = type { i8*, i8* }
%struct.stat = type { i64, i32 }
@.str = [10 x i8] c"/etc/mtab\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"rootfs\00"
define %struct.mntent* @find_mount_point(i8* %0) {
%2 = alloca %struct.mntent*
%3 = alloca i8*
%4 = alloca %struct.mntent*
%5 = alloca i64
%6 = alloca %struct.stat
%7 = alloca i32*
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i64 @stat(i8* %8, %struct.stat* %6)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store %struct.mntent* null, %struct.mntent** %2
br label %67
12: ; preds = %1
%13 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%14 = load i64, i64* %13
store i64 %14, i64* %5
%15 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%16 = load i32, i32* %15
%17 = call i64 @S_ISBLK(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %12
%20 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%21 = load i32, i32* %20
%22 = call i64 @S_ISCHR(i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19, %12
store %struct.mntent* null, %struct.mntent** %2
br label %67
25: ; preds = %19
%26 = 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* %26, i32** %7
%27 = load i32*, i32** %7
%28 = icmp ne i32* %27, null
br i1 %28, label %30, label %29
29: ; preds = %25
store %struct.mntent* null, %struct.mntent** %2
br label %67
30: ; preds = %25
br label %31
31: ; preds = %62, %41, %30
%32 = load i32*, i32** %7
%33 = call %struct.mntent* @getmntent(i32* %32)
store %struct.mntent* %33, %struct.mntent** %4
%34 = icmp ne %struct.mntent* %33, null
br i1 %34, label %35, label %63
35: ; preds = %31
%36 = load %struct.mntent*, %struct.mntent** %4
%37 = getelementptr inbounds %struct.mntent, %struct.mntent* %36, i32 0, i32 0
%38 = load i8*, i8** %37
%39 = call i32 @strcmp(i8* %38, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%40 = icmp ne i32 %39, 0
br i1 %40, label %42, label %41
41: ; preds = %35
br label %31
42: ; preds = %35
%43 = load i8*, i8** %3
%44 = load %struct.mntent*, %struct.mntent** %4
%45 = getelementptr inbounds %struct.mntent, %struct.mntent* %44, i32 0, i32 1
%46 = load i8*, i8** %45
%47 = call i32 @strcmp(i8* %43, i8* %46)
%48 = icmp ne i32 %47, 0
br i1 %48, label %50, label %49
49: ; preds = %42
br label %63
50: ; preds = %42
%51 = load %struct.mntent*, %struct.mntent** %4
%52 = getelementptr inbounds %struct.mntent, %struct.mntent* %51, i32 0, i32 1
%53 = load i8*, i8** %52
%54 = call i64 @stat(i8* %53, %struct.stat* %6)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %62
56: ; preds = %50
%57 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%58 = load i64, i64* %57
%59 = load i64, i64* %5
%60 = icmp eq i64 %58, %59
br i1 %60, label %61, label %62
61: ; preds = %56
br label %63
62: ; preds = %56, %50
br label %31
63: ; preds = %61, %49, %31
%64 = load i32*, i32** %7
%65 = call i32 @endmntent(i32* %64)
%66 = load %struct.mntent*, %struct.mntent** %4
store %struct.mntent* %66, %struct.mntent** %2
br label %67
67: ; preds = %63, %29, %24, %11
%68 = load %struct.mntent*, %struct.mntent** %2
ret %struct.mntent* %68
}

LLVM IR (-O2):
%struct.mntent = type { i8*, i8* }
%struct.stat = type { i64, i32 }
@.str = [10 x i8] c"/etc/mtab\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"rootfs\00"
define %struct.mntent* @find_mount_point(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @stat(i8* %0, %struct.stat* %2)
%5 = icmp slt i64 %4, 0
br i1 %5, label %46, label %6
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%8 = load i64, i64* %7
%9 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%10 = load i32, i32* %9
%11 = call i64 @S_ISBLK(i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %46
13: ; preds = %6
%14 = load i32, i32* %9
%15 = call i64 @S_ISCHR(i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %46
17: ; preds = %13
%18 = 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))
%19 = icmp eq i32* %18, null
br i1 %19, label %46, label %20
20: ; preds = %17
%21 = call %struct.mntent* @getmntent(i32* %18)
%22 = icmp eq %struct.mntent* %21, null
br i1 %22, label %43, label %23
23: ; preds = %20, %29
%24 = phi %struct.mntent* [ %30, %29 ], [ %21, %20 ]
%25 = getelementptr inbounds %struct.mntent, %struct.mntent* %24, i64 0, i32 0
%26 = load i8*, i8** %25
%27 = call i32 @strcmp(i8* dereferenceable(1) %26, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %23, %37
%30 = call %struct.mntent* @getmntent(i32* %18)
%31 = icmp eq %struct.mntent* %30, null
br i1 %31, label %43, label %23
32: ; preds = %23
%33 = getelementptr inbounds %struct.mntent, %struct.mntent* %24, i64 0, i32 1
%34 = load i8*, i8** %33
%35 = call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(1) %34)
%36 = icmp eq i32 %35, 0
br i1 %36, label %43, label %37
37: ; preds = %32
%38 = call i64 @stat(i8* %34, %struct.stat* %2)
%39 = icmp eq i64 %38, 0
%40 = load i64, i64* %7
%41 = icmp eq i64 %40, %8
%42 = select i1 %39, i1 %41, i1 false
br i1 %42, label %43, label %29
43: ; preds = %29, %32, %37, %20
%44 = phi %struct.mntent* [ null, %20 ], [ %24, %37 ], [ %24, %32 ], [ null, %29 ]
%45 = call i32 @endmntent(i32* %18)
br label %46
46: ; preds = %17, %6, %13, %1, %43
%47 = phi %struct.mntent* [ %44, %43 ], [ null, %1 ], [ null, %13 ], [ null, %6 ], [ null, %17 ]
ret %struct.mntent* %47
}