#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 count_zeros(uint16_t d) {
  int i, cnt = 0;
  for (i = 0; i < 16; i++) {
    if (0 == (d & (1 << i)))
      cnt++;
  }
  return cnt;
}


x86 assembly (clang, -O0):
<count_zeros>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x10,-0x8(%rbp)
jge    115a <count_zeros+0x5a>
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    -0x10(%rbp),%ecx
and    %eax,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    1147 <count_zeros+0x47>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114c <count_zeros+0x4c>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1115 <count_zeros+0x15>
mov    -0xc(%rbp),%eax
pop    %rbp
ret

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

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