#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 */
struct bitmask {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ add_core_range(int, int, int **, int *, int *);
int /*<<< orphan*/ check_range(int, int, scalar_t__);
int get_nprocs();
struct bitmask *numa_allocate_cpumask();
scalar_t__ numa_bitmask_isbitset(struct bitmask *, int);
int /*<<< orphan*/ numa_free_cpumask(struct bitmask *);
scalar_t__ numa_max_node();
int /*<<< orphan*/ numa_node_to_cpus(int, struct bitmask *);
void add_node_range(int node0, int node1, int **cores, int *nr_entries_in_cores,
                    int *cores_len) {
  int i;
  int nprocs = get_nprocs();
  check_range(node0, node1, numa_max_node() + 1);
  for (i = node0 + 1; i <= node1; i++) {
    struct bitmask *bm = numa_allocate_cpumask();
    numa_node_to_cpus(i, bm);
    int j = 0;
    for (j = 0; j < nprocs; j++) {
      if (numa_bitmask_isbitset(bm, j)) {
        add_core_range(j - 1, j, cores, nr_entries_in_cores, cores_len);
      }
    }
    numa_free_cpumask(bm);
  }
}


x86 assembly (clang, -O0):
<add_node_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    $0x0,%al
call   10a0 <get_nprocs@plt>
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    $0x0,%al
call   1090 <numa_max_node@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%esi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <check_range@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1269 <add_node_range+0xe9>
mov    $0x0,%al
call   1080 <numa_allocate_cpumask@plt>
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1050 <numa_node_to_cpus@plt>
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1252 <add_node_range+0xd2>
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1060 <numa_bitmask_isbitset@plt>
cmp    $0x0,%rax
je     123f <add_node_range+0xbf>
mov    -0x34(%rbp),%edi
sub    $0x1,%edi
mov    -0x34(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1040 <add_core_range@plt>
jmp    1244 <add_node_range+0xc4>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1203 <add_node_range+0x83>
mov    -0x30(%rbp),%rdi
call   1070 <numa_free_cpumask@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d2 <add_node_range+0x52>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_node_range>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,0x10(%rsp)
mov    %rcx,%r15
mov    %rdx,%r14
mov    %esi,%r12d
mov    %edi,%ebx
xor    %eax,%eax
call   10a0 <get_nprocs@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1090 <numa_max_node@plt>
lea    0x1(%rax),%rdx
mov    %ebx,%edi
mov    %r12d,%esi
call   1030 <check_range@plt>
mov    %r12d,0x8(%rsp)
cmp    %r12d,%ebx
jl     11f2 <add_node_range+0x72>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
call   1070 <numa_free_cpumask@plt>
mov    0xc(%rsp),%ebx
cmp    0x8(%rsp),%ebx
je     11c6 <add_node_range+0x46>
add    $0x1,%ebx
xor    %eax,%eax
call   1080 <numa_allocate_cpumask@plt>
mov    %rax,%r12
mov    %ebx,0xc(%rsp)
mov    %ebx,%edi
mov    %rax,%rsi
call   1050 <numa_node_to_cpus@plt>
test   %ebp,%ebp
mov    0x10(%rsp),%rbx
jle    11e0 <add_node_range+0x60>
xor    %r13d,%r13d
jmp    1229 <add_node_range+0xa9>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13d
cmp    %r13d,%ebp
je     11e0 <add_node_range+0x60>
mov    %r12,%rdi
mov    %r13d,%esi
call   1060 <numa_bitmask_isbitset@plt>
test   %rax,%rax
je     1220 <add_node_range+0xa0>
lea    -0x1(%r13),%edi
mov    %r13d,%esi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %rbx,%r8
call   1040 <add_core_range@plt>
jmp    1220 <add_node_range+0xa0>

LLVM IR (-O0):
%struct.bitmask = type { i32 }
define void @add_node_range(i32 %0, i32 %1, i32** %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32**
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.bitmask*
%14 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32** %2, i32*** %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%15 = call i32 (...) @get_nprocs()
store i32 %15, i32* %12
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = call i64 (...) @numa_max_node()
%19 = add nsw i64 %18, 1
%20 = call i32 @check_range(i32 %16, i32 %17, i64 %19)
%21 = load i32, i32* %6
%22 = add nsw i32 %21, 1
store i32 %22, i32* %11
br label %23
23: ; preds = %56, %5
%24 = load i32, i32* %11
%25 = load i32, i32* %7
%26 = icmp sle i32 %24, %25
br i1 %26, label %27, label %59
27: ; preds = %23
%28 = call %struct.bitmask* (...) @numa_allocate_cpumask()
store %struct.bitmask* %28, %struct.bitmask** %13
%29 = load i32, i32* %11
%30 = load %struct.bitmask*, %struct.bitmask** %13
%31 = call i32 @numa_node_to_cpus(i32 %29, %struct.bitmask* %30)
store i32 0, i32* %14
store i32 0, i32* %14
br label %32
32: ; preds = %50, %27
%33 = load i32, i32* %14
%34 = load i32, i32* %12
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %53
36: ; preds = %32
%37 = load %struct.bitmask*, %struct.bitmask** %13
%38 = load i32, i32* %14
%39 = call i64 @numa_bitmask_isbitset(%struct.bitmask* %37, i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %49
41: ; preds = %36
%42 = load i32, i32* %14
%43 = sub nsw i32 %42, 1
%44 = load i32, i32* %14
%45 = load i32**, i32*** %8
%46 = load i32*, i32** %9
%47 = load i32*, i32** %10
%48 = call i32 @add_core_range(i32 %43, i32 %44, i32** %45, i32* %46, i32* %47)
br label %49
49: ; preds = %41, %36
br label %50
50: ; preds = %49
%51 = load i32, i32* %14
%52 = add nsw i32 %51, 1
store i32 %52, i32* %14
br label %32
53: ; preds = %32
%54 = load %struct.bitmask*, %struct.bitmask** %13
%55 = call i32 @numa_free_cpumask(%struct.bitmask* %54)
br label %56
56: ; preds = %53
%57 = load i32, i32* %11
%58 = add nsw i32 %57, 1
store i32 %58, i32* %11
br label %23
59: ; preds = %23
ret void
}

LLVM IR (-O2):
%struct.bitmask = type { i32 }
define void @add_node_range(i32 %0, i32 %1, i32** %2, i32* %3, i32* %4) {
%6 = tail call i32 (...) @get_nprocs()
%7 = tail call i64 (...) @numa_max_node()
%8 = add nsw i64 %7, 1
%9 = tail call i32 @check_range(i32 %0, i32 %1, i64 %8)
%10 = icmp slt i32 %0, %1
br i1 %10, label %11, label %31
11: ; preds = %5
%12 = icmp sgt i32 %6, 0
br label %13
13: ; preds = %11, %28
%14 = phi i32 [ %0, %11 ], [ %15, %28 ]
%15 = add i32 %14, 1
%16 = tail call %struct.bitmask* (...) @numa_allocate_cpumask()
%17 = tail call i32 @numa_node_to_cpus(i32 %15, %struct.bitmask* %16)
br i1 %12, label %18, label %28
18: ; preds = %13, %25
%19 = phi i32 [ %26, %25 ], [ 0, %13 ]
%20 = tail call i64 @numa_bitmask_isbitset(%struct.bitmask* %16, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = add nsw i32 %19, -1
%24 = tail call i32 @add_core_range(i32 %23, i32 %19, i32** %2, i32* %3, i32* %4)
br label %25
25: ; preds = %18, %22
%26 = add nuw nsw i32 %19, 1
%27 = icmp eq i32 %26, %6
br i1 %27, label %28, label %18
28: ; preds = %25, %13
%29 = tail call i32 @numa_free_cpumask(%struct.bitmask* %16)
%30 = icmp eq i32 %15, %1
br i1 %30, label %31, label %13
31: ; preds = %28, %5
ret void
}