#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 /*<<< orphan*/ CPU_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_status(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int sched_getaffinity(int /*<<< orphan*/, int, int /*<<< orphan*/ *);
int sched_setaffinity(int /*<<< orphan*/, int, int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  cpu_set_t set;
  int ret, i;
  CPU_ZERO(&set);
  ret = sched_getaffinity(0, sizeof(cpu_set_t), &set);
  if (ret == -1)
    perror("sched_getaffinity");
  print_status(&set);
  printf("Now, let's trying to unset CPU #1\n");
  CPU_CLR(1, &set);
  ret = sched_setaffinity(0, sizeof(cpu_set_t), &set);
  if (ret == -1)
    perror("sched_setaffinity");
  print_status(&set);
  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)
lea    -0x14(%rbp),%rdi
call   1060 <CPU_ZERO@plt>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0x14(%rbp),%rdx
call   1080 <sched_getaffinity@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11b8 <main+0x48>
lea    0xe4d(%rip),%rdi
call   1070 <perror@plt>
lea    -0x14(%rbp),%rdi
call   1050 <print_status@plt>
lea    0xe4a(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
lea    -0x14(%rbp),%rsi
call   1090 <CPU_CLR@plt>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0x14(%rbp),%rdx
call   1040 <sched_setaffinity@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1204 <main+0x94>
lea    0xe36(%rip),%rdi
call   1070 <perror@plt>
lea    -0x14(%rbp),%rdi
call   1050 <print_status@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <CPU_ZERO@plt>
xor    %edi,%edi
mov    $0x4,%esi
mov    %rbx,%rdx
call   1080 <sched_getaffinity@plt>
cmp    $0xffffffff,%eax
je     11e2 <main+0x72>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <print_status@plt>
lea    0xe7a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
call   1090 <CPU_CLR@plt>
xor    %edi,%edi
mov    $0x4,%esi
mov    %rbx,%rdx
call   1040 <sched_setaffinity@plt>
cmp    $0xffffffff,%eax
je     11f0 <main+0x80>
lea    0xc(%rsp),%rdi
call   1050 <print_status@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe17(%rip),%rdi
call   1070 <perror@plt>
jmp    1196 <main+0x26>
lea    0xe1b(%rip),%rdi
call   1070 <perror@plt>
jmp    11d0 <main+0x60>

LLVM IR (-O0):
@.str = [18 x i8] c"sched_getaffinity\00"
@.str.1 = [35 x i8] c"Now, let's trying to unset CPU\0A\00"
@.str.2 = [18 x i8] c"sched_setaffinity\00"
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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @CPU_ZERO(i32* %6)
%10 = call i32 @sched_getaffinity(i32 0, i32 4, i32* %6)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = call i32 @print_status(i32* %6)
%17 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @CPU_CLR(i32 1, i32* %6)
%19 = call i32 @sched_setaffinity(i32 0, i32 4, i32* %6)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %15
%25 = call i32 @print_status(i32* %6)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"sched_getaffinity\00"
@.str.2 = [18 x i8] c"sched_setaffinity\00"
@str = [34 x i8] c"Now, let's trying to unset CPU\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @CPU_ZERO(i32* %3)
%6 = call i32 @sched_getaffinity(i32 0, i32 4, i32* %3)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = call i32 @print_status(i32* %3)
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%13 = call i32 @CPU_CLR(i32 1, i32* %3)
%14 = call i32 @sched_setaffinity(i32 0, i32 4, i32* %3)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
%19 = call i32 @print_status(i32* %3)
ret i32 0
}