#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 /*<<< orphan*/ __CPU_SET_S(int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ __CPU_ZERO_S(int, int /*<<< orphan*/ *);
int sched_setaffinity(int /*<<< orphan*/, int, int /*<<< orphan*/ *);
int setaffinity(int num) {
  cpu_set_t mask;
  int rc;
  if (num > 128 || num < 0) {
    return -1;
  }
  __CPU_ZERO_S(sizeof(cpu_set_t), &mask);
  __CPU_SET_S(num, sizeof(cpu_set_t), &mask);
  rc = sched_setaffinity(0, sizeof(mask), &mask);
  if (rc != 0) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<setaffinity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x80,-0x8(%rbp)
jg     1152 <setaffinity+0x22>
cmpl   $0x0,-0x8(%rbp)
jge    115e <setaffinity+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ad <setaffinity+0x7d>
mov    $0x4,%edi
lea    -0xc(%rbp),%rsi
call   1040 <__CPU_ZERO_S@plt>
mov    -0x8(%rbp),%edi
mov    $0x4,%esi
lea    -0xc(%rbp),%rdx
call   1050 <__CPU_SET_S@plt>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0xc(%rbp),%rdx
call   1030 <sched_setaffinity@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11a6 <setaffinity+0x76>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ad <setaffinity+0x7d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setaffinity>:
mov    $0xffffffff,%eax
cmp    $0x80,%edi
ja     117e <setaffinity+0x4e>
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0x4(%rsp),%r14
mov    $0x4,%edi
mov    %r14,%rsi
call   1040 <__CPU_ZERO_S@plt>
mov    %ebx,%edi
mov    $0x4,%esi
mov    %r14,%rdx
call   1050 <__CPU_SET_S@plt>
xor    %edi,%edi
mov    $0x4,%esi
mov    %r14,%rdx
call   1030 <sched_setaffinity@plt>
neg    %eax
sbb    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @setaffinity(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = icmp sgt i32 %6, 128
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %8, %1
store i32 -1, i32* %2
br label %21
12: ; preds = %8
%13 = call i32 @__CPU_ZERO_S(i32 4, i32* %4)
%14 = load i32, i32* %3
%15 = call i32 @__CPU_SET_S(i32 %14, i32 4, i32* %4)
%16 = call i32 @sched_setaffinity(i32 0, i32 4, i32* %4)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %12
store i32 -1, i32* %2
br label %21
20: ; preds = %12
store i32 0, i32* %2
br label %21
21: ; preds = %20, %19, %11
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
define i32 @setaffinity(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = icmp ugt i32 %0, 128
br i1 %4, label %11, label %5
5: ; preds = %1
%6 = call i32 @__CPU_ZERO_S(i32 4, i32* %2)
%7 = call i32 @__CPU_SET_S(i32 %0, i32 4, i32* %2)
%8 = call i32 @sched_setaffinity(i32 0, i32 4, i32* %2)
%9 = icmp ne i32 %8, 0
%10 = sext i1 %9 to i32
br label %11
11: ; preds = %5, %1
%12 = phi i32 [ -1, %1 ], [ %10, %5 ]
ret i32 %12
}