#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 */

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *get_file_contents(char *, size_t *);
char *strchr(char const *, char);
size_t strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char const *, size_t);
int is_mounted(const char *path) {
  const char *line;
  int ret = 0;
  size_t pathlen;
  size_t buflen;
  char *buf;
  pathlen = strlen(path);
  buf = get_file_contents("/proc/mounts", &buflen);
  line = buf;
  do {
    const char *newl;
    const char *mnt;
    const char *end;
    mnt = strchr(line, ' ');
    if (mnt) {
      mnt += 1;
      end = strchr(mnt, ' ');
      if (end) {
        if (!strncmp(path, mnt, pathlen) && (end - mnt) == pathlen) {
          ret = 1;
          break;
        }
      }
    }
    newl = strchr(line, '\n');
    if (newl)
      line = newl + 1;
    else
      line = NULL;
  } while (line);
  free(buf);
  return ret;
}


x86 assembly (clang, -O0):
<is_mounted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x20(%rbp)
lea    0xe89(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <get_file_contents@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1217 <is_mounted+0xc7>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     1212 <is_mounted+0xc2>
mov    -0x8(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    120d <is_mounted+0xbd>
mov    -0x48(%rbp),%rax
mov    -0x40(%rbp),%rcx
sub    %rcx,%rax
cmp    -0x20(%rbp),%rax
jne    120d <is_mounted+0xbd>
movl   $0x1,-0x14(%rbp)
jmp    125d <is_mounted+0x10d>
jmp    1212 <is_mounted+0xc2>
jmp    1217 <is_mounted+0xc7>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1245 <is_mounted+0xf5>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    124d <is_mounted+0xfd>
movq   $0x0,-0x10(%rbp)
jmp    1252 <is_mounted+0x102>
cmpq   $0x0,-0x10(%rbp)
jne    118c <is_mounted+0x3c>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_mounted>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1050 <strlen@plt>
mov    %rax,%r12
lea    0xe93(%rip),%rdi
mov    %rsp,%rsi
call   1070 <get_file_contents@plt>
mov    %rax,%r14
mov    %rax,%r13
jmp    1196 <is_mounted+0x46>
nopl   (%rax)
mov    %r13,%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
lea    0x1(%rax),%r13
test   %rax,%rax
je     11e5 <is_mounted+0x95>
mov    %r13,%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1180 <is_mounted+0x30>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1180 <is_mounted+0x30>
mov    %rax,%rbp
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <strncmp@plt>
test   %eax,%eax
jne    1180 <is_mounted+0x30>
sub    %rbx,%rbp
cmp    %r12,%rbp
jne    1180 <is_mounted+0x30>
mov    $0x1,%ebx
jmp    11e7 <is_mounted+0x97>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/proc/mounts\00"
define i32 @is_mounted(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %4
%11 = load i8*, i8** %2
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %5
%13 = call i8* @get_file_contents(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64* %6)
store i8* %13, i8** %7
%14 = load i8*, i8** %7
store i8* %14, i8** %3
br label %15
15: ; preds = %54, %1
%16 = load i8*, i8** %3
%17 = call i8* @strchr(i8* %16, i8 signext 32)
store i8* %17, i8** %9
%18 = load i8*, i8** %9
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %44
20: ; preds = %15
%21 = load i8*, i8** %9
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8* %22, i8** %9
%23 = load i8*, i8** %9
%24 = call i8* @strchr(i8* %23, i8 signext 32)
store i8* %24, i8** %10
%25 = load i8*, i8** %10
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %43
27: ; preds = %20
%28 = load i8*, i8** %2
%29 = load i8*, i8** %9
%30 = load i64, i64* %5
%31 = call i32 @strncmp(i8* %28, i8* %29, i64 %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %42, label %33
33: ; preds = %27
%34 = load i8*, i8** %10
%35 = load i8*, i8** %9
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = load i64, i64* %5
%40 = icmp eq i64 %38, %39
br i1 %40, label %41, label %42
41: ; preds = %33
store i32 1, i32* %4
br label %57
42: ; preds = %33, %27
br label %43
43: ; preds = %42, %20
br label %44
44: ; preds = %43, %15
%45 = load i8*, i8** %3
%46 = call i8* @strchr(i8* %45, i8 signext 10)
store i8* %46, i8** %8
%47 = load i8*, i8** %8
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %52
49: ; preds = %44
%50 = load i8*, i8** %8
%51 = getelementptr inbounds i8, i8* %50, i64 1
store i8* %51, i8** %3
br label %53
52: ; preds = %44
store i8* null, i8** %3
br label %53
53: ; preds = %52, %49
br label %54
54: ; preds = %53
%55 = load i8*, i8** %3
%56 = icmp ne i8* %55, null
br i1 %56, label %15, label %57
57: ; preds = %54, %41
%58 = load i8*, i8** %7
%59 = call i32 @free(i8* %58)
%60 = load i32, i32* %4
ret i32 %60
}

LLVM IR (-O2):
@.str = [13 x i8] c"/proc/mounts\00"
define i32 @is_mounted(i8* nocapture %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = call i8* @get_file_contents(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64* %2)
br label %6
6: ; preds = %22, %1
%7 = phi i8* [ %5, %1 ], [ %25, %22 ]
%8 = call i8* @strchr(i8* dereferenceable(1) %7, i8 signext 32)
%9 = icmp eq i8* %8, null
br i1 %9, label %22, label %10
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %8, i64 1
%12 = call i8* @strchr(i8* %11, i8 signext 32)
%13 = icmp eq i8* %12, null
br i1 %13, label %22, label %14
14: ; preds = %10
%15 = call i32 @strncmp(i8* %0, i8* %11, i64 %4)
%16 = icmp eq i32 %15, 0
%17 = ptrtoint i8* %12 to i64
%18 = ptrtoint i8* %11 to i64
%19 = sub i64 %17, %18
%20 = icmp eq i64 %19, %4
%21 = select i1 %16, i1 %20, i1 false
br i1 %21, label %26, label %22
22: ; preds = %6, %14, %10
%23 = call i8* @strchr(i8* dereferenceable(1) %7, i8 signext 10)
%24 = icmp eq i8* %23, null
%25 = getelementptr inbounds i8, i8* %23, i64 1
br i1 %24, label %26, label %6
26: ; preds = %14, %22
%27 = phi i32 [ 0, %22 ], [ 1, %14 ]
%28 = call i32 @free(i8* %5)
ret i32 %27
}