#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*/ cpuset;
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 sched_getcpu();
int /*<<< orphan*/ sched_setaffinity(int /*<<< orphan*/, int,
                                     int /*<<< orphan*/ *);
int sysconf(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  cpu_set_t cpuset;
  int total_cpus;
  int c, cpu;
  total_cpus = sysconf(_SC_NPROCESSORS_ONLN);
  cpu = sched_getcpu();
  CPU_ZERO(&cpuset);
  for (c = 0; c < total_cpus; c++) {
    if (c != cpu)
      CPU_SET(c, &cpuset);
  }
  sched_setaffinity(0, sizeof(cpuset), &cpuset);
  CPU_ZERO(&cpuset);
  CPU_SET(cpu, &cpuset);
  sched_setaffinity(0, sizeof(cpuset), &cpuset);
  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)
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1060 <sched_getcpu@plt>
mov    %eax,-0x20(%rbp)
lea    -0x14(%rbp),%rdi
call   1040 <CPU_ZERO@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11c8 <main+0x78>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     11b5 <main+0x65>
mov    -0x1c(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1070 <CPU_SET@plt>
jmp    11ba <main+0x6a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1191 <main+0x41>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0x14(%rbp),%rdx
call   1030 <sched_setaffinity@plt>
lea    -0x14(%rbp),%rdi
call   1040 <CPU_ZERO@plt>
mov    -0x20(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1070 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0x14(%rbp),%rdx
call   1030 <sched_setaffinity@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
mov    %eax,%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <sched_getcpu@plt>
mov    %eax,%r14d
lea    0x4(%rsp),%rdi
call   1040 <CPU_ZERO@plt>
test   %ebp,%ebp
jle    11a8 <main+0x58>
lea    0x4(%rsp),%r15
jmp    1197 <main+0x47>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    %ebx,%ebp
je     11a8 <main+0x58>
cmp    %ebx,%r14d
je     1190 <main+0x40>
mov    %ebx,%edi
mov    %r15,%rsi
call   1070 <CPU_SET@plt>
jmp    1190 <main+0x40>
lea    0x4(%rsp),%rbx
xor    %edi,%edi
mov    $0x4,%esi
mov    %rbx,%rdx
call   1030 <sched_setaffinity@plt>
mov    %rbx,%rdi
call   1040 <CPU_ZERO@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1070 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
mov    %rbx,%rdx
call   1030 <sched_setaffinity@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
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
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @_SC_NPROCESSORS_ONLN
%11 = call i32 @sysconf(i32 %10)
store i32 %11, i32* %7
%12 = call i32 (...) @sched_getcpu()
store i32 %12, i32* %9
%13 = call i32 @CPU_ZERO(i32* %6)
store i32 0, i32* %8
br label %14
14: ; preds = %26, %2
%15 = load i32, i32* %8
%16 = load i32, i32* %7
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %29
18: ; preds = %14
%19 = load i32, i32* %8
%20 = load i32, i32* %9
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* %8
%24 = call i32 @CPU_SET(i32 %23, i32* %6)
br label %25
25: ; preds = %22, %18
br label %26
26: ; preds = %25
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
store i32 %28, i32* %8
br label %14
29: ; preds = %14
%30 = call i32 @sched_setaffinity(i32 0, i32 4, i32* %6)
%31 = call i32 @CPU_ZERO(i32* %6)
%32 = load i32, i32* %9
%33 = call i32 @CPU_SET(i32 %32, i32* %6)
%34 = call i32 @sched_setaffinity(i32 0, i32 4, i32* %6)
ret i32 0
}

LLVM IR (-O2):
@_SC_NPROCESSORS_ONLN = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32, i32* @_SC_NPROCESSORS_ONLN
%6 = tail call i32 @sysconf(i32 %5)
%7 = tail call i32 (...) @sched_getcpu()
%8 = call i32 @CPU_ZERO(i32* %3)
%9 = icmp sgt i32 %6, 0
br i1 %9, label %10, label %18
10: ; preds = %2, %15
%11 = phi i32 [ %16, %15 ], [ 0, %2 ]
%12 = icmp eq i32 %11, %7
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = call i32 @CPU_SET(i32 %11, i32* %3)
br label %15
15: ; preds = %10, %13
%16 = add nuw nsw i32 %11, 1
%17 = icmp eq i32 %16, %6
br i1 %17, label %18, label %10
18: ; preds = %15, %2
%19 = call i32 @sched_setaffinity(i32 0, i32 4, i32* %3)
%20 = call i32 @CPU_ZERO(i32* %3)
%21 = call i32 @CPU_SET(i32 %7, i32* %3)
%22 = call i32 @sched_setaffinity(i32 0, i32 4, i32* %3)
ret i32 0
}