#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_SET(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_ZERO(int /*<<< orphan*/ *);
int EXIT_SUCCESS;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_affinity();
int /*<<< orphan*/ printf(char *, int);
int sched_getcpu();
int sched_setaffinity(int /*<<< orphan*/, int, int /*<<< orphan*/ *);
int main(void) {
  cpu_set_t mask;
  print_affinity();
  printf("sched_getcpu = %d\n", sched_getcpu());
  CPU_ZERO(&mask);
  CPU_SET(0, &mask);
  if (sched_setaffinity(0, sizeof(cpu_set_t), &mask) == -1) {
    perror("sched_setaffinity");
    assert(false);
  }
  print_affinity();
  printf("sched_getcpu = %d\n", sched_getcpu());
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1090 <print_affinity@plt>
mov    $0x0,%al
call   1080 <sched_getcpu@plt>
mov    %eax,%esi
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
lea    -0x8(%rbp),%rdi
call   1060 <CPU_ZERO@plt>
xor    %edi,%edi
lea    -0x8(%rbp),%rsi
call   10a0 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0x8(%rbp),%rdx
call   1040 <sched_setaffinity@plt>
cmp    $0xffffffff,%eax
jne    11eb <main+0x6b>
lea    0xe34(%rip),%rdi
call   1070 <perror@plt>
xor    %edi,%edi
call   1050 <assert@plt>
mov    $0x0,%al
call   1090 <print_affinity@plt>
mov    $0x0,%al
call   1080 <sched_getcpu@plt>
mov    %eax,%esi
lea    0xdfe(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1090 <print_affinity@plt>
xor    %eax,%eax
call   1080 <sched_getcpu@plt>
lea    0xe66(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <CPU_ZERO@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   10a0 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
mov    %rbx,%rdx
call   1040 <sched_setaffinity@plt>
cmp    $0xffffffff,%eax
je     11f7 <main+0x77>
xor    %eax,%eax
call   1090 <print_affinity@plt>
xor    %eax,%eax
call   1080 <sched_getcpu@plt>
lea    0xe1f(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe15(%rip),%rdi
call   1070 <perror@plt>
xor    %edi,%edi
call   1050 <assert@plt>
jmp    11cc <main+0x4c>

LLVM IR (-O0):
@.str = [19 x i8] c"sched_getcpu = %d\0A\00"
@.str.1 = [18 x i8] c"sched_setaffinity\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (...) @print_affinity()
%4 = call i32 (...) @sched_getcpu()
%5 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i32 @CPU_ZERO(i32* %2)
%7 = call i32 @CPU_SET(i32 0, i32* %2)
%8 = call i32 @sched_setaffinity(i32 0, i32 4, i32* %2)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @assert(i32 0)
br label %13
13: ; preds = %10, %0
%14 = call i32 (...) @print_affinity()
%15 = call i32 (...) @sched_getcpu()
%16 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @EXIT_SUCCESS
ret i32 %17
}

LLVM IR (-O2):
@.str = [19 x i8] c"sched_getcpu = %d\0A\00"
@.str.1 = [18 x i8] c"sched_setaffinity\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @print_affinity()
%4 = tail call i32 (...) @sched_getcpu()
%5 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i32 @CPU_ZERO(i32* %1)
%7 = call i32 @CPU_SET(i32 0, i32* %1)
%8 = call i32 @sched_setaffinity(i32 0, i32 4, i32* %1)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @assert(i32 0)
br label %13
13: ; preds = %10, %0
%14 = call i32 (...) @print_affinity()
%15 = call i32 (...) @sched_getcpu()
%16 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @EXIT_SUCCESS
ret i32 %17
}