#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_FREE(int /*<<< orphan*/ *);
unsigned long long cpusettoull(int /*<<< orphan*/ *, size_t);
int num_online_cpus();
int read_mapping(int, char *, int /*<<< orphan*/ **, size_t *);
int domain_to_cpus(int domain, unsigned long long int *mask) {
  cpu_set_t *bits;
  size_t sz;
  int ret;
  if (num_online_cpus() > sizeof(unsigned long long int) * 8)
    return -1;
  ret = read_mapping(domain, "domains", &bits, &sz);
  if (!ret) {
    *mask = cpusettoull(bits, sz);
    CPU_FREE(bits);
  }
  return ret;
}


x86 assembly (clang, -O0):
<domain_to_cpus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <num_online_cpus@plt>
cltq
cmp    $0x40,%rax
jbe    116e <domain_to_cpus+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b8 <domain_to_cpus+0x78>
mov    -0x8(%rbp),%edi
lea    0xe88(%rip),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1060 <read_mapping@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11b2 <domain_to_cpus+0x72>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <cpusettoull@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rdi
call   1040 <CPU_FREE@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<domain_to_cpus>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1030 <num_online_cpus@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x40,%ecx
ja     1198 <domain_to_cpus+0x58>
lea    0xe9b(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %ebp,%edi
call   1060 <read_mapping@plt>
test   %eax,%eax
jne    1198 <domain_to_cpus+0x58>
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
call   1050 <cpusettoull@plt>
mov    %rax,(%rbx)
mov    0x8(%rsp),%rdi
call   1040 <CPU_FREE@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"domains\00"
define i32 @domain_to_cpus(i32 %0, i64* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32
store i32 %0, i32* %4
store i64* %1, i64** %5
%9 = call i32 (...) @num_online_cpus()
%10 = sext i32 %9 to i64
%11 = icmp ugt i64 %10, 64
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %27
13: ; preds = %2
%14 = load i32, i32* %4
%15 = call i32 @read_mapping(i32 %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32** %6, i64* %7)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp ne i32 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %13
%19 = load i32*, i32** %6
%20 = load i64, i64* %7
%21 = call i64 @cpusettoull(i32* %19, i64 %20)
%22 = load i64*, i64** %5
store i64 %21, i64* %22
%23 = load i32*, i32** %6
%24 = call i32 @CPU_FREE(i32* %23)
br label %25
25: ; preds = %18, %13
%26 = load i32, i32* %8
store i32 %26, i32* %3
br label %27
27: ; preds = %25, %12
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@.str = [8 x i8] c"domains\00"
define i32 @domain_to_cpus(i32 %0, i64* nocapture writeonly %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = bitcast i32** %3 to i8*
%6 = bitcast i64* %4 to i8*
%7 = tail call i32 (...) @num_online_cpus()
%8 = icmp ugt i32 %7, 64
br i1 %8, label %18, label %9
9: ; preds = %2
%10 = call i32 @read_mapping(i32 %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32** %3, i64* %4)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = load i32*, i32** %3
%14 = load i64, i64* %4
%15 = call i64 @cpusettoull(i32* %13, i64 %14)
store i64 %15, i64* %1
%16 = load i32*, i32** %3
%17 = call i32 @CPU_FREE(i32* %16)
br label %18
18: ; preds = %9, %12, %2
%19 = phi i32 [ -1, %2 ], [ 0, %12 ], [ %10, %9 ]
ret i32 %19
}