#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 ocfs2_find_next_bit_set(void *, int, int);
int ocfs2_get_bits_set(void *addr, int size, int offset) {
  int set_bits = 0, found = 0;
  while (1) {
    found = ocfs2_find_next_bit_set(addr, size, offset);
    if (found < size) {
      set_bits++;
      offset = found + 1;
    } else
      break;
  }
  return set_bits;
}


x86 assembly (clang, -O0):
<ocfs2_get_bits_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <ocfs2_find_next_bit_set@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1165 <ocfs2_get_bits_set+0x55>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116a <ocfs2_get_bits_set+0x5a>
jmp    116f <ocfs2_get_bits_set+0x5f>
jmp    1130 <ocfs2_get_bits_set+0x20>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ocfs2_get_bits_set>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
call   1030 <ocfs2_find_next_bit_set@plt>
xor    %ebp,%ebp
cmp    %ebx,%eax
jge    1146 <ocfs2_get_bits_set+0x36>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
add    $0x1,%eax
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1030 <ocfs2_find_next_bit_set@plt>
cmp    %ebx,%eax
jl     1130 <ocfs2_get_bits_set+0x20>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @ocfs2_get_bits_set(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 @ocfs2_find_next_bit_set(i8* %0, i32 %1, i32 %2)
%5 = icmp slt i32 %4, %1
br i1 %5, label %6, label %13
6: ; preds = %3, %6
%7 = phi i32 [ %11, %6 ], [ %4, %3 ]
%8 = phi i32 [ %9, %6 ], [ 0, %3 ]
%9 = add nuw nsw i32 %8, 1
%10 = add nsw i32 %7, 1
%11 = tail call i32 @ocfs2_find_next_bit_set(i8* %0, i32 %1, i32 %10)
%12 = icmp slt i32 %11, %1
br i1 %12, label %6, label %13
13: ; preds = %6, %3
%14 = phi i32 [ 0, %3 ], [ %9, %6 ]
ret i32 %14
}