#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 */
short int count_adcs(uint16_t word) {
  int i = 0;
  int counter = 0;
  for (i = 0; i < 16; i++) {
    counter += (word >> i) & 1;
  }
  return counter;
}


x86 assembly (clang, -O0):
<count_adcs>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x10,-0x8(%rbp)
jge    1145 <count_adcs+0x45>
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    111c <count_adcs+0x1c>
mov    -0xc(%rbp),%eax
cwtl
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_adcs>:
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 signext i16 @count_adcs(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %3
br label %5
5: ; preds = %15, %1
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 16
br i1 %7, label %8, label %18
8: ; preds = %5
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = ashr i32 %9, %10
%12 = and i32 %11, 1
%13 = load i32, i32* %4
%14 = add nsw i32 %13, %12
store i32 %14, i32* %4
br label %15
15: ; preds = %8
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %5
18: ; preds = %5
%19 = load i32, i32* %4
%20 = trunc i32 %19 to i16
ret i16 %20
}

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