#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*/ cpu_set_t;

/* Variables and functions */
int /*<<< orphan*/ CPU_CLR(int, int /*<<< orphan*/ *);
int CPU_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_SET(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, char *);
int sched_getaffinity(int /*<<< orphan*/, int, int /*<<< orphan*/ *);
int sched_setaffinity(int /*<<< orphan*/, int, int /*<<< orphan*/ *);
int main(void) {
  cpu_set_t set;
  int ret, i;
  CPU_ZERO(&set);
  CPU_SET(0, &set);
  CPU_CLR(1, &set);
  ret = sched_setaffinity(0, sizeof(cpu_set_t), &set);
  if (ret == -1)
    perror("sched_setaffinity");
  ret = sched_getaffinity(0, sizeof(cpu_set_t), &set);
  if (ret == -1)
    perror("sched_getaffinity");
  for (i = 0; i < 2; i++) {
    int cpu;
    cpu = CPU_ISSET(i, &set);
    printf("cpu=%i is %s\n", i, cpu ? "set" : "unset");
  }
  while (1)
    ;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1060 <CPU_ZERO@plt>
xor    %edi,%edi
lea    -0x8(%rbp),%rsi
call   1090 <CPU_SET@plt>
mov    $0x1,%edi
lea    -0x8(%rbp),%rsi
call   10a0 <CPU_CLR@plt>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0x8(%rbp),%rdx
call   1040 <sched_setaffinity@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11da <main+0x5a>
lea    0xe2b(%rip),%rdi
call   1070 <perror@plt>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0x8(%rbp),%rdx
call   1080 <sched_getaffinity@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1203 <main+0x83>
lea    0xe14(%rip),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x2,-0x10(%rbp)
jge    1258 <main+0xd8>
mov    -0x10(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1050 <CPU_ISSET@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%ecx
lea    0xe02(%rip),%rdx
lea    0xdfd(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
lea    0xddf(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    120a <main+0x8a>
jmp    125d <main+0xdd>
jmp    125d <main+0xdd>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <CPU_ZERO@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1090 <CPU_SET@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
call   10a0 <CPU_CLR@plt>
xor    %edi,%edi
mov    $0x4,%esi
mov    %rbx,%rdx
call   1040 <sched_setaffinity@plt>
cmp    $0xffffffff,%eax
je     1232 <main+0xb2>
lea    0x4(%rsp),%rdx
xor    %edi,%edi
mov    $0x4,%esi
call   1080 <sched_getaffinity@plt>
cmp    $0xffffffff,%eax
je     1240 <main+0xc0>
lea    0x4(%rsp),%r14
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <CPU_ISSET@plt>
test   %eax,%eax
lea    0xe44(%rip),%r12
lea    0xe3f(%rip),%rbx
mov    %rbx,%rdx
cmove  %r12,%rdx
lea    0xe21(%rip),%r15
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
mov    %r14,%rsi
call   1050 <CPU_ISSET@plt>
test   %eax,%eax
cmove  %r12,%rbx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
call   1030 <printf@plt>
jmp    1230 <main+0xb0>
lea    0xdc7(%rip),%rdi
call   1070 <perror@plt>
jmp    11c0 <main+0x40>
lea    0xdcb(%rip),%rdi
call   1070 <perror@plt>
jmp    11d6 <main+0x56>

LLVM IR (-O0):
@.str = [18 x i8] c"sched_setaffinity\00"
@.str.1 = [18 x i8] c"sched_getaffinity\00"
@.str.2 = [14 x i8] c"cpu=%i is %s\0A\00"
@.str.3 = [4 x i8] c"set\00"
@.str.4 = [6 x i8] c"unset\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @CPU_ZERO(i32* %2)
%7 = call i32 @CPU_SET(i32 0, i32* %2)
%8 = call i32 @CPU_CLR(i32 1, i32* %2)
%9 = call i32 @sched_setaffinity(i32 0, i32 4, i32* %2)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %0
%15 = call i32 @sched_getaffinity(i32 0, i32 4, i32* %2)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
store i32 0, i32* %4
br label %21
21: ; preds = %33, %20
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 2
br i1 %23, label %24, label %36
24: ; preds = %21
%25 = load i32, i32* %4
%26 = call i32 @CPU_ISSET(i32 %25, i32* %2)
store i32 %26, i32* %5
%27 = load i32, i32* %4
%28 = load i32, i32* %5
%29 = icmp ne i32 %28, 0
%30 = zext i1 %29 to i64
%31 = select i1 %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0)
%32 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %27, i8* %31)
br label %33
33: ; preds = %24
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %21
36: ; preds = %21
br label %37
37: ; preds = %36, %37
br label %37
}

LLVM IR (-O2):
@.str = [18 x i8] c"sched_setaffinity\00"
@.str.1 = [18 x i8] c"sched_getaffinity\00"
@.str.2 = [14 x i8] c"cpu=%i is %s\0A\00"
@.str.3 = [4 x i8] c"set\00"
@.str.4 = [6 x i8] c"unset\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @CPU_ZERO(i32* %1)
%4 = call i32 @CPU_SET(i32 0, i32* %1)
%5 = call i32 @CPU_CLR(i32 1, i32* %1)
%6 = call i32 @sched_setaffinity(i32 0, i32 4, i32* %1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = call i32 @sched_getaffinity(i32 0, i32 4, i32* %1)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = call i32 @CPU_ISSET(i32 0, i32* %1)
%17 = icmp eq i32 %16, 0
%18 = select i1 %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0)
%19 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 0, i8* %18)
%20 = call i32 @CPU_ISSET(i32 1, i32* %1)
%21 = icmp eq i32 %20, 0
%22 = select i1 %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0)
%23 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 1, i8* %22)
br label %24
24: ; preds = %15, %24
br label %24
}