#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 uint16_t;

/* Variables and functions */
int cnt_one_bit_16(uint16_t data) {
  int i, ones;
  ones = 0;
  for (i = 0; i < 16; i++)
    if ((data << i) & 0x8000)
      ones++;
  return ones;
}


x86 assembly (clang, -O0):
<cnt_one_bit_16>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x10,-0x8(%rbp)
jge    1151 <cnt_one_bit_16+0x51>
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
shl    %cl,%eax
and    $0x8000,%eax
cmp    $0x0,%eax
je     113e <cnt_one_bit_16+0x3e>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1143 <cnt_one_bit_16+0x43>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1115 <cnt_one_bit_16+0x15>
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<cnt_one_bit_16>:
mov    %edi,%eax
shr    $0xf,%eax
and    $0x1,%eax
mov    %edi,%ecx
shr    $0xe,%ecx
and    $0x1,%ecx
add    %eax,%ecx
mov    %edi,%eax
shr    $0xd,%eax
and    $0x1,%eax
add    %ecx,%eax
mov    %edi,%ecx
shr    $0xc,%ecx
and    $0x1,%ecx
add    %eax,%ecx
mov    %edi,%eax
shr    $0xb,%eax
and    $0x1,%eax
add    %ecx,%eax
mov    %edi,%ecx
shr    $0xa,%ecx
and    $0x1,%ecx
add    %eax,%ecx
mov    %edi,%eax
shr    $0x9,%eax
and    $0x1,%eax
add    %ecx,%eax
mov    %edi,%ecx
shr    $0x8,%ecx
and    $0x1,%ecx
add    %eax,%ecx
mov    %edi,%eax
shr    $0x7,%eax
and    $0x1,%eax
add    %ecx,%eax
mov    %edi,%ecx
shr    $0x6,%ecx
and    $0x1,%ecx
add    %eax,%ecx
mov    %edi,%eax
shr    $0x5,%eax
and    $0x1,%eax
add    %ecx,%eax
mov    %edi,%ecx
shr    $0x4,%ecx
and    $0x1,%ecx
add    %eax,%ecx
mov    %edi,%eax
shr    $0x3,%eax
and    $0x1,%eax
add    %ecx,%eax
mov    %edi,%ecx
shr    $0x2,%ecx
and    $0x1,%ecx
add    %eax,%ecx
mov    %edi,%eax
shr    %eax
and    $0x1,%eax
add    %ecx,%eax
and    $0x1,%edi
add    %edi,%eax
ret

LLVM IR (-O0):
define i32 @cnt_one_bit_16(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
store i32 0, i32* %3
br label %5
5: ; preds = %18, %1
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 16
br i1 %7, label %8, label %21
8: ; preds = %5
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = shl i32 %9, %10
%12 = and i32 %11, 32768
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
br label %17
17: ; preds = %14, %8
br label %18
18: ; preds = %17
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %5
21: ; preds = %5
%22 = load i32, i32* %4
ret i32 %22
}

LLVM IR (-O2):
define i32 @cnt_one_bit_16(i32 %0) {
%2 = lshr i32 %0, 15
%3 = and i32 %2, 1
%4 = lshr i32 %0, 14
%5 = and i32 %4, 1
%6 = add nuw nsw i32 %3, %5
%7 = lshr i32 %0, 13
%8 = and i32 %7, 1
%9 = add nuw nsw i32 %6, %8
%10 = lshr i32 %0, 12
%11 = and i32 %10, 1
%12 = add nuw nsw i32 %9, %11
%13 = lshr i32 %0, 11
%14 = and i32 %13, 1
%15 = add nuw nsw i32 %12, %14
%16 = lshr i32 %0, 10
%17 = and i32 %16, 1
%18 = add nuw nsw i32 %15, %17
%19 = lshr i32 %0, 9
%20 = and i32 %19, 1
%21 = add nuw nsw i32 %18, %20
%22 = lshr i32 %0, 8
%23 = and i32 %22, 1
%24 = add nuw nsw i32 %21, %23
%25 = lshr i32 %0, 7
%26 = and i32 %25, 1
%27 = add nuw nsw i32 %24, %26
%28 = lshr i32 %0, 6
%29 = and i32 %28, 1
%30 = add nuw nsw i32 %27, %29
%31 = lshr i32 %0, 5
%32 = and i32 %31, 1
%33 = add nuw nsw i32 %30, %32
%34 = lshr i32 %0, 4
%35 = and i32 %34, 1
%36 = add nuw nsw i32 %33, %35
%37 = lshr i32 %0, 3
%38 = and i32 %37, 1
%39 = add nuw nsw i32 %36, %38
%40 = lshr i32 %0, 2
%41 = and i32 %40, 1
%42 = add nuw nsw i32 %39, %41
%43 = lshr i32 %0, 1
%44 = and i32 %43, 1
%45 = add nuw nsw i32 %42, %44
%46 = and i32 %0, 1
%47 = add nuw nsw i32 %45, %46
ret i32 %47
}