#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 */
long UINT_MAX;
int /*<<< orphan*/ _SC_NPROCESSORS_ONLN;
long sysconf(int /*<<< orphan*/);
int /*<<< orphan*/ warning(char *);
unsigned get_default_num_threads(void) {
  long nproc = sysconf(_SC_NPROCESSORS_ONLN);
  if (nproc > 0 && nproc <= UINT_MAX)
    return nproc;
  warning("Could not determine number of processors! Assuming 1");
  return 1;
}


x86 assembly (clang, -O0):
<get_default_num_threads>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2eb9(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jle    1165 <get_default_num_threads+0x45>
mov    -0x10(%rbp),%rax
mov    0x2e90(%rip),%rcx
cmp    (%rcx),%rax
jg     1165 <get_default_num_threads+0x45>
mov    -0x10(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    1178 <get_default_num_threads+0x58>
lea    0xe94(%rip),%rdi
call   1030 <warning@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_default_num_threads>:
push   %rax
mov    0x2ec0(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
test   %rax,%rax
jle    1142 <get_default_num_threads+0x22>
mov    0x2ea5(%rip),%rcx
cmp    (%rcx),%rax
jg     1142 <get_default_num_threads+0x22>
pop    %rcx
ret
lea    0xeb7(%rip),%rdi
call   1030 <warning@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@_SC_NPROCESSORS_ONLN = global i32 0
@UINT_MAX = global i64 0
@.str = [53 x i8] c"Could not determine number of processors! Assuming 1\00"
define i32 @get_default_num_threads() {
%1 = alloca i32
%2 = alloca i64
%3 = load i32, i32* @_SC_NPROCESSORS_ONLN
%4 = call i64 @sysconf(i32 %3)
store i64 %4, i64* %2
%5 = load i64, i64* %2
%6 = icmp sgt i64 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %0
%8 = load i64, i64* %2
%9 = load i64, i64* @UINT_MAX
%10 = icmp sle i64 %8, %9
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i64, i64* %2
%13 = trunc i64 %12 to i32
store i32 %13, i32* %1
br label %16
14: ; preds = %7, %0
%15 = call i32 @warning(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %16
16: ; preds = %14, %11
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@_SC_NPROCESSORS_ONLN = global i32 0
@UINT_MAX = global i64 0
@.str = [53 x i8] c"Could not determine number of processors! Assuming 1\00"
define i32 @get_default_num_threads() {
%1 = load i32, i32* @_SC_NPROCESSORS_ONLN
%2 = tail call i64 @sysconf(i32 %1)
%3 = icmp slt i64 %2, 1
%4 = load i64, i64* @UINT_MAX
%5 = icmp sgt i64 %2, %4
%6 = select i1 %3, i1 true, i1 %5
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = trunc i64 %2 to i32
br label %11
9: ; preds = %0
%10 = tail call i32 @warning(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %7
%12 = phi i32 [ %8, %7 ], [ 1, %9 ]
ret i32 %12
}