#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 */
int Kit_TruthWordNum(int);
scalar_t__ Kit_WordCountOnes(unsigned int);
int Kit_TruthCountOnes(unsigned *pIn, int nVars) {
  int w, Counter = 0;
  for (w = Kit_TruthWordNum(nVars) - 1; w >= 0; w--)
    Counter += Kit_WordCountOnes(pIn[w]);
  return Counter;
}


x86 assembly (clang, -O0):
<Kit_TruthCountOnes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <Kit_TruthWordNum@plt>
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     1179 <Kit_TruthCountOnes+0x59>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <Kit_WordCountOnes@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1144 <Kit_TruthCountOnes+0x24>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Kit_TruthCountOnes>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    %esi,%edi
call   1040 <Kit_TruthWordNum@plt>
test   %eax,%eax
jle    115a <Kit_TruthCountOnes+0x3a>
mov    %eax,%ebx
add    $0x1,%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
lea    -0x2(%rbx),%eax
mov    (%r14,%rax,4),%edi
call   1030 <Kit_WordCountOnes@plt>
add    %eax,%ebp
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1140 <Kit_TruthCountOnes+0x20>
jmp    115c <Kit_TruthCountOnes+0x3c>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @Kit_TruthCountOnes(i32* nocapture %0, i32 %1) {
%3 = tail call i32 @Kit_TruthWordNum(i32 %1)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %18
5: ; preds = %2
%6 = zext i32 %3 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ %6, %5 ], [ %10, %7 ]
%9 = phi i32 [ 0, %5 ], [ %16, %7 ]
%10 = add nsw i64 %8, -1
%11 = and i64 %10, 4294967295
%12 = getelementptr inbounds i32, i32* %0, i64 %11
%13 = load i32, i32* %12
%14 = tail call i64 @Kit_WordCountOnes(i32 %13)
%15 = trunc i64 %14 to i32
%16 = add i32 %9, %15
%17 = icmp ugt i64 %8, 1
br i1 %17, label %7, label %18
18: ; preds = %7, %2
%19 = phi i32 [ 0, %2 ], [ %16, %7 ]
ret i32 %19
}