#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 */
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ logger(int, int /*<<< orphan*/, char *);
char *realpath(char const *, int /*<<< orphan*/ *);
int sscanf(char *, char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
char *strdup(char const *);
int vz_fs_is_mounted(const char *root) {
  FILE *fp;
  char buf[512];
  char mnt[512];
  char *path;
  int ret = 0;
  if ((fp = fopen("/proc/mounts", "r")) == NULL) {
    logger(-1, errno, "unable to open /proc/mounts");
    return -1;
  }
  path = realpath(root, NULL);
  if (path == NULL)
    path = strdup(root);
  while (!feof(fp)) {
    if (fgets(buf, sizeof(buf), fp) == NULL)
      break;
    if (sscanf(buf, "%*[^ ] %s ", mnt) != 1)
      continue;
    if (!strcmp(mnt, path)) {
      ret = 1;
      break;
    }
  }
  free(path);
  fclose(fp);
  return ret;
}


x86 assembly (clang, -O0):
<vz_fs_is_mounted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x42c(%rbp)
lea    0xe51(%rip),%rdi
lea    0xe39(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1200 <vz_fs_is_mounted+0x60>
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edi
lea    0xe13(%rip),%rdx
call   1080 <logger@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ef <vz_fs_is_mounted+0x14f>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1090 <realpath@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    1232 <vz_fs_is_mounted+0x92>
mov    -0x10(%rbp),%rdi
call   10c0 <strdup@plt>
mov    %rax,-0x428(%rbp)
jmp    1237 <vz_fs_is_mounted+0x97>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1255 <vz_fs_is_mounted+0xb5>
jmp    12d1 <vz_fs_is_mounted+0x131>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x200,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    1279 <vz_fs_is_mounted+0xd9>
jmp    12d1 <vz_fs_is_mounted+0x131>
lea    -0x220(%rbp),%rdi
lea    -0x420(%rbp),%rdx
lea    0xd90(%rip),%rsi
call   10a0 <sscanf@plt>
cmp    $0x1,%eax
je     12a1 <vz_fs_is_mounted+0x101>
jmp    1237 <vz_fs_is_mounted+0x97>
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    12cc <vz_fs_is_mounted+0x12c>
movl   $0x1,-0x42c(%rbp)
jmp    12d1 <vz_fs_is_mounted+0x131>
jmp    1237 <vz_fs_is_mounted+0x97>
mov    -0x428(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x42c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vz_fs_is_mounted>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%rbp
lea    0xe56(%rip),%rdi
lea    0xe3e(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     120d <vz_fs_is_mounted+0x6d>
mov    %rax,%rbx
xor    %r14d,%r14d
mov    %rbp,%rdi
xor    %esi,%esi
call   1090 <realpath@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11ef <vz_fs_is_mounted+0x4f>
mov    %rbp,%rdi
call   10c0 <strdup@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     1242 <vz_fs_is_mounted+0xa2>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    122d <vz_fs_is_mounted+0x8d>
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
lea    0xde5(%rip),%rdx
mov    $0xffffffff,%r14d
mov    $0xffffffff,%edi
call   1080 <logger@plt>
mov    %r14d,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x200(%rsp),%r12
lea    0xdcd(%rip),%r13
mov    %rsp,%rbp
jmp    126c <vz_fs_is_mounted+0xcc>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11fb <vz_fs_is_mounted+0x5b>
mov    %r12,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11fb <vz_fs_is_mounted+0x5b>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   10a0 <sscanf@plt>
cmp    $0x1,%eax
jne    1260 <vz_fs_is_mounted+0xc0>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    1260 <vz_fs_is_mounted+0xc0>
mov    $0x1,%r14d
jmp    11fb <vz_fs_is_mounted+0x5b>

LLVM IR (-O0):
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@errno = global i32 0
@.str.2 = [28 x i8] c"unable to open /proc/mounts\00"
@.str.3 = [11 x i8] c"%*[^ ] %s \00"
define i32 @vz_fs_is_mounted(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [512 x i8]
%6 = alloca [512 x i8]
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %8
%9 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* @errno
%13 = call i32 @logger(i32 -1, i32 %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %53
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = call i8* @realpath(i8* %15, i32* null)
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = call i8* @strdup(i8* %20)
store i8* %21, i8** %7
br label %22
22: ; preds = %19, %14
br label %23
23: ; preds = %46, %39, %22
%24 = load i32*, i32** %4
%25 = call i32 @feof(i32* %24)
%26 = icmp ne i32 %25, 0
%27 = xor i1 %26, true
br i1 %27, label %28, label %47
28: ; preds = %23
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%30 = load i32*, i32** %4
%31 = call i32* @fgets(i8* %29, i32 512, i32* %30)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %34
33: ; preds = %28
br label %47
34: ; preds = %28
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%36 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%37 = call i32 @sscanf(i8* %35, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = icmp ne i32 %37, 1
br i1 %38, label %39, label %40
39: ; preds = %34
br label %23
40: ; preds = %34
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%42 = load i8*, i8** %7
%43 = call i32 @strcmp(i8* %41, i8* %42)
%44 = icmp ne i32 %43, 0
br i1 %44, label %46, label %45
45: ; preds = %40
store i32 1, i32* %8
br label %47
46: ; preds = %40
br label %23
47: ; preds = %45, %33, %23
%48 = load i8*, i8** %7
%49 = call i32 @free(i8* %48)
%50 = load i32*, i32** %4
%51 = call i32 @fclose(i32* %50)
%52 = load i32, i32* %8
store i32 %52, i32* %2
br label %53
53: ; preds = %47, %11
%54 = load i32, i32* %2
ret i32 %54
}

LLVM IR (-O2):
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@errno = global i32 0
@.str.2 = [28 x i8] c"unable to open /proc/mounts\00"
@.str.3 = [11 x i8] c"%*[^ ] %s \00"
define i32 @vz_fs_is_mounted(i8* nocapture %0) {
%2 = alloca [512 x i8]
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @errno
%10 = tail call i32 @logger(i32 -1, i32 %9, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %36
11: ; preds = %1
%12 = tail call i8* @realpath(i8* %0, i32* null)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i8* @strdup(i8* %0)
br label %16
16: ; preds = %14, %11
%17 = phi i8* [ %15, %14 ], [ %12, %11 ]
%18 = call i32 @feof(i32* %6)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %32
20: ; preds = %16, %26
%21 = call i32* @fgets(i8* %4, i32 512, i32* %6)
%22 = icmp eq i32* %21, null
br i1 %22, label %32, label %23
23: ; preds = %20
%24 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%25 = icmp eq i32 %24, 1
br i1 %25, label %29, label %26
26: ; preds = %23, %29
%27 = call i32 @feof(i32* %6)
%28 = icmp eq i32 %27, 0
br i1 %28, label %20, label %32
29: ; preds = %23
%30 = call i32 @strcmp(i8* %5, i8* dereferenceable(1) %17)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %26
32: ; preds = %26, %20, %29, %16
%33 = phi i32 [ 0, %16 ], [ 1, %29 ], [ 0, %20 ], [ 0, %26 ]
%34 = call i32 @free(i8* %17)
%35 = call i32 @fclose(i32* %6)
br label %36
36: ; preds = %32, %8
%37 = phi i32 [ -1, %8 ], [ %33, %32 ]
ret i32 %37
}