#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*/ EXIT_FAILURE;
int /*<<< orphan*/ _SC_NPROCESSORS_CONF;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ sysconf(int /*<<< orphan*/);
int get_total_cpus(void) {
  int nr_cpus = (int)sysconf(_SC_NPROCESSORS_CONF);
  if (nr_cpus <= 0) {
    fprintf(stderr, "Could not read cpus\n");
    goto error;
  } else if (nr_cpus > 256) {
    fprintf(stderr, "Exceed max cpus(%d)\n", (int)256);
    goto error;
  }
  return nr_cpus;
error:
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<get_total_cpus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     116f <get_total_cpus+0x3f>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
lea    0xe9d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11ab <get_total_cpus+0x7b>
cmpl   $0x100,-0x4(%rbp)
jle    119d <get_total_cpus+0x6d>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
mov    $0x100,%edx
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11ab <get_total_cpus+0x7b>
jmp    11a2 <get_total_cpus+0x72>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<get_total_cpus>:
push   %rax
mov    0x2e98(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
test   %eax,%eax
jle    114c <get_total_cpus+0x1c>
cmp    $0x101,%eax
jae    1165 <get_total_cpus+0x35>
pop    %rcx
ret
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
lea    0xea4(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    1181 <get_total_cpus+0x51>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
mov    $0x100,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@_SC_NPROCESSORS_CONF = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"Could not read cpus\0A\00"
@.str.1 = [21 x i8] c"Exceed max cpus(%d)\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @get_total_cpus() {
%1 = alloca i32
%2 = load i32, i32* @_SC_NPROCESSORS_CONF
%3 = call i64 @sysconf(i32 %2)
%4 = trunc i64 %3 to i32
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = icmp sle i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %19
10: ; preds = %0
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 256
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 256)
br label %19
16: ; preds = %10
br label %17
17: ; preds = %16
%18 = load i32, i32* %1
ret i32 %18
19: ; preds = %13, %7
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
}

LLVM IR (-O2):
@_SC_NPROCESSORS_CONF = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"Could not read cpus\0A\00"
@.str.1 = [21 x i8] c"Exceed max cpus(%d)\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @get_total_cpus() {
%1 = load i32, i32* @_SC_NPROCESSORS_CONF
%2 = tail call i64 @sysconf(i32 %1)
%3 = trunc i64 %2 to i32
%4 = icmp slt i32 %3, 1
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %14
8: ; preds = %0
%9 = icmp ugt i32 %3, 256
br i1 %9, label %10, label %13
10: ; preds = %8
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 256)
br label %14
13: ; preds = %8
ret i32 %3
14: ; preds = %10, %5
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
}