#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*/ exit(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ sched_setaffinity(int /*<<< orphan*/, int, int /*<<< orphan*/ *);
void set_cpu(int cpu) {
  cpu_set_t cpuset;
  if (cpu == -1)
    return;
  CPU_ZERO(&cpuset);
  CPU_SET(cpu, &cpuset);
  if (sched_setaffinity(0, sizeof(cpuset), &cpuset)) {
    perror("sched_setaffinity");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<set_cpu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    116a <set_cpu+0x1a>
jmp    11af <set_cpu+0x5f>
lea    -0x8(%rbp),%rdi
call   1040 <CPU_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1070 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0x8(%rbp),%rdx
call   1030 <sched_setaffinity@plt>
cmp    $0x0,%rax
je     11af <set_cpu+0x5f>
lea    0xe60(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_cpu>:
push   %r14
push   %rbx
push   %rax
cmp    $0xffffffff,%edi
je     1186 <set_cpu+0x36>
mov    %edi,%ebx
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1040 <CPU_ZERO@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1070 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
mov    %r14,%rdx
call   1030 <sched_setaffinity@plt>
test   %rax,%rax
jne    118e <set_cpu+0x3e>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe6b(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"sched_setaffinity\00"
define void @set_cpu(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %7
6: ; preds = %1
br label %16
7: ; preds = %1
%8 = call i32 @CPU_ZERO(i32* %3)
%9 = load i32, i32* %2
%10 = call i32 @CPU_SET(i32 %9, i32* %3)
%11 = call i64 @sched_setaffinity(i32 0, i32 4, i32* %3)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %6, %7
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"sched_setaffinity\00"
define void @set_cpu(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = icmp eq i32 %0, -1
br i1 %4, label %13, label %5
5: ; preds = %1
%6 = call i32 @CPU_ZERO(i32* %2)
%7 = call i32 @CPU_SET(i32 %0, i32* %2)
%8 = call i64 @sched_setaffinity(i32 0, i32 4, i32* %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %5
%11 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %5, %1
ret void
}