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

/* Variables and functions */
int /*<<< orphan*/ CPU_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ core_set_no_affinity();
int getpid();
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ sched_setaffinity(int, int, int /*<<< orphan*/ *);
void core_set_affinity(int processor) {
  int set_affinity;
  core_set_no_affinity();
  set_affinity = 0;
  if (!set_affinity) {
    return;
  }
  cpu_set_t mask;
  pid_t process;
  if (processor < 0) {
    return;
  }
  process = getpid();
  CPU_ZERO(&mask);
  CPU_SET(processor, &mask);
  sched_setaffinity(process, sizeof(mask), &mask);
  printf("AFFINITY: the affinity of process %d has been set to CPU %d\n",
         process, processor);
}


x86 assembly (clang, -O0):
<core_set_affinity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1030 <core_set_no_affinity@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1188 <core_set_affinity+0x28>
jmp    11d9 <core_set_affinity+0x79>
cmpl   $0x0,-0x4(%rbp)
jge    1197 <core_set_affinity+0x37>
jmp    11d9 <core_set_affinity+0x79>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x10(%rbp)
lea    -0xc(%rbp),%rdi
call   1070 <CPU_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0xc(%rbp),%rsi
call   1080 <CPU_SET@plt>
mov    -0x10(%rbp),%edi
mov    $0x4,%esi
lea    -0xc(%rbp),%rdx
call   1060 <sched_setaffinity@plt>
mov    -0x10(%rbp),%esi
mov    -0x4(%rbp),%edx
lea    0xe2c(%rip),%rdi
call   1050 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<core_set_affinity>:
xor    %eax,%eax
jmp    1030 <core_set_no_affinity@plt>

LLVM IR (-O0):
@.str = [61 x i8] c"AFFINITY: the affinity of process %d has been set to CPU %d\0A\00"
define void @core_set_affinity(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = call i32 (...) @core_set_no_affinity()
store i32 0, i32* %3
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %1
br label %24
10: ; preds = %1
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10
br label %24
14: ; preds = %10
%15 = call i32 (...) @getpid()
store i32 %15, i32* %5
%16 = call i32 @CPU_ZERO(i32* %4)
%17 = load i32, i32* %2
%18 = call i32 @CPU_SET(i32 %17, i32* %4)
%19 = load i32, i32* %5
%20 = call i32 @sched_setaffinity(i32 %19, i32 4, i32* %4)
%21 = load i32, i32* %5
%22 = load i32, i32* %2
%23 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %22)
br label %24
24: ; preds = %14, %13, %9
ret void
}

LLVM IR (-O2):
define void @core_set_affinity(i32 %0) {
%2 = tail call i32 (...) @core_set_no_affinity()
ret void
}