#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*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *get_field(char *, int);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ null_endofword(char *);
scalar_t__ strcmp(char *, char const *);
scalar_t__ strstr(char *, char *);
bool is_shared_mount(const char *path) {
  size_t len = 0;
  char *line = NULL;
  FILE *f = NULL;
  f = fopen("/proc/self/mountinfo", "re");
  if (!f)
    return false;
  while (getline(&line, &len, f) != -1) {
    char *opts, *target;
    target = get_field(line, 4);
    if (!target)
      continue;
    opts = get_field(target, 2);
    if (!opts)
      continue;
    null_endofword(target);
    if (strcmp(target, path) != 0)
      continue;
    null_endofword(opts);
    if (strstr(opts, "shared:"))
      return true;
  }
  free(line);
  fclose(f);
  return false;
}


x86 assembly (clang, -O0):
<is_shared_mount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0xe55(%rip),%rdi
lea    0xe63(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d2 <is_shared_mount+0x52>
movl   $0x0,-0x4(%rbp)
jmp    12a7 <is_shared_mount+0x127>
jmp    11d7 <is_shared_mount+0x57>
mov    -0x28(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     128e <is_shared_mount+0x10e>
mov    -0x20(%rbp),%rdi
mov    $0x4,%esi
call   1050 <get_field@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1213 <is_shared_mount+0x93>
jmp    11d7 <is_shared_mount+0x57>
mov    -0x38(%rbp),%rdi
mov    $0x2,%esi
call   1050 <get_field@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1235 <is_shared_mount+0xb5>
jmp    11d7 <is_shared_mount+0x57>
mov    -0x38(%rbp),%rdi
call   1070 <null_endofword@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     125a <is_shared_mount+0xda>
jmp    11d7 <is_shared_mount+0x57>
mov    -0x30(%rbp),%rdi
call   1070 <null_endofword@plt>
mov    -0x30(%rbp),%rdi
lea    0xdaa(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     1289 <is_shared_mount+0x109>
movl   $0x1,-0x4(%rbp)
jmp    12a7 <is_shared_mount+0x127>
jmp    11d7 <is_shared_mount+0x57>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_shared_mount>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r15
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xe56(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbp
xor    %eax,%eax
test   %rbp,%rbp
je     127e <is_shared_mount+0xfe>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rbp,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     126a <is_shared_mount+0xea>
lea    0x8(%rsp),%r12
lea    0x10(%rsp),%rbx
jmp    1203 <is_shared_mount+0x83>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     126a <is_shared_mount+0xea>
mov    0x8(%rsp),%rdi
mov    $0x4,%esi
call   1050 <get_field@plt>
test   %rax,%rax
je     11f0 <is_shared_mount+0x70>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x2,%esi
call   1050 <get_field@plt>
test   %rax,%rax
je     11f0 <is_shared_mount+0x70>
mov    %rax,%r13
mov    %r14,%rdi
call   1070 <null_endofword@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11f0 <is_shared_mount+0x70>
mov    %r13,%rdi
call   1070 <null_endofword@plt>
mov    %r13,%rdi
lea    0xdbf(%rip),%rsi
call   10a0 <strstr@plt>
test   %rax,%rax
je     11f0 <is_shared_mount+0x70>
mov    $0x1,%eax
jmp    127e <is_shared_mount+0xfe>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"/proc/self/mountinfo\00"
@.str.1 = [3 x i8] c"re\00"
@.str.2 = [8 x i8] c"shared:\00"
define i32 @is_shared_mount(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %3
store i64 0, i64* %4
store i8* null, i8** %5
store i32* null, i32** %6
%9 = call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp ne i32* %10, null
br i1 %11, label %13, label %12
12: ; preds = %1
store i32 0, i32* %2
br label %51
13: ; preds = %1
br label %14
14: ; preds = %45, %37, %29, %23, %13
%15 = load i32*, i32** %6
%16 = call i32 @getline(i8** %5, i64* %4, i32* %15)
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %46
18: ; preds = %14
%19 = load i8*, i8** %5
%20 = call i8* @get_field(i8* %19, i32 4)
store i8* %20, i8** %8
%21 = load i8*, i8** %8
%22 = icmp ne i8* %21, null
br i1 %22, label %24, label %23
23: ; preds = %18
br label %14
24: ; preds = %18
%25 = load i8*, i8** %8
%26 = call i8* @get_field(i8* %25, i32 2)
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = icmp ne i8* %27, null
br i1 %28, label %30, label %29
29: ; preds = %24
br label %14
30: ; preds = %24
%31 = load i8*, i8** %8
%32 = call i32 @null_endofword(i8* %31)
%33 = load i8*, i8** %8
%34 = load i8*, i8** %3
%35 = call i64 @strcmp(i8* %33, i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %30
br label %14
38: ; preds = %30
%39 = load i8*, i8** %7
%40 = call i32 @null_endofword(i8* %39)
%41 = load i8*, i8** %7
%42 = call i64 @strstr(i8* %41, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %38
store i32 1, i32* %2
br label %51
45: ; preds = %38
br label %14
46: ; preds = %14
%47 = load i8*, i8** %5
%48 = call i32 @free(i8* %47)
%49 = load i32*, i32** %6
%50 = call i32 @fclose(i32* %49)
store i32 0, i32* %2
br label %51
51: ; preds = %46, %44, %12
%52 = load i32, i32* %2
ret i32 %52
}

LLVM IR (-O2):
@.str = [21 x i8] c"/proc/self/mountinfo\00"
@.str.1 = [3 x i8] c"re\00"
@.str.2 = [8 x i8] c"shared:\00"
define i32 @is_shared_mount(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %33, label %8
8: ; preds = %1
%9 = call i32 @getline(i8** %3, i64* %2, i32* %6)
%10 = icmp eq i32 %9, -1
br i1 %10, label %29, label %11
11: ; preds = %8, %26
%12 = load i8*, i8** %3
%13 = call i8* @get_field(i8* %12, i32 4)
%14 = icmp eq i8* %13, null
br i1 %14, label %26, label %15
15: ; preds = %11
%16 = call i8* @get_field(i8* %13, i32 2)
%17 = icmp eq i8* %16, null
br i1 %17, label %26, label %18
18: ; preds = %15
%19 = call i32 @null_endofword(i8* %13)
%20 = call i64 @strcmp(i8* %13, i8* %0)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = call i32 @null_endofword(i8* %16)
%24 = call i64 @strstr(i8* %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %22, %18, %15, %11
%27 = call i32 @getline(i8** %3, i64* %2, i32* %6)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %11
29: ; preds = %26, %8
%30 = load i8*, i8** %3
%31 = call i32 @free(i8* %30)
%32 = call i32 @fclose(i32* %6)
br label %33
33: ; preds = %22, %1, %29
%34 = phi i32 [ 0, %29 ], [ 0, %1 ], [ 1, %22 ]
ret i32 %34
}