#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 */

/* Variables and functions */
int /*<<< orphan*/ _SC_NPROCESSORS_ONLN;
int atoi(char *);
char *getenv(char *);
int sysconf(int /*<<< orphan*/);
int param_nprocs(int n) {
  int nprocs = 0;
  if (n > 0) {
    nprocs = n;
  }
  if (nprocs == 0) {
    char *env = getenv("FIBRIL_NPROCS");
    if (env)
      nprocs = atoi(env);
  }
  int max_nprocs = sysconf(_SC_NPROCESSORS_ONLN);
  if (nprocs <= 0 || nprocs > max_nprocs) {
    nprocs = max_nprocs;
  }
  return nprocs;
}


x86 assembly (clang, -O0):
<param_nprocs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1152 <param_nprocs+0x22>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1188 <param_nprocs+0x58>
lea    0xe9d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1183 <param_nprocs+0x53>
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x8(%rbp)
jmp    1188 <param_nprocs+0x58>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11af <param_nprocs+0x7f>
mov    -0x8(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    11b5 <param_nprocs+0x85>
mov    -0x14(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<param_nprocs>:
push   %rbx
mov    %edi,%ebx
test   %edi,%edi
jg     1156 <param_nprocs+0x26>
lea    0xec2(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1154 <param_nprocs+0x24>
mov    %rax,%rdi
call   1050 <atoi@plt>
mov    %eax,%ebx
jmp    1156 <param_nprocs+0x26>
xor    %ebx,%ebx
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
cmp    %eax,%ebx
mov    %ebx,%ecx
cmovg  %eax,%ecx
test   %ebx,%ebx
cmovg  %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"FIBRIL_NPROCS\00"
@_SC_NPROCESSORS_ONLN = global i32 0
define i32 @param_nprocs(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%6 = load i32, i32* %2
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = load i32, i32* %2
store i32 %9, i32* %3
br label %10
10: ; preds = %8, %1
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %3
br label %20
20: ; preds = %17, %13
br label %21
21: ; preds = %20, %10
%22 = load i32, i32* @_SC_NPROCESSORS_ONLN
%23 = call i32 @sysconf(i32 %22)
store i32 %23, i32* %5
%24 = load i32, i32* %3
%25 = icmp sle i32 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %21
%27 = load i32, i32* %3
%28 = load i32, i32* %5
%29 = icmp sgt i32 %27, %28
br i1 %29, label %30, label %32
30: ; preds = %26, %21
%31 = load i32, i32* %5
store i32 %31, i32* %3
br label %32
32: ; preds = %30, %26
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [14 x i8] c"FIBRIL_NPROCS\00"
@_SC_NPROCESSORS_ONLN = global i32 0
define i32 @param_nprocs(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %3, label %8
3: ; preds = %1
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @atoi(i8* %4)
br label %8
8: ; preds = %3, %6, %1
%9 = phi i32 [ %0, %1 ], [ %7, %6 ], [ 0, %3 ]
%10 = load i32, i32* @_SC_NPROCESSORS_ONLN
%11 = tail call i32 @sysconf(i32 %10)
%12 = icmp slt i32 %9, 1
%13 = icmp sgt i32 %9, %11
%14 = select i1 %12, i1 true, i1 %13
%15 = select i1 %14, i32 %11, i32 %9
ret i32 %15
}