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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ strstr(char *, char *);
int check_if_mounted(char *path) {
  FILE *fp;
  char buf[4096];
  int found = 0;
  fp = fopen("/proc/mounts", "r");
  while (fgets(buf, 4096, fp)) {
    if (strstr(buf, path)) {
      found = 1;
      break;
    }
  }
  fclose(fp);
  return found;
}


x86 assembly (clang, -O0):
<check_if_mounted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1014(%rbp)
lea    0xea0(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x1000,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11bd <check_if_mounted+0x7d>
lea    -0x1010(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
je     11b8 <check_if_mounted+0x78>
movl   $0x1,-0x1014(%rbp)
jmp    11bd <check_if_mounted+0x7d>
jmp    1170 <check_if_mounted+0x30>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1014(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_if_mounted>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rdi,%r14
lea    0xeaa(%rip),%rdi
lea    0xeb0(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     119c <check_if_mounted+0x5c>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     1170 <check_if_mounted+0x30>
mov    $0x1,%ebx
jmp    119e <check_if_mounted+0x5e>
xor    %ebx,%ebx
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @check_if_mounted(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [4096 x i8]
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %5
%6 = 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* %6, i32** %3
br label %7
7: ; preds = %18, %1
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%9 = load i32*, i32** %3
%10 = call i64 @fgets(i8* %8, i32 4096, i32* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %7
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%14 = load i8*, i8** %2
%15 = call i64 @strstr(i8* %13, i8* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 1, i32* %5
br label %19
18: ; preds = %12
br label %7
19: ; preds = %17, %7
%20 = load i32*, i32** %3
%21 = call i32 @fclose(i32* %20)
%22 = load i32, i32* %5
ret i32 %22
}

LLVM IR (-O2):
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @check_if_mounted(i8* %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = 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))
br label %5
5: ; preds = %8, %1
%6 = call i64 @fgets(i8* %3, i32 4096, i32* %4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = call i64 @strstr(i8* %3, i8* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %5, label %11
11: ; preds = %8, %5
%12 = phi i32 [ 0, %5 ], [ 1, %8 ]
%13 = call i32 @fclose(i32* %4)
ret i32 %12
}