#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 */
typedef int /*<<< orphan*/ cpu_set_t;

/* Variables and functions */
int CPU_COUNT(int /*<<< orphan*/ *);
int /*<<< orphan*/ _SC_CLK_TCK;
int /*<<< orphan*/ _SC_NPROCESSORS_ONLN;
int /*<<< orphan*/ printf(char *, int, ...);
int sched_getaffinity(int /*<<< orphan*/, int, int /*<<< orphan*/ *);
void *sysconf(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  cpu_set_t cpumask;
  int res = sched_getaffinity(0, sizeof(cpu_set_t), &cpumask);
  long totprocs = sysconf(_SC_NPROCESSORS_ONLN);
  int nprocs = CPU_COUNT(&cpumask);
  int jiffy = sysconf(_SC_CLK_TCK);
  printf("cores (total): %d (%ld)\n", nprocs, totprocs);
  printf("jiffy: %d\n", jiffy);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %edi,%edi
mov    $0x4,%esi
lea    -0x14(%rbp),%rdx
call   1060 <sched_getaffinity@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
mov    %rax,-0x20(%rbp)
lea    -0x14(%rbp),%rdi
call   1040 <CPU_COUNT@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0x4(%rsp),%r14
xor    %edi,%edi
mov    $0x4,%esi
mov    %r14,%rdx
call   1060 <sched_getaffinity@plt>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <CPU_COUNT@plt>
mov    %eax,%ebp
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
mov    %rax,%rbx
lea    0xe72(%rip),%rdi
mov    %ebp,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe78(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@_SC_NPROCESSORS_ONLN = global i32 0
@_SC_CLK_TCK = global i32 0
@.str = [25 x i8] c"cores (total): %d (%ld)\0A\00"
@.str.1 = [11 x i8] c"jiffy: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%10 = call i32 @sched_getaffinity(i32 0, i32 4, i32* %5)
store i32 %10, i32* %6
%11 = load i32, i32* @_SC_NPROCESSORS_ONLN
%12 = call i8* @sysconf(i32 %11)
%13 = ptrtoint i8* %12 to i64
store i64 %13, i64* %7
%14 = call i32 @CPU_COUNT(i32* %5)
store i32 %14, i32* %8
%15 = load i32, i32* @_SC_CLK_TCK
%16 = call i8* @sysconf(i32 %15)
%17 = ptrtoint i8* %16 to i32
store i32 %17, i32* %9
%18 = load i32, i32* %8
%19 = load i64, i64* %7
%20 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %18, i64 %19)
%21 = load i32, i32* %9
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %21)
ret i32 0
}

LLVM IR (-O2):
@_SC_NPROCESSORS_ONLN = global i32 0
@_SC_CLK_TCK = global i32 0
@.str = [25 x i8] c"cores (total): %d (%ld)\0A\00"
@.str.1 = [11 x i8] c"jiffy: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @sched_getaffinity(i32 0, i32 4, i32* %3)
%6 = load i32, i32* @_SC_NPROCESSORS_ONLN
%7 = call i8* @sysconf(i32 %6)
%8 = ptrtoint i8* %7 to i64
%9 = call i32 @CPU_COUNT(i32* %3)
%10 = load i32, i32* @_SC_CLK_TCK
%11 = call i8* @sysconf(i32 %10)
%12 = ptrtoint i8* %11 to i64
%13 = trunc i64 %12 to i32
%14 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %9, i64 %8)
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %13)
ret i32 0
}