#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*/ uint64_t;

/* Variables and functions */
scalar_t__ scalar_hamming_weight(int /*<<< orphan*/ const);
int scalar_bitset64_weight(const uint64_t *input, size_t length) {
  int card = 0;
  for (size_t k = 0; k < length; k++) {
    card += scalar_hamming_weight(input[k]);
  }
  return card;
}


x86 assembly (clang, -O0):
<scalar_bitset64_weight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    116b <scalar_bitset64_weight+0x5b>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <scalar_hamming_weight@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112f <scalar_bitset64_weight+0x1f>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scalar_bitset64_weight>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     1146 <scalar_bitset64_weight+0x36>
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    (%r14,%rbx,4),%edi
call   1030 <scalar_hamming_weight@plt>
add    %eax,%ebp
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <scalar_bitset64_weight+0x20>
jmp    1148 <scalar_bitset64_weight+0x38>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @scalar_bitset64_weight(i32* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %6, %2
%5 = phi i32 [ 0, %2 ], [ %13, %6 ]
ret i32 %5
6: ; preds = %2, %6
%7 = phi i64 [ %14, %6 ], [ 0, %2 ]
%8 = phi i32 [ %13, %6 ], [ 0, %2 ]
%9 = getelementptr inbounds i32, i32* %0, i64 %7
%10 = load i32, i32* %9
%11 = tail call i64 @scalar_hamming_weight(i32 %10)
%12 = trunc i64 %11 to i32
%13 = add i32 %8, %12
%14 = add nuw i64 %7, 1
%15 = icmp eq i64 %14, %1
br i1 %15, label %4, label %6
}