#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);
int getNumaCount();
struct bitmask *numa_allocate_cpumask();
int /*<<< orphan*/ numa_bitmask_free(struct bitmask *);
unsigned int numa_bitmask_weight(struct bitmask *);
int /*<<< orphan*/ numa_node_to_cpus(int, struct bitmask *);
int cpuCountPerNuma(int numa) {
  assert(getNumaCount() > 0);
  assert(numa >= 0 && numa < getNumaCount());
  struct bitmask *bm = numa_allocate_cpumask();
  numa_node_to_cpus(numa, bm);
  unsigned int cpu_count = numa_bitmask_weight(bm);
  numa_bitmask_free(bm);
  return cpu_count;
}


x86 assembly (clang, -O0):
<cpuCountPerNuma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%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,-0x15(%rbp)
jl     11ab <cpuCountPerNuma+0x4b>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1050 <getNumaCount@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
setl   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    $0x0,%al
call   1080 <numa_allocate_cpumask@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <numa_node_to_cpus@plt>
mov    -0x10(%rbp),%rdi
call   1030 <numa_bitmask_weight@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <numa_bitmask_free@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpuCountPerNuma>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <getNumaCount@plt>
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1060 <assert@plt>
test   %ebx,%ebx
js     118e <cpuCountPerNuma+0x2e>
xor    %eax,%eax
call   1050 <getNumaCount@plt>
xor    %ebp,%ebp
cmp    %ebx,%eax
setg   %bpl
mov    %ebp,%edi
call   1060 <assert@plt>
xor    %eax,%eax
call   1080 <numa_allocate_cpumask@plt>
mov    %rax,%rbp
mov    %ebx,%edi
mov    %rax,%rsi
call   1040 <numa_node_to_cpus@plt>
mov    %rbp,%rdi
call   1030 <numa_bitmask_weight@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1070 <numa_bitmask_free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.bitmask = type { i32 }
define i32 @cpuCountPerNuma(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.bitmask*
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i32 (...) @getNumaCount()
%6 = icmp sgt i32 %5, 0
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i32, i32* %2
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = load i32, i32* %2
%13 = call i32 (...) @getNumaCount()
%14 = icmp slt i32 %12, %13
br label %15
15: ; preds = %11, %1
%16 = phi i1 [ false, %1 ], [ %14, %11 ]
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = call %struct.bitmask* (...) @numa_allocate_cpumask()
store %struct.bitmask* %19, %struct.bitmask** %3
%20 = load i32, i32* %2
%21 = load %struct.bitmask*, %struct.bitmask** %3
%22 = call i32 @numa_node_to_cpus(i32 %20, %struct.bitmask* %21)
%23 = load %struct.bitmask*, %struct.bitmask** %3
%24 = call i32 @numa_bitmask_weight(%struct.bitmask* %23)
store i32 %24, i32* %4
%25 = load %struct.bitmask*, %struct.bitmask** %3
%26 = call i32 @numa_bitmask_free(%struct.bitmask* %25)
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
%struct.bitmask = type { i32 }
define i32 @cpuCountPerNuma(i32 %0) {
%2 = tail call i32 (...) @getNumaCount()
%3 = icmp sgt i32 %2, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = icmp sgt i32 %0, -1
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = tail call i32 (...) @getNumaCount()
%9 = icmp sgt i32 %8, %0
%10 = zext i1 %9 to i32
br label %11
11: ; preds = %7, %1
%12 = phi i32 [ 0, %1 ], [ %10, %7 ]
%13 = tail call i32 @assert(i32 %12)
%14 = tail call %struct.bitmask* (...) @numa_allocate_cpumask()
%15 = tail call i32 @numa_node_to_cpus(i32 %0, %struct.bitmask* %14)
%16 = tail call i32 @numa_bitmask_weight(%struct.bitmask* %14)
%17 = tail call i32 @numa_bitmask_free(%struct.bitmask* %14)
ret i32 %16
}