#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 */
struct filter_mask {
  int dummy;
};

/* Variables and functions */
scalar_t__ test_mask_bit(struct filter_mask const *, unsigned int);
unsigned int count_mask_bits(const struct filter_mask *mask,
                             unsigned int fa_entry_count) {
  unsigned int count = 0;
  for (unsigned int bit = 0; bit < fa_entry_count; bit++)
    if (test_mask_bit(mask, bit))
      count++;
  return count;
}


x86 assembly (clang, -O0):
<count_mask_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    116b <count_mask_bits+0x5b>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <test_mask_bit@plt>
cmp    $0x0,%rax
je     1158 <count_mask_bits+0x48>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115d <count_mask_bits+0x4d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112d <count_mask_bits+0x1d>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_mask_bits>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
je     114b <count_mask_bits+0x3b>
mov    %esi,%r15d
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <test_mask_bit@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
add    $0x1,%ebx
cmp    %ebx,%r15d
jne    1130 <count_mask_bits+0x20>
jmp    114d <count_mask_bits+0x3d>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.filter_mask = type { i32 }
define i32 @count_mask_bits(%struct.filter_mask* %0, i32 %1) {
%3 = alloca %struct.filter_mask*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store %struct.filter_mask* %0, %struct.filter_mask** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %20, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %4
%10 = icmp ult i32 %8, %9
br i1 %10, label %11, label %23
11: ; preds = %7
%12 = load %struct.filter_mask*, %struct.filter_mask** %3
%13 = load i32, i32* %6
%14 = call i64 @test_mask_bit(%struct.filter_mask* %12, i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* %5
%18 = add i32 %17, 1
store i32 %18, i32* %5
br label %19
19: ; preds = %16, %11
br label %20
20: ; preds = %19
%21 = load i32, i32* %6
%22 = add i32 %21, 1
store i32 %22, i32* %6
br label %7
23: ; preds = %7
%24 = load i32, i32* %5
ret i32 %24
}

LLVM IR (-O2):
%struct.filter_mask = type { i32 }
define i32 @count_mask_bits(%struct.filter_mask* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %6, %2
%5 = phi i32 [ 0, %2 ], [ %12, %6 ]
ret i32 %5
6: ; preds = %2, %6
%7 = phi i32 [ %13, %6 ], [ 0, %2 ]
%8 = phi i32 [ %12, %6 ], [ 0, %2 ]
%9 = tail call i64 @test_mask_bit(%struct.filter_mask* %0, i32 %7)
%10 = icmp ne i64 %9, 0
%11 = zext i1 %10 to i32
%12 = add i32 %8, %11
%13 = add nuw i32 %7, 1
%14 = icmp eq i32 %13, %1
br i1 %14, label %4, label %6
}