#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 {
  unsigned int size;
};

/* Variables and functions */
scalar_t__ rt_numa_bitmask_isbitset(struct bitmask const *, unsigned int);
unsigned int rt_numa_bitmask_count(const struct bitmask *mask) {
  unsigned int num_bits = 0, i;
  for (i = 0; i < mask->size; i++) {
    if (rt_numa_bitmask_isbitset(mask, i))
      num_bits++;
  }
  return num_bits;
}


x86 assembly (clang, -O0):
<rt_numa_bitmask_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jae    116b <rt_numa_bitmask_count+0x5b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1030 <rt_numa_bitmask_isbitset@plt>
cmp    $0x0,%rax
je     1158 <rt_numa_bitmask_count+0x48>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115d <rt_numa_bitmask_count+0x4d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112a <rt_numa_bitmask_count+0x1a>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rt_numa_bitmask_count>:
push   %rbp
push   %r14
push   %rbx
cmpl   $0x0,(%rdi)
je     113b <rt_numa_bitmask_count+0x2b>
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %ebp,%ebp
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <rt_numa_bitmask_isbitset@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
add    $0x1,%ebx
cmp    (%r14),%ebx
jb     1120 <rt_numa_bitmask_count+0x10>
jmp    113d <rt_numa_bitmask_count+0x2d>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.bitmask = type { i32 }
define i32 @rt_numa_bitmask_count(%struct.bitmask* %0) {
%2 = alloca %struct.bitmask*
%3 = alloca i32
%4 = alloca i32
store %struct.bitmask* %0, %struct.bitmask** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %20, %1
%6 = load i32, i32* %4
%7 = load %struct.bitmask*, %struct.bitmask** %2
%8 = getelementptr inbounds %struct.bitmask, %struct.bitmask* %7, i32 0, i32 0
%9 = load i32, i32* %8
%10 = icmp ult i32 %6, %9
br i1 %10, label %11, label %23
11: ; preds = %5
%12 = load %struct.bitmask*, %struct.bitmask** %2
%13 = load i32, i32* %4
%14 = call i64 @rt_numa_bitmask_isbitset(%struct.bitmask* %12, i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* %3
%18 = add i32 %17, 1
store i32 %18, i32* %3
br label %19
19: ; preds = %16, %11
br label %20
20: ; preds = %19
%21 = load i32, i32* %4
%22 = add i32 %21, 1
store i32 %22, i32* %4
br label %5
23: ; preds = %5
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
%struct.bitmask = type { i32 }
define i32 @rt_numa_bitmask_count(%struct.bitmask* %0) {
%2 = getelementptr inbounds %struct.bitmask, %struct.bitmask* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = icmp eq i32 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %1, %5
%6 = phi i32 [ %12, %5 ], [ 0, %1 ]
%7 = phi i32 [ %11, %5 ], [ 0, %1 ]
%8 = tail call i64 @rt_numa_bitmask_isbitset(%struct.bitmask* %0, i32 %6)
%9 = icmp ne i64 %8, 0
%10 = zext i1 %9 to i32
%11 = add i32 %7, %10
%12 = add nuw i32 %6, 1
%13 = load i32, i32* %2
%14 = icmp ult i32 %12, %13
br i1 %14, label %5, label %15
15: ; preds = %5, %1
%16 = phi i32 [ 0, %1 ], [ %11, %5 ]
ret i32 %16
}