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

/* Variables and functions */
int CPU_COUNT(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int sched_getaffinity(int /*<<< orphan*/, int, int /*<<< orphan*/ *);
int sched_getcpu();
int main(int argc, char **argv) {
  printf("Running CPU test...\n");
  int cpu = sched_getcpu();
  printf("CPU is %d.\n", cpu);
  cpu_set_t mask;
  int retcode = sched_getaffinity(0, sizeof(mask), &mask);
  printf("sched_getaffinity() returned %d.\n", retcode);
  printf("There are %d CPUs.\n", CPU_COUNT(&mask));
  printf("End of CPU test.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <sched_getcpu@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0x18(%rbp),%rdx
call   1060 <sched_getaffinity@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x18(%rbp),%rdi
call   1040 <CPU_COUNT@plt>
mov    %eax,%esi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xee6(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <sched_getcpu@plt>
lea    0xe91(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%rbx
xor    %edi,%edi
mov    $0x4,%esi
mov    %rbx,%rdx
call   1070 <sched_getaffinity@plt>
lea    0xe79(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <CPU_COUNT@plt>
lea    0xe83(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Running CPU test...\0A\00"
@.str.1 = [12 x i8] c"CPU is %d.\0A\00"
@.str.2 = [34 x i8] c"sched_getaffinity() returned %d.\0A\00"
@.str.3 = [20 x i8] c"There are %d CPUs.\0A\00"
@.str.4 = [18 x i8] c"End of CPU test.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (...) @sched_getcpu()
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = call i32 @sched_getaffinity(i32 0, i32 4, i32* %7)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = call i32 @CPU_COUNT(i32* %7)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"CPU is %d.\0A\00"
@.str.2 = [34 x i8] c"sched_getaffinity() returned %d.\0A\00"
@.str.3 = [20 x i8] c"There are %d CPUs.\0A\00"
@str = [20 x i8] c"Running CPU test...\00"
@str.5 = [17 x i8] c"End of CPU test.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 (...) @sched_getcpu()
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = bitcast i32* %3 to i8*
%8 = call i32 @sched_getaffinity(i32 0, i32 4, i32* %3)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = call i32 @CPU_COUNT(i32* %3)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.5, i64 0, i64 0))
ret i32 0
}