#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ stderr;
int read_pid_max() {
  int ret, proc_pid_max = 32768;
  FILE *f = fopen("/proc/sys/kernel/pid_max", "r");
  if (!f) {
    fprintf(stderr,
            "Warning: Unable to read /proc/sys/kernel/pid_max, defaulting to");
    fprintf(stderr, " %db for the size of the abort mmap() region\n", 32768);
    return proc_pid_max;
  }
  ret = fscanf(f, "%d", &proc_pid_max);
  if (!ret || ret == EOF) {
    fprintf(stderr,
            "Warning: Unable to read /proc/sys/kernel/pid_max, defaulting to");
    fprintf(stderr, " %db for the size of the abort mmap() region\n", 32768);
    proc_pid_max = 32768;
  }
  fclose(f);
  return proc_pid_max;
}


x86 assembly (clang, -O0):
<read_pid_max>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x8000,-0xc(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xebc(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11af <read_pid_max+0x6f>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    0xe9a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xec3(%rip),%rsi
mov    $0x8000,%edx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    122b <read_pid_max+0xeb>
mov    -0x18(%rbp),%rdi
lea    0xecf(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <fscanf@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11e2 <read_pid_max+0xa2>
mov    -0x8(%rbp),%eax
mov    0x2e0e(%rip),%rcx
cmp    (%rcx),%eax
jne    121c <read_pid_max+0xdc>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
mov    $0x8000,%edx
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x8000,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_pid_max>:
push   %r14
push   %rbx
push   %rax
movl   $0x8000,0x4(%rsp)
lea    0xead(%rip),%rdi
lea    0xebf(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ce <read_pid_max+0x8e>
mov    %rax,%rbx
lea    0xf1b(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
test   %eax,%eax
je     118a <read_pid_max+0x4a>
mov    0x2e62(%rip),%rcx
cmp    (%rcx),%eax
jne    11c0 <read_pid_max+0x80>
mov    0x2e47(%rip),%r14
mov    (%r14),%edi
lea    0xe80(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r14),%edi
lea    0xeaf(%rip),%rsi
mov    $0x8000,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
movl   $0x8000,0x4(%rsp)
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x4(%rsp),%ebx
jmp    11ff <read_pid_max+0xbf>
mov    0x2e03(%rip),%rbx
mov    (%rbx),%edi
lea    0xe3d(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe6d(%rip),%rsi
mov    $0x8000,%ebx
mov    $0x8000,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [25 x i8] c"/proc/sys/kernel/pid_max\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [64 x i8] c"Warning: Unable to read /proc/sys/kernel/pid_max, defaulting to\00"
@.str.3 = [46 x i8] c" %db for the size of the abort mmap() region\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@EOF = global i32 0
define i32 @read_pid_max() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
store i32 32768, i32* %3
%5 = 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* %5, i32** %4
%6 = load i32*, i32** %4
%7 = icmp ne i32* %6, null
br i1 %7, label %14, label %8
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 32768)
%13 = load i32, i32* %3
store i32 %13, i32* %1
br label %32
14: ; preds = %0
%15 = load i32*, i32** %4
%16 = call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
store i32 %16, i32* %2
%17 = load i32, i32* %2
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i32, i32* %2
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %28
23: ; preds = %19, %14
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 32768)
store i32 32768, i32* %3
br label %28
28: ; preds = %23, %19
%29 = load i32*, i32** %4
%30 = call i32 @fclose(i32* %29)
%31 = load i32, i32* %3
store i32 %31, i32* %1
br label %32
32: ; preds = %28, %8
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@.str = [25 x i8] c"/proc/sys/kernel/pid_max\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [64 x i8] c"Warning: Unable to read /proc/sys/kernel/pid_max, defaulting to\00"
@.str.3 = [46 x i8] c" %db for the size of the abort mmap() region\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@EOF = global i32 0
define i32 @read_pid_max() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 32768, i32* %1
%3 = 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))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0))
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 32768)
br label %24
10: ; preds = %0
%11 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%12 = icmp eq i32 %11, 0
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %11, %13
%15 = select i1 %12, i1 true, i1 %14
br i1 %15, label %16, label %21
16: ; preds = %10
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 32768)
store i32 32768, i32* %1
br label %21
21: ; preds = %10, %16
%22 = call i32 @fclose(i32* %3)
%23 = load i32, i32* %1
br label %24
24: ; preds = %21, %5
%25 = phi i32 [ %23, %21 ], [ 32768, %5 ]
ret i32 %25
}