#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 EOF;
int /*<<< orphan*/ R_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
bool sane_proc_pid_info(void) {
  FILE *fp;
  static const char pattern[] = "container=";
  const char *ptr = pattern;
  bool ret = true;
  if (access("/run/systemd/container", R_OK) == 0)
    return false;
  fp = fopen("/proc/1/environ", "r");
  if (!fp)
    return false;
  while (!feof(fp)) {
    int ch = getc(fp);
    if (*ptr == ch) {
      ptr++;
      if (*ptr == '\0') {
        ret = false;
        break;
      }
    } else {
      do {
        ch = getc(fp);
      } while ((ch != EOF) && (ch != '\0'));
      ptr = pattern;
    }
  }
  (void)fclose(fp);
  return ret;
}


x86 assembly (clang, -O0):
<sane_proc_pid_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xea1(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1050 <access@plt>
cmp    $0x0,%rax
jne    1195 <sane_proc_pid_info+0x45>
movl   $0x0,-0x4(%rbp)
jmp    128b <sane_proc_pid_info+0x13b>
lea    0xe86(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c3 <sane_proc_pid_info+0x73>
movl   $0x0,-0x4(%rbp)
jmp    128b <sane_proc_pid_info+0x13b>
jmp    11c8 <sane_proc_pid_info+0x78>
mov    -0x10(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e6 <sane_proc_pid_info+0x96>
jmp    127c <sane_proc_pid_info+0x12c>
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    -0x20(%rbp),%eax
jne    122f <sane_proc_pid_info+0xdf>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    122a <sane_proc_pid_info+0xda>
movl   $0x0,-0x1c(%rbp)
jmp    127c <sane_proc_pid_info+0x12c>
jmp    1277 <sane_proc_pid_info+0x127>
jmp    1234 <sane_proc_pid_info+0xe4>
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%ecx
xor    %eax,%eax
mov    0x2d9c(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x21(%rbp)
je     1261 <sane_proc_pid_info+0x111>
cmpl   $0x0,-0x20(%rbp)
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1234 <sane_proc_pid_info+0xe4>
lea    0xd8d(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11c8 <sane_proc_pid_info+0x78>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sane_proc_pid_info>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
lea    0xea3(%rip),%rdi
call   1050 <access@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     11aa <sane_proc_pid_info+0x5a>
lea    0xea6(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11aa <sane_proc_pid_info+0x5a>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <feof@plt>
mov    $0x1,%r15d
test   %eax,%eax
je     11b6 <sane_proc_pid_info+0x66>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe43(%rip),%r14
mov    0x2e24(%rip),%rbp
mov    %r14,%r12
jmp    11df <sane_proc_pid_info+0x8f>
nopl   0x0(%rax)
mov    %r14,%r12
mov    %rbx,%rdi
call   1040 <feof@plt>
test   %eax,%eax
jne    11a2 <sane_proc_pid_info+0x52>
mov    %rbx,%rdi
call   1070 <getc@plt>
movsbl (%r12),%ecx
cmp    %ecx,%eax
jne    1200 <sane_proc_pid_info+0xb0>
cmpb   $0x0,0x1(%r12)
je     1213 <sane_proc_pid_info+0xc3>
add    $0x1,%r12
jmp    11d3 <sane_proc_pid_info+0x83>
xchg   %ax,%ax
mov    %rbx,%rdi
call   1070 <getc@plt>
test   %eax,%eax
je     11d0 <sane_proc_pid_info+0x80>
cmp    0x0(%rbp),%eax
jne    1200 <sane_proc_pid_info+0xb0>
jmp    11d0 <sane_proc_pid_info+0x80>
xor    %r15d,%r15d
jmp    11a2 <sane_proc_pid_info+0x52>

LLVM IR (-O0):
@sane_proc_pid_info.pattern = internal constant [11 x i8] c"container=\00"
@.str = [23 x i8] c"/run/systemd/container\00"
@R_OK = global i32 0
@.str.1 = [16 x i8] c"/proc/1/environ\00"
@.str.2 = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @sane_proc_pid_info() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @sane_proc_pid_info.pattern, i64 0, i64 0), i8** %3
store i32 1, i32* %4
%6 = load i32, i32* @R_OK
%7 = call i64 @access(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 0, i32* %1
br label %57
10: ; preds = %0
%11 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %11, i32** %2
%12 = load i32*, i32** %2
%13 = icmp ne i32* %12, null
br i1 %13, label %15, label %14
14: ; preds = %10
store i32 0, i32* %1
br label %57
15: ; preds = %10
br label %16
16: ; preds = %52, %15
%17 = load i32*, i32** %2
%18 = call i32 @feof(i32* %17)
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br i1 %20, label %21, label %53
21: ; preds = %16
%22 = load i32*, i32** %2
%23 = call i32 @getc(i32* %22)
store i32 %23, i32* %5
%24 = load i8*, i8** %3
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = load i32, i32* %5
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %38
29: ; preds = %21
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %3
%32 = load i8*, i8** %3
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %29
store i32 0, i32* %4
br label %53
37: ; preds = %29
br label %52
38: ; preds = %21
br label %39
39: ; preds = %49, %38
%40 = load i32*, i32** %2
%41 = call i32 @getc(i32* %40)
store i32 %41, i32* %5
br label %42
42: ; preds = %39
%43 = load i32, i32* %5
%44 = load i32, i32* @EOF
%45 = icmp ne i32 %43, %44
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = load i32, i32* %5
%48 = icmp ne i32 %47, 0
br label %49
49: ; preds = %46, %42
%50 = phi i1 [ false, %42 ], [ %48, %46 ]
br i1 %50, label %39, label %51
51: ; preds = %49
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @sane_proc_pid_info.pattern, i64 0, i64 0), i8** %3
br label %52
52: ; preds = %51, %37
br label %16
53: ; preds = %36, %16
%54 = load i32*, i32** %2
%55 = call i32 @fclose(i32* %54)
%56 = load i32, i32* %4
store i32 %56, i32* %1
br label %57
57: ; preds = %53, %14, %9
%58 = load i32, i32* %1
ret i32 %58
}

LLVM IR (-O2):
@sane_proc_pid_info.pattern = internal unnamed_addr constant [11 x i8] c"container=\00"
@.str = [23 x i8] c"/run/systemd/container\00"
@R_OK = global i32 0
@.str.1 = [16 x i8] c"/proc/1/environ\00"
@.str.2 = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @sane_proc_pid_info() {
%1 = load i32, i32* @R_OK
%2 = tail call i64 @access(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i64 %2, 0
br i1 %3, label %33, label %4
4: ; preds = %0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %33, label %7
7: ; preds = %4
%8 = tail call i32 @feof(i32* %5)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %30
10: ; preds = %7, %26
%11 = phi i8* [ %27, %26 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @sane_proc_pid_info.pattern, i64 0, i64 0), %7 ]
%12 = tail call i32 @getc(i32* %5)
%13 = load i8, i8* %11
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %12, %14
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = getelementptr inbounds i8, i8* %11, i64 1
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %30, label %26
20: ; preds = %10, %20
%21 = tail call i32 @getc(i32* %5)
%22 = load i32, i32* @EOF
%23 = icmp ne i32 %21, %22
%24 = icmp ne i32 %21, 0
%25 = and i1 %24, %23
br i1 %25, label %20, label %26
26: ; preds = %20, %16
%27 = phi i8* [ %17, %16 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @sane_proc_pid_info.pattern, i64 0, i64 0), %20 ]
%28 = tail call i32 @feof(i32* %5)
%29 = icmp eq i32 %28, 0
br i1 %29, label %10, label %30
30: ; preds = %26, %16, %7
%31 = phi i32 [ 1, %7 ], [ 0, %16 ], [ 1, %26 ]
%32 = tail call i32 @fclose(i32* %5)
br label %33
33: ; preds = %4, %0, %30
%34 = phi i32 [ %31, %30 ], [ 0, %0 ], [ 0, %4 ]
ret i32 %34
}