#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
unsigned int sysconf(int /*<<< orphan*/);
unsigned int getCoreNumber() {
  static unsigned int nbCore = 0;
  if (nbCore == 0) {
    nbCore = sysconf(_SC_NPROCESSORS_ONLN);
    if (nbCore < 1) {
      fprintf(stderr, "Fail to get the number of CPU\n");
      nbCore = 1;
    }
  }
  return nbCore;
}


x86 assembly (clang, -O0):
<getCoreNumber>:
push   %rbp
mov    %rsp,%rbp
cmpl   $0x0,0x2f09(%rip)
jne    1176 <getCoreNumber+0x56>
mov    0x2eb0(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %eax,0x2eef(%rip)
cmpl   $0x1,0x2ee8(%rip)
jae    1171 <getCoreNumber+0x51>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    0xe9e(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x1,0x2ec3(%rip)
jmp    1176 <getCoreNumber+0x56>
mov    0x2eb8(%rip),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCoreNumber>:
push   %rax
mov    0x2f0d(%rip),%eax
test   %eax,%eax
je     112d <getCoreNumber+0xd>
pop    %rcx
ret
mov    0x2eb4(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %eax,0x2ef3(%rip)
test   %eax,%eax
jne    112b <getCoreNumber+0xb>
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
lea    0xeab(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x1,0x2ed0(%rip)
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@getCoreNumber.nbCore = internal global i32 0
@_SC_NPROCESSORS_ONLN = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"Fail to get the number of CPU\0A\00"
define i32 @getCoreNumber() {
%1 = load i32, i32* @getCoreNumber.nbCore
%2 = icmp eq i32 %1, 0
br i1 %2, label %3, label %12
3: ; preds = %0
%4 = load i32, i32* @_SC_NPROCESSORS_ONLN
%5 = call i32 @sysconf(i32 %4)
store i32 %5, i32* @getCoreNumber.nbCore
%6 = load i32, i32* @getCoreNumber.nbCore
%7 = icmp ult i32 %6, 1
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* @getCoreNumber.nbCore
br label %11
11: ; preds = %8, %3
br label %12
12: ; preds = %11, %0
%13 = load i32, i32* @getCoreNumber.nbCore
ret i32 %13
}

LLVM IR (-O2):
@getCoreNumber.nbCore = internal unnamed_addr global i32 0
@_SC_NPROCESSORS_ONLN = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"Fail to get the number of CPU\0A\00"
define i32 @getCoreNumber() {
%1 = load i32, i32* @getCoreNumber.nbCore
%2 = icmp eq i32 %1, 0
br i1 %2, label %3, label %10
3: ; preds = %0
%4 = load i32, i32* @_SC_NPROCESSORS_ONLN
%5 = tail call i32 @sysconf(i32 %4)
store i32 %5, i32* @getCoreNumber.nbCore
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* @getCoreNumber.nbCore
br label %10
10: ; preds = %3, %7, %0
%11 = phi i32 [ %5, %3 ], [ 1, %7 ], [ %1, %0 ]
ret i32 %11
}