#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 ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ ERANGE;
int /*<<< orphan*/ EXIT_FAILURE;
unsigned long LONG_MAX;
unsigned long LONG_MIN;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
unsigned long strtoul(char *, char **, int /*<<< orphan*/);
void sysflake_check(void) {
  FILE *stream;
  char *line = NULL;
  size_t len = 0;
  stream = fopen("/proc/sys/kernel/pid_max", "r");
  if (stream != NULL) {
    ssize_t read;
    read = getline(&line, &len, stream);
    if (read != -1) {
      char *temp;
      bool ret = true;
      unsigned long int pid_max;
      errno = 0;
      pid_max = strtoul(line, &temp, 0);
      if (temp == line ||
          ((pid_max == LONG_MIN || pid_max == LONG_MAX) && errno == ERANGE)) {
        ret = false;
      }
      if (ret == true) {
        if (pid_max > (1 << 17)) {
          fprintf(stderr, "Sysflake error:\n");
          fprintf(stderr,
                  "/proc/sys/kernel/pid_max is too big on your system!\n");
          exit(EXIT_FAILURE);
        }
      }
    }
    free(line);
    fclose(stream);
  }
}


x86 assembly (clang, -O0):
<sysflake_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe71(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     12b3 <sysflake_check+0x143>
mov    -0x8(%rbp),%rdx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <getline@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
je     12a1 <sysflake_check+0x131>
movl   $0x1,-0x2c(%rbp)
mov    0x2dea(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1240 <sysflake_check+0xd0>
mov    -0x38(%rbp),%rax
mov    0x2ddf(%rip),%rcx
cmp    (%rcx),%rax
je     1226 <sysflake_check+0xb6>
mov    -0x38(%rbp),%rax
mov    0x2dab(%rip),%rcx
cmp    (%rcx),%rax
jne    1247 <sysflake_check+0xd7>
mov    0x2d93(%rip),%rax
mov    (%rax),%rax
mov    0x2da9(%rip),%rcx
cmp    (%rcx),%rax
jne    1247 <sysflake_check+0xd7>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jne    129c <sysflake_check+0x12c>
cmpq   $0x20000,-0x38(%rbp)
jbe    1297 <sysflake_check+0x127>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
lea    0xdac(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
lea    0xda8(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    129c <sysflake_check+0x12c>
jmp    12a1 <sysflake_check+0x131>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sysflake_check>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movq   $0x0,(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe71(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1231 <sysflake_check+0xc1>
mov    %rax,%rbx
mov    %rsp,%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     1207 <sysflake_check+0x97>
mov    0x2dfd(%rip),%r14
movq   $0x0,(%r14)
mov    (%rsp),%rdi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    (%rsp),%rdi
cmp    %rdi,0x8(%rsp)
je     1224 <sysflake_check+0xb4>
mov    0x2dfc(%rip),%rcx
cmp    (%rcx),%rax
je     120d <sysflake_check+0x9d>
mov    0x2dd0(%rip),%rcx
cmp    (%rcx),%rax
je     120d <sysflake_check+0x9d>
cmp    $0x20001,%rax
jb     1224 <sysflake_check+0xb4>
jmp    1239 <sysflake_check+0xc9>
mov    (%rsp),%rdi
jmp    1224 <sysflake_check+0xb4>
mov    (%r14),%rcx
mov    0x2dc9(%rip),%rdx
cmp    (%rdx),%rcx
je     1224 <sysflake_check+0xb4>
cmp    $0x20000,%rax
ja     1239 <sysflake_check+0xc9>
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d90(%rip),%rbx
mov    (%rbx),%edi
lea    0xdd2(%rip),%rsi
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdd5(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"/proc/sys/kernel/pid_max\00"
@.str.1 = [2 x i8] c"r\00"
@errno = global i64 0
@LONG_MIN = global i64 0
@LONG_MAX = global i64 0
@ERANGE = global i64 0
@stderr = global i32 0
@.str.2 = [17 x i8] c"Sysflake error:\0A\00"
@.str.3 = [53 x i8] c"/proc/sys/kernel/pid_max is too big on your system!\0A\00"
@EXIT_FAILURE = global i32 0
define void @sysflake_check() {
%1 = alloca i32*
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
store i8* null, i8** %2
store i64 0, i64* %3
%8 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %1
%9 = load i32*, i32** %1
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %55
11: ; preds = %0
%12 = load i32*, i32** %1
%13 = call i32 @getline(i8** %2, i64* %3, i32* %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %50
16: ; preds = %11
store i32 1, i32* %6
store i64 0, i64* @errno
%17 = load i8*, i8** %2
%18 = call i64 @strtoul(i8* %17, i8** %5, i32 0)
store i64 %18, i64* %7
%19 = load i8*, i8** %5
%20 = load i8*, i8** %2
%21 = icmp eq i8* %19, %20
br i1 %21, label %34, label %22
22: ; preds = %16
%23 = load i64, i64* %7
%24 = load i64, i64* @LONG_MIN
%25 = icmp eq i64 %23, %24
br i1 %25, label %30, label %26
26: ; preds = %22
%27 = load i64, i64* %7
%28 = load i64, i64* @LONG_MAX
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %35
30: ; preds = %26, %22
%31 = load i64, i64* @errno
%32 = load i64, i64* @ERANGE
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %35
34: ; preds = %30, %16
store i32 0, i32* %6
br label %35
35: ; preds = %34, %30, %26
%36 = load i32, i32* %6
%37 = icmp eq i32 %36, 1
br i1 %37, label %38, label %49
38: ; preds = %35
%39 = load i64, i64* %7
%40 = icmp ugt i64 %39, 131072
br i1 %40, label %41, label %48
41: ; preds = %38
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %38
br label %49
49: ; preds = %48, %35
br label %50
50: ; preds = %49, %11
%51 = load i8*, i8** %2
%52 = call i32 @free(i8* %51)
%53 = load i32*, i32** %1
%54 = call i32 @fclose(i32* %53)
br label %55
55: ; preds = %50, %0
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"/proc/sys/kernel/pid_max\00"
@.str.1 = [2 x i8] c"r\00"
@errno = global i64 0
@LONG_MIN = global i64 0
@LONG_MAX = global i64 0
@ERANGE = global i64 0
@stderr = global i32 0
@.str.2 = [17 x i8] c"Sysflake error:\0A\00"
@.str.3 = [53 x i8] c"/proc/sys/kernel/pid_max is too big on your system!\0A\00"
@EXIT_FAILURE = global i32 0
define void @sysflake_check() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i8*
%4 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%5 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %46, label %8
8: ; preds = %0
%9 = call i32 @getline(i8** %1, i64* %2, i32* %6)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = load i8*, i8** %1
br label %42
13: ; preds = %8
%14 = bitcast i8** %3 to i8*
store i64 0, i64* @errno
%15 = load i8*, i8** %1
%16 = call i64 @strtoul(i8* %15, i8** %3, i32 0)
%17 = load i8*, i8** %3
%18 = load i8*, i8** %1
%19 = icmp eq i8* %17, %18
br i1 %19, label %41, label %20
20: ; preds = %13
%21 = load i64, i64* @LONG_MIN
%22 = icmp eq i64 %16, %21
%23 = load i64, i64* @LONG_MAX
%24 = icmp eq i64 %16, %23
%25 = select i1 %22, i1 true, i1 %24
br i1 %25, label %26, label %32
26: ; preds = %20
%27 = load i64, i64* @errno
%28 = load i64, i64* @ERANGE
%29 = icmp ne i64 %27, %28
%30 = icmp ugt i64 %16, 131072
%31 = select i1 %29, i1 %30, i1 false
br i1 %31, label %34, label %41
32: ; preds = %20
%33 = icmp ugt i64 %16, 131072
br i1 %33, label %34, label %41
34: ; preds = %26, %32
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %26, %13, %32
br label %42
42: ; preds = %11, %41
%43 = phi i8* [ %12, %11 ], [ %18, %41 ]
%44 = call i32 @free(i8* %43)
%45 = call i32 @fclose(i32* %6)
br label %46
46: ; preds = %42, %0
ret void
}