#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*/ assert(int);
scalar_t__ cpuCountPerNuma(int);
int getNumHardwareThreads();
int getNumaCount();
struct bitmask *numa_allocate_cpumask();
int /*<<< orphan*/ numa_bitmask_free(struct bitmask *);
scalar_t__ numa_bitmask_isbitset(struct bitmask *, int);
int /*<<< orphan*/ numa_node_to_cpus(int, struct bitmask *);
void getThreadIDs(int numa, int *numa_cpu_list) {
  assert(getNumaCount() > 0);
  assert(numa >= 0 && numa < getNumaCount());
  assert(numa_cpu_list != NULL);
  struct bitmask *bm = numa_allocate_cpumask();
  numa_node_to_cpus(numa, bm);
  size_t cur_list_idx = 0;
  for (int tid = 0; tid < getNumHardwareThreads(); ++tid) {
    if (numa_bitmask_isbitset(bm, tid)) {
      assert(cur_list_idx < (size_t)cpuCountPerNuma(numa));
      numa_cpu_list[cur_list_idx++] = tid;
    }
  }
  numa_bitmask_free(bm);
}


x86 assembly (clang, -O0):
<getThreadIDs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <getNumaCount@plt>
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0x25(%rbp)
jl     11cf <getThreadIDs+0x4f>
mov    -0x4(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1050 <getNumaCount@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
setl   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    $0x0,%al
call   10a0 <numa_allocate_cpumask@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <numa_node_to_cpus@plt>
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1080 <getNumHardwareThreads@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
jge    1297 <getThreadIDs+0x117>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1040 <numa_bitmask_isbitset@plt>
cmp    $0x0,%rax
je     1284 <getThreadIDs+0x104>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x4(%rbp),%edi
call   1070 <cpuCountPerNuma@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x24(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x20(%rbp)
mov    %edx,(%rax,%rcx,4)
jmp    1289 <getThreadIDs+0x109>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1214 <getThreadIDs+0x94>
mov    -0x18(%rbp),%rdi
call   1090 <numa_bitmask_free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getThreadIDs>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%r15d
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getNumaCount@plt>
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1060 <assert@plt>
test   %r15d,%r15d
js     11b8 <getThreadIDs+0x38>
xor    %eax,%eax
call   1050 <getNumaCount@plt>
xor    %ebx,%ebx
cmp    %r15d,%eax
setg   %bl
mov    %ebx,%edi
call   1060 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1060 <assert@plt>
xor    %eax,%eax
call   10a0 <numa_allocate_cpumask@plt>
mov    %rax,%r12
mov    %r15d,%edi
mov    %rax,%rsi
call   1030 <numa_node_to_cpus@plt>
xor    %eax,%eax
call   1080 <getNumHardwareThreads@plt>
test   %eax,%eax
jle    123d <getThreadIDs+0xbd>
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    120e <getThreadIDs+0x8e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebp
xor    %eax,%eax
call   1080 <getNumHardwareThreads@plt>
cmp    %eax,%ebp
jge    123d <getThreadIDs+0xbd>
mov    %r12,%rdi
mov    %ebp,%esi
call   1040 <numa_bitmask_isbitset@plt>
test   %rax,%rax
je     1200 <getThreadIDs+0x80>
mov    %r15d,%edi
call   1070 <cpuCountPerNuma@plt>
xor    %edi,%edi
cmp    %rax,%rbx
setb   %dil
call   1060 <assert@plt>
mov    %ebp,(%r14,%rbx,4)
add    $0x1,%rbx
jmp    1200 <getThreadIDs+0x80>
mov    %r12,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <numa_bitmask_free@plt>

LLVM IR (-O0):
%struct.bitmask = type { i32 }
define void @getThreadIDs(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca %struct.bitmask*
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
%8 = call i32 (...) @getNumaCount()
%9 = icmp sgt i32 %8, 0
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i32, i32* %3
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* %3
%16 = call i32 (...) @getNumaCount()
%17 = icmp slt i32 %15, %16
br label %18
18: ; preds = %14, %2
%19 = phi i1 [ false, %2 ], [ %17, %14 ]
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i32*, i32** %4
%23 = icmp ne i32* %22, null
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = call %struct.bitmask* (...) @numa_allocate_cpumask()
store %struct.bitmask* %26, %struct.bitmask** %5
%27 = load i32, i32* %3
%28 = load %struct.bitmask*, %struct.bitmask** %5
%29 = call i32 @numa_node_to_cpus(i32 %27, %struct.bitmask* %28)
store i64 0, i64* %6
store i32 0, i32* %7
br label %30
30: ; preds = %52, %18
%31 = load i32, i32* %7
%32 = call i32 (...) @getNumHardwareThreads()
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %55
34: ; preds = %30
%35 = load %struct.bitmask*, %struct.bitmask** %5
%36 = load i32, i32* %7
%37 = call i64 @numa_bitmask_isbitset(%struct.bitmask* %35, i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %51
39: ; preds = %34
%40 = load i64, i64* %6
%41 = load i32, i32* %3
%42 = call i64 @cpuCountPerNuma(i32 %41)
%43 = icmp ult i64 %40, %42
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = load i32, i32* %7
%47 = load i32*, i32** %4
%48 = load i64, i64* %6
%49 = add i64 %48, 1
store i64 %49, i64* %6
%50 = getelementptr inbounds i32, i32* %47, i64 %48
store i32 %46, i32* %50
br label %51
51: ; preds = %39, %34
br label %52
52: ; preds = %51
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 1
store i32 %54, i32* %7
br label %30
55: ; preds = %30
%56 = load %struct.bitmask*, %struct.bitmask** %5
%57 = call i32 @numa_bitmask_free(%struct.bitmask* %56)
ret void
}

LLVM IR (-O2):
%struct.bitmask = type { i32 }
define void @getThreadIDs(i32 %0, i32* writeonly %1) {
%3 = tail call i32 (...) @getNumaCount()
%4 = icmp sgt i32 %3, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp sgt i32 %0, -1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = tail call i32 (...) @getNumaCount()
%10 = icmp sgt i32 %9, %0
%11 = zext i1 %10 to i32
br label %12
12: ; preds = %8, %2
%13 = phi i32 [ 0, %2 ], [ %11, %8 ]
%14 = tail call i32 @assert(i32 %13)
%15 = icmp ne i32* %1, null
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = tail call %struct.bitmask* (...) @numa_allocate_cpumask()
%19 = tail call i32 @numa_node_to_cpus(i32 %0, %struct.bitmask* %18)
%20 = tail call i32 (...) @getNumHardwareThreads()
%21 = icmp sgt i32 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %36, %12
%23 = tail call i32 @numa_bitmask_free(%struct.bitmask* %18)
ret void
24: ; preds = %12, %36
%25 = phi i32 [ %38, %36 ], [ 0, %12 ]
%26 = phi i64 [ %37, %36 ], [ 0, %12 ]
%27 = tail call i64 @numa_bitmask_isbitset(%struct.bitmask* %18, i32 %25)
%28 = icmp eq i64 %27, 0
br i1 %28, label %36, label %29
29: ; preds = %24
%30 = tail call i64 @cpuCountPerNuma(i32 %0)
%31 = icmp ult i64 %26, %30
%32 = zext i1 %31 to i32
%33 = tail call i32 @assert(i32 %32)
%34 = add i64 %26, 1
%35 = getelementptr inbounds i32, i32* %1, i64 %26
store i32 %25, i32* %35
br label %36
36: ; preds = %24, %29
%37 = phi i64 [ %34, %29 ], [ %26, %24 ]
%38 = add nuw nsw i32 %25, 1
%39 = tail call i32 (...) @getNumHardwareThreads()
%40 = icmp slt i32 %38, %39
br i1 %40, label %24, label %22
}