#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 pid_hidepid(void) {
  FILE *fp = fopen("/proc/mounts", "r");
  if (!fp)
    return 1;
  char buf[4096];
  while (fgets(buf, 4096, fp)) {
    if (strstr(buf, "proc /proc proc")) {
      fclose(fp);
      if (strstr(buf, "hidepid="))
        return 1;
      return 0;
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<pid_hidepid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
lea    0xeae(%rip),%rdi
lea    0xeb4(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1179 <pid_hidepid+0x39>
movl   $0x1,-0x4(%rbp)
jmp    120d <pid_hidepid+0xcd>
jmp    117e <pid_hidepid+0x3e>
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x1000,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11fd <pid_hidepid+0xbd>
lea    -0x1010(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
je     11f8 <pid_hidepid+0xb8>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x1010(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
je     11ec <pid_hidepid+0xac>
movl   $0x1,-0x4(%rbp)
jmp    120d <pid_hidepid+0xcd>
movl   $0x0,-0x4(%rbp)
jmp    120d <pid_hidepid+0xcd>
jmp    117e <pid_hidepid+0x3e>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pid_hidepid>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
lea    0xead(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11c9 <pid_hidepid+0x89>
mov    %rax,%rbx
mov    %rsp,%r14
lea    0xe9e(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x1000,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11d0 <pid_hidepid+0x90>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     1180 <pid_hidepid+0x40>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe6b(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
jmp    11da <pid_hidepid+0x9a>
mov    $0x1,%eax
jmp    11da <pid_hidepid+0x9a>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%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"
@.str.2 = [16 x i8] c"proc /proc proc\00"
@.str.3 = [9 x i8] c"hidepid=\00"
define i32 @pid_hidepid() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [4096 x i8]
%4 = 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* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp ne i32* %5, null
br i1 %6, label %8, label %7
7: ; preds = %0
store i32 1, i32* %1
br label %30
8: ; preds = %0
br label %9
9: ; preds = %26, %8
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%11 = load i32*, i32** %2
%12 = call i64 @fgets(i8* %10, i32 4096, i32* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %27
14: ; preds = %9
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%16 = call i64 @strstr(i8* %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = load i32*, i32** %2
%20 = call i32 @fclose(i32* %19)
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%22 = call i64 @strstr(i8* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %18
store i32 1, i32* %1
br label %30
25: ; preds = %18
store i32 0, i32* %1
br label %30
26: ; preds = %14
br label %9
27: ; preds = %9
%28 = load i32*, i32** %2
%29 = call i32 @fclose(i32* %28)
store i32 0, i32* %1
br label %30
30: ; preds = %27, %25, %24, %7
%31 = load i32, i32* %1
ret i32 %31
}

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