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

/* Variables and functions */
scalar_t__ of_hweight32_table(unsigned int);
scalar_t__ of_popcount_3(unsigned long long);
unsigned int of_hweight_array(unsigned int *array, int size) {
  unsigned int weight = 0;
  unsigned int i;
  unsigned int array_size_32, array_size_32_rem;
  unsigned int *v32;
  array_size_32 = size >> 5;
  array_size_32_rem = size % 32;
  if (array_size_32_rem > 0) {
    array_size_32++;
  }
  unsigned int array_size64;
  unsigned int array_size64rem;
  array_size64 = array_size_32 >> 1;
  array_size64rem = array_size_32 % 2;
  unsigned long long *v64 = (unsigned long long *)array;
  for (i = array_size64; i > 0; i--) {
    weight += of_popcount_3(*v64);
    v64++;
  }
  if (array_size64rem > 0) {
    v32 = (unsigned int *)v64;
    weight += of_hweight32_table(*v32);
    v32++;
  }
  return weight;
}


x86 assembly (clang, -O0):
<of_hweight_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x5,%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jbe    1160 <of_hweight_array+0x40>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%eax
and    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jbe    11bc <of_hweight_array+0x9c>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
call   1030 <of_popcount_3@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0x38(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1180 <of_hweight_array+0x60>
cmpl   $0x0,-0x30(%rbp)
jbe    11f1 <of_hweight_array+0xd1>
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
call   1040 <of_hweight32_table@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<of_hweight_array>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %esi,%r14d
sar    $0x5,%r14d
and    $0x1f,%esi
cmp    $0x1,%esi
sbb    $0xffffffff,%r14d
cmp    $0x2,%r14d
jae    1146 <of_hweight_array+0x26>
xor    %r15d,%r15d
jmp    1164 <of_hweight_array+0x44>
mov    %r14d,%ebp
shr    %ebp
xor    %r15d,%r15d
xchg   %ax,%ax
mov    (%rbx),%rdi
call   1030 <of_popcount_3@plt>
add    %eax,%r15d
add    $0x8,%rbx
add    $0xffffffff,%ebp
jne    1150 <of_hweight_array+0x30>
test   $0x1,%r14b
je     1174 <of_hweight_array+0x54>
mov    (%rbx),%edi
call   1040 <of_hweight32_table@plt>
add    %eax,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @of_hweight_array(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64*
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%13 = load i32, i32* %4
%14 = ashr i32 %13, 5
store i32 %14, i32* %7
%15 = load i32, i32* %4
%16 = srem i32 %15, 32
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp ugt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = load i32, i32* %7
%21 = add i32 %20, 1
store i32 %21, i32* %7
br label %22
22: ; preds = %19, %2
%23 = load i32, i32* %7
%24 = lshr i32 %23, 1
store i32 %24, i32* %10
%25 = load i32, i32* %7
%26 = urem i32 %25, 2
store i32 %26, i32* %11
%27 = load i32*, i32** %3
%28 = bitcast i32* %27 to i64*
store i64* %28, i64** %12
%29 = load i32, i32* %10
store i32 %29, i32* %6
br label %30
30: ; preds = %43, %22
%31 = load i32, i32* %6
%32 = icmp ugt i32 %31, 0
br i1 %32, label %33, label %46
33: ; preds = %30
%34 = load i64*, i64** %12
%35 = load i64, i64* %34
%36 = call i64 @of_popcount_3(i64 %35)
%37 = load i32, i32* %5
%38 = zext i32 %37 to i64
%39 = add nsw i64 %38, %36
%40 = trunc i64 %39 to i32
store i32 %40, i32* %5
%41 = load i64*, i64** %12
%42 = getelementptr inbounds i64, i64* %41, i32 1
store i64* %42, i64** %12
br label %43
43: ; preds = %33
%44 = load i32, i32* %6
%45 = add i32 %44, -1
store i32 %45, i32* %6
br label %30
46: ; preds = %30
%47 = load i32, i32* %11
%48 = icmp ugt i32 %47, 0
br i1 %48, label %49, label %61
49: ; preds = %46
%50 = load i64*, i64** %12
%51 = bitcast i64* %50 to i32*
store i32* %51, i32** %9
%52 = load i32*, i32** %9
%53 = load i32, i32* %52
%54 = call i64 @of_hweight32_table(i32 %53)
%55 = load i32, i32* %5
%56 = zext i32 %55 to i64
%57 = add nsw i64 %56, %54
%58 = trunc i64 %57 to i32
store i32 %58, i32* %5
%59 = load i32*, i32** %9
%60 = getelementptr inbounds i32, i32* %59, i32 1
store i32* %60, i32** %9
br label %61
61: ; preds = %49, %46
%62 = load i32, i32* %5
ret i32 %62
}

LLVM IR (-O2):
define i32 @of_hweight_array(i32* nocapture %0, i32 %1) {
%3 = ashr i32 %1, 5
%4 = and i32 %1, 31
%5 = icmp ne i32 %4, 0
%6 = zext i1 %5 to i32
%7 = add nsw i32 %3, %6
%8 = and i32 %7, 1
%9 = bitcast i32* %0 to i64*
%10 = icmp ult i32 %7, 2
br i1 %10, label %24, label %11
11: ; preds = %2
%12 = lshr i32 %7, 1
br label %13
13: ; preds = %11, %13
%14 = phi i64* [ %21, %13 ], [ %9, %11 ]
%15 = phi i32 [ %20, %13 ], [ 0, %11 ]
%16 = phi i32 [ %22, %13 ], [ %12, %11 ]
%17 = load i64, i64* %14
%18 = tail call i64 @of_popcount_3(i64 %17)
%19 = trunc i64 %18 to i32
%20 = add i32 %15, %19
%21 = getelementptr inbounds i64, i64* %14, i64 1
%22 = add i32 %16, -1
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %13
24: ; preds = %13, %2
%25 = phi i32 [ 0, %2 ], [ %20, %13 ]
%26 = phi i64* [ %9, %2 ], [ %21, %13 ]
%27 = icmp eq i32 %8, 0
br i1 %27, label %34, label %28
28: ; preds = %24
%29 = bitcast i64* %26 to i32*
%30 = load i32, i32* %29
%31 = tail call i64 @of_hweight32_table(i32 %30)
%32 = trunc i64 %31 to i32
%33 = add i32 %25, %32
br label %34
34: ; preds = %28, %24
%35 = phi i32 [ %33, %28 ], [ %25, %24 ]
ret i32 %35
}