#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(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int get_proc_cpu_nr();
int get_sys_cpu_nr(int);
int /*<<< orphan*/ stderr;
int get_cpu_nr(unsigned int max_nr_cpus, int highest) {
  int cpu_nr;
  if ((cpu_nr = get_sys_cpu_nr(highest)) == 0) {
    cpu_nr = get_proc_cpu_nr();
  }
  if (cpu_nr > max_nr_cpus) {
    fprintf(stderr, ("Cannot handle so many processors!\n"));
    exit(1);
  }
  return cpu_nr;
}


x86 assembly (clang, -O0):
<get_cpu_nr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <get_sys_cpu_nr@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jne    116c <get_cpu_nr+0x2c>
mov    $0x0,%al
call   1050 <get_proc_cpu_nr@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jbe    1197 <get_cpu_nr+0x57>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpu_nr>:
push   %rbx
mov    %edi,%ebx
mov    %esi,%edi
call   1040 <get_sys_cpu_nr@plt>
test   %eax,%eax
jne    1155 <get_cpu_nr+0x15>
xor    %eax,%eax
call   1050 <get_proc_cpu_nr@plt>
cmp    %ebx,%eax
ja     115b <get_cpu_nr+0x1b>
pop    %rbx
ret
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"Cannot handle so many processors!\0A\00"
define i32 @get_cpu_nr(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = call i32 @get_sys_cpu_nr(i32 %6)
store i32 %7, i32* %5
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 (...) @get_proc_cpu_nr()
store i32 %10, i32* %5
br label %11
11: ; preds = %9, %2
%12 = load i32, i32* %5
%13 = load i32, i32* %3
%14 = icmp ugt i32 %12, %13
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %11
%20 = load i32, i32* %5
ret i32 %20
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"Cannot handle so many processors!\0A\00"
define i32 @get_cpu_nr(i32 %0, i32 %1) {
%3 = tail call i32 @get_sys_cpu_nr(i32 %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (...) @get_proc_cpu_nr()
br label %7
7: ; preds = %5, %2
%8 = phi i32 [ %6, %5 ], [ %3, %2 ]
%9 = icmp ugt i32 %8, %0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %7
ret i32 %8
}