#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(long, int /*<<< orphan*/ *);
int /*<<< orphan*/ _SC_NPROCESSORS_ONLN;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int sched_getaffinity(int /*<<< orphan*/, int, int /*<<< orphan*/ *);
long sysconf(int /*<<< orphan*/);
void print_affinity() {
  cpu_set_t mask;
  long nproc, i;
  if (sched_getaffinity(0, sizeof(cpu_set_t), &mask) == -1) {
    perror("sched_getaffinity");
    assert(false);
  }
  nproc = sysconf(_SC_NPROCESSORS_ONLN);
  printf("sched_getaffinity = ");
  for (i = 0; i < nproc; i++) {
    printf("%d ", CPU_ISSET(i, &mask));
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_affinity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xor    %edi,%edi
mov    $0x4,%esi
lea    -0x4(%rbp),%rdx
call   1080 <sched_getaffinity@plt>
cmp    $0xffffffff,%eax
jne    1194 <print_affinity+0x34>
lea    0xe78(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1050 <assert@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %rax,-0x10(%rbp)
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11f8 <print_affinity+0x98>
mov    -0x18(%rbp),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <CPU_ISSET@plt>
mov    %eax,%esi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11bc <print_affinity+0x5c>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_affinity>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0x4(%rsp),%rdx
xor    %edi,%edi
mov    $0x4,%esi
call   1090 <sched_getaffinity@plt>
cmp    $0xffffffff,%eax
je     11f6 <print_affinity+0x86>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    %rax,%r12
lea    0xe6c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r12,%r12
jle    11e0 <print_affinity+0x70>
lea    0x4(%rsp),%r14
lea    0xe69(%rip),%r15
xor    %ebx,%ebx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <CPU_ISSET@plt>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11c0 <print_affinity+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe03(%rip),%rdi
call   1070 <perror@plt>
xor    %edi,%edi
call   1060 <assert@plt>
jmp    118e <print_affinity+0x1e>

LLVM IR (-O0):
@.str = [18 x i8] c"sched_getaffinity\00"
@_SC_NPROCESSORS_ONLN = global i32 0
@.str.1 = [21 x i8] c"sched_getaffinity = \00"
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [2 x i8] c"\0A\00"
define void @print_affinity() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = call i32 @sched_getaffinity(i32 0, i32 4, i32* %1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @assert(i32 0)
br label %9
9: ; preds = %6, %0
%10 = load i32, i32* @_SC_NPROCESSORS_ONLN
%11 = call i64 @sysconf(i32 %10)
store i64 %11, i64* %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i64 0, i64* %3
br label %13
13: ; preds = %21, %9
%14 = load i64, i64* %3
%15 = load i64, i64* %2
%16 = icmp slt i64 %14, %15
br i1 %16, label %17, label %24
17: ; preds = %13
%18 = load i64, i64* %3
%19 = call i32 @CPU_ISSET(i64 %18, i32* %1)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %17
%22 = load i64, i64* %3
%23 = add nsw i64 %22, 1
store i64 %23, i64* %3
br label %13
24: ; preds = %13
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"sched_getaffinity\00"
@_SC_NPROCESSORS_ONLN = global i32 0
@.str.1 = [21 x i8] c"sched_getaffinity = \00"
@.str.2 = [4 x i8] c"%d \00"
define void @print_affinity() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @sched_getaffinity(i32 0, i32 4, i32* %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @assert(i32 0)
br label %8
8: ; preds = %5, %0
%9 = load i32, i32* @_SC_NPROCESSORS_ONLN
%10 = call i64 @sysconf(i32 %9)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp sgt i64 %10, 0
br i1 %12, label %13, label %19
13: ; preds = %8, %13
%14 = phi i64 [ %17, %13 ], [ 0, %8 ]
%15 = call i32 @CPU_ISSET(i64 %14, i32* %1)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = add nuw nsw i64 %14, 1
%18 = icmp eq i64 %17, %10
br i1 %18, label %19, label %13
19: ; preds = %13, %8
%20 = call i32 @putchar(i32 10)
ret void
}