#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 CPU_ISSET(int, 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 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()");
  for (i = 0; i < 10; i++) {
    int cpu = CPU_ISSET(i, &set);
    printf("cpu=%i is %s\n", i, cpu ? "set" : "unset");
  }
}


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   1050 <CPU_ZERO@plt>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0x14(%rbp),%rdx
call   1070 <sched_getaffinity@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1198 <main+0x48>
lea    0xe6d(%rip),%rdi
call   1060 <perror@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    11ed <main+0x9d>
mov    -0x1c(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1040 <CPU_ISSET@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%ecx
lea    0xe5d(%rip),%rdx
lea    0xe58(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
lea    0xe3a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119f <main+0x4f>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <CPU_ZERO@plt>
xor    %edi,%edi
mov    $0x4,%esi
mov    %rbx,%rdx
call   1070 <sched_getaffinity@plt>
cmp    $0xffffffff,%eax
je     12fd <main+0x1ad>
lea    0x4(%rsp),%r14
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <CPU_ISSET@plt>
test   %eax,%eax
lea    0xe8d(%rip),%r12
lea    0xe88(%rip),%rbx
mov    %rbx,%rdx
cmove  %r12,%rdx
lea    0xe6a(%rip),%r15
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
mov    %r14,%rsi
call   1040 <CPU_ISSET@plt>
test   %eax,%eax
mov    %rbx,%rdx
cmove  %r12,%rdx
mov    %r15,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
mov    $0x2,%edi
mov    %r14,%rsi
call   1040 <CPU_ISSET@plt>
test   %eax,%eax
mov    %rbx,%rdx
cmove  %r12,%rdx
mov    %r15,%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
mov    $0x3,%edi
mov    %r14,%rsi
call   1040 <CPU_ISSET@plt>
test   %eax,%eax
mov    %rbx,%rdx
cmove  %r12,%rdx
mov    %r15,%rdi
mov    $0x3,%esi
call   1030 <printf@plt>
mov    $0x4,%edi
mov    %r14,%rsi
call   1040 <CPU_ISSET@plt>
test   %eax,%eax
mov    %rbx,%rdx
cmove  %r12,%rdx
mov    %r15,%rdi
mov    $0x4,%esi
call   1030 <printf@plt>
mov    $0x5,%edi
mov    %r14,%rsi
call   1040 <CPU_ISSET@plt>
test   %eax,%eax
mov    %rbx,%rdx
cmove  %r12,%rdx
mov    %r15,%rdi
mov    $0x5,%esi
call   1030 <printf@plt>
mov    $0x6,%edi
mov    %r14,%rsi
call   1040 <CPU_ISSET@plt>
test   %eax,%eax
mov    %rbx,%rdx
cmove  %r12,%rdx
mov    %r15,%rdi
mov    $0x6,%esi
call   1030 <printf@plt>
mov    $0x7,%edi
mov    %r14,%rsi
call   1040 <CPU_ISSET@plt>
test   %eax,%eax
mov    %rbx,%rdx
cmove  %r12,%rdx
mov    %r15,%rdi
mov    $0x7,%esi
call   1030 <printf@plt>
mov    $0x8,%edi
mov    %r14,%rsi
call   1040 <CPU_ISSET@plt>
test   %eax,%eax
mov    %rbx,%rdx
cmove  %r12,%rdx
mov    %r15,%rdi
mov    $0x8,%esi
call   1030 <printf@plt>
mov    $0x9,%edi
mov    %r14,%rsi
call   1040 <CPU_ISSET@plt>
test   %eax,%eax
cmove  %r12,%rbx
mov    %r15,%rdi
mov    $0x9,%esi
mov    %rbx,%rdx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xcfc(%rip),%rdi
call   1060 <perror@plt>
jmp    117d <main+0x2d>

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

LLVM IR (-O2):
@.str = [20 x i8] c"sched_getaffinity()\00"
@.str.1 = [14 x i8] c"cpu=%i is %s\0A\00"
@.str.2 = [4 x i8] c"set\00"
@.str.3 = [6 x i8] c"unset\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 ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = call i32 @CPU_ISSET(i32 0, i32* %3)
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%14 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 0, i8* %13)
%15 = call i32 @CPU_ISSET(i32 1, i32* %3)
%16 = icmp eq i32 %15, 0
%17 = select i1 %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%18 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 1, i8* %17)
%19 = call i32 @CPU_ISSET(i32 2, i32* %3)
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%22 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 2, i8* %21)
%23 = call i32 @CPU_ISSET(i32 3, i32* %3)
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%26 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 3, i8* %25)
%27 = call i32 @CPU_ISSET(i32 4, i32* %3)
%28 = icmp eq i32 %27, 0
%29 = select i1 %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%30 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 4, i8* %29)
%31 = call i32 @CPU_ISSET(i32 5, i32* %3)
%32 = icmp eq i32 %31, 0
%33 = select i1 %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%34 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 5, i8* %33)
%35 = call i32 @CPU_ISSET(i32 6, i32* %3)
%36 = icmp eq i32 %35, 0
%37 = select i1 %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%38 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 6, i8* %37)
%39 = call i32 @CPU_ISSET(i32 7, i32* %3)
%40 = icmp eq i32 %39, 0
%41 = select i1 %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%42 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 7, i8* %41)
%43 = call i32 @CPU_ISSET(i32 8, i32* %3)
%44 = icmp eq i32 %43, 0
%45 = select i1 %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%46 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 8, i8* %45)
%47 = call i32 @CPU_ISSET(i32 9, i32* %3)
%48 = icmp eq i32 %47, 0
%49 = select i1 %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%50 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 9, i8* %49)
ret i32 0
}