#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*/ logger(int, int /*<<< orphan*/, char *);
int sscanf(char *, char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int vz_fs_is_mounted(char *root) {
  FILE *fp;
  char buf[512];
  char mnt[512];
  int ret = 0;
  if ((fp = fopen("/proc/mounts", "r")) == NULL) {
    logger(-1, errno, "unable to open /proc/mounts");
    return -1;
  }
  while (!feof(fp)) {
    if (fgets(buf, sizeof(buf), fp) == NULL)
      break;
    if (sscanf(buf, "%*[^ ] %s ", mnt) != 1)
      continue;
    if (!strcmp(mnt, root)) {
      ret = 1;
      break;
    }
  }
  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,-0x424(%rbp)
lea    0xe81(%rip),%rdi
lea    0xe69(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11d0 <vz_fs_is_mounted+0x60>
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edi
lea    0xe43(%rip),%rdx
call   1070 <logger@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    127e <vz_fs_is_mounted+0x10e>
jmp    11d5 <vz_fs_is_mounted+0x65>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f3 <vz_fs_is_mounted+0x83>
jmp    126c <vz_fs_is_mounted+0xfc>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x200,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    1217 <vz_fs_is_mounted+0xa7>
jmp    126c <vz_fs_is_mounted+0xfc>
lea    -0x220(%rbp),%rdi
lea    -0x420(%rbp),%rdx
lea    0xdf2(%rip),%rsi
call   1080 <sscanf@plt>
cmp    $0x1,%eax
je     123f <vz_fs_is_mounted+0xcf>
jmp    11d5 <vz_fs_is_mounted+0x65>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1267 <vz_fs_is_mounted+0xf7>
movl   $0x1,-0x424(%rbp)
jmp    126c <vz_fs_is_mounted+0xfc>
jmp    11d5 <vz_fs_is_mounted+0x65>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x424(%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,%r15
lea    0xe86(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11b8 <vz_fs_is_mounted+0x48>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <feof@plt>
xor    %r14d,%r14d
test   %eax,%eax
je     11ed <vz_fs_is_mounted+0x7d>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11d8 <vz_fs_is_mounted+0x68>
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
lea    0xe3a(%rip),%rdx
mov    $0xffffffff,%r14d
mov    $0xffffffff,%edi
call   1070 <logger@plt>
mov    %r14d,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x200(%rsp),%rbp
lea    0xe22(%rip),%r12
mov    %rsp,%r13
jmp    121c <vz_fs_is_mounted+0xac>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11ae <vz_fs_is_mounted+0x3e>
mov    %rbp,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11ae <vz_fs_is_mounted+0x3e>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    1210 <vz_fs_is_mounted+0xa0>
mov    %r13,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    1210 <vz_fs_is_mounted+0xa0>
mov    $0x1,%r14d
jmp    11ae <vz_fs_is_mounted+0x3e>

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 i32
store i8* %0, i8** %3
store i32 0, i32* %7
%8 = 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* %8, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* @errno
%12 = call i32 @logger(i32 -1, i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %42
13: ; preds = %1
br label %14
14: ; preds = %37, %30, %13
%15 = load i32*, i32** %4
%16 = call i32 @feof(i32* %15)
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
br i1 %18, label %19, label %38
19: ; preds = %14
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%21 = load i32*, i32** %4
%22 = call i32* @fgets(i8* %20, i32 512, i32* %21)
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %25
24: ; preds = %19
br label %38
25: ; preds = %19
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%28 = call i32 @sscanf(i8* %26, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = icmp ne i32 %28, 1
br i1 %29, label %30, label %31
30: ; preds = %25
br label %14
31: ; preds = %25
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%33 = load i8*, i8** %3
%34 = call i32 @strcmp(i8* %32, i8* %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %31
store i32 1, i32* %7
br label %38
37: ; preds = %31
br label %14
38: ; preds = %36, %24, %14
%39 = load i32*, i32** %4
%40 = call i32 @fclose(i32* %39)
%41 = load i32, i32* %7
store i32 %41, i32* %2
br label %42
42: ; preds = %38, %10
%43 = load i32, i32* %2
ret i32 %43
}

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 %11, label %8
8: ; preds = %1
%9 = call i32 @feof(i32* %6)
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %26
11: ; preds = %1
%12 = load i32, i32* @errno
%13 = tail call i32 @logger(i32 -1, i32 %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %29
14: ; preds = %8, %20
%15 = call i32* @fgets(i8* %4, i32 512, i32* %6)
%16 = icmp eq i32* %15, null
br i1 %16, label %26, label %17
17: ; preds = %14
%18 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%19 = icmp eq i32 %18, 1
br i1 %19, label %23, label %20
20: ; preds = %17, %23
%21 = call i32 @feof(i32* %6)
%22 = icmp eq i32 %21, 0
br i1 %22, label %14, label %26
23: ; preds = %17
%24 = call i32 @strcmp(i8* %5, i8* dereferenceable(1) %0)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %20
26: ; preds = %20, %14, %23, %8
%27 = phi i32 [ 0, %8 ], [ 1, %23 ], [ 0, %14 ], [ 0, %20 ]
%28 = call i32 @fclose(i32* %6)
br label %29
29: ; preds = %26, %11
%30 = phi i32 [ -1, %11 ], [ %27, %26 ]
ret i32 %30
}