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

/* Variables and functions */
int /*<<< orphan*/ CPU_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ _SC_NPROCESSORS_ONLN;
int /*<<< orphan*/ get_cpu_mask(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ set_cpu_mask(int /*<<< orphan*/, int /*<<< orphan*/ *);
int sysconf(int /*<<< orphan*/);
void active_cpu(uint32_t active_cpu) {
  cpu_set_t cpu_mask;
  int cpu_count = sysconf(_SC_NPROCESSORS_ONLN);
  if (cpu_count < 1) {
    return;
  }
  active_cpu = active_cpu % cpu_count;
  get_cpu_mask(0, &cpu_mask);
  CPU_ZERO(&cpu_mask);
  CPU_SET(active_cpu, &cpu_mask);
  set_cpu_mask(0, &cpu_mask);
}


x86 assembly (clang, -O0):
<active_cpu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jge    117b <active_cpu+0x2b>
jmp    11b0 <active_cpu+0x60>
mov    -0x4(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %edx,-0x4(%rbp)
xor    %edi,%edi
lea    -0x8(%rbp),%rsi
call   1040 <get_cpu_mask@plt>
lea    -0x8(%rbp),%rdi
call   1050 <CPU_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1070 <CPU_SET@plt>
xor    %edi,%edi
lea    -0x8(%rbp),%rsi
call   1030 <set_cpu_mask@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<active_cpu>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
test   %eax,%eax
jle    119b <active_cpu+0x4b>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %edx,%ebp
lea    0x4(%rsp),%rbx
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <get_cpu_mask@plt>
mov    %rbx,%rdi
call   1050 <CPU_ZERO@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <CPU_SET@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1030 <set_cpu_mask@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@_SC_NPROCESSORS_ONLN = global i32 0
define void @active_cpu(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* @_SC_NPROCESSORS_ONLN
%6 = call i32 @sysconf(i32 %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %10
9: ; preds = %1
br label %19
10: ; preds = %1
%11 = load i32, i32* %2
%12 = load i32, i32* %4
%13 = srem i32 %11, %12
store i32 %13, i32* %2
%14 = call i32 @get_cpu_mask(i32 0, i32* %3)
%15 = call i32 @CPU_ZERO(i32* %3)
%16 = load i32, i32* %2
%17 = call i32 @CPU_SET(i32 %16, i32* %3)
%18 = call i32 @set_cpu_mask(i32 0, i32* %3)
br label %19
19: ; preds = %10, %9
ret void
}

LLVM IR (-O2):
@_SC_NPROCESSORS_ONLN = global i32 0
define void @active_cpu(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @_SC_NPROCESSORS_ONLN
%5 = tail call i32 @sysconf(i32 %4)
%6 = icmp slt i32 %5, 1
br i1 %6, label %13, label %7
7: ; preds = %1
%8 = srem i32 %0, %5
%9 = call i32 @get_cpu_mask(i32 0, i32* %2)
%10 = call i32 @CPU_ZERO(i32* %2)
%11 = call i32 @CPU_SET(i32 %8, i32* %2)
%12 = call i32 @set_cpu_mask(i32 0, i32* %2)
br label %13
13: ; preds = %1, %7
ret void
}