#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 bit_map_t {
  int dummy;
};

/* Variables and functions */
scalar_t__ bit_map_get(struct bit_map_t *, unsigned int, int);
int bit_map_count_ones(struct bit_map_t *bit_map, unsigned int where,
                       unsigned int size) {
  unsigned int i;
  int count = 0;
  for (i = 0; i < size; i++)
    count += bit_map_get(bit_map, where + i, 1);
  return count;
}


x86 assembly (clang, -O0):
<bit_map_count_ones>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    116b <bit_map_count_ones+0x5b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    -0x14(%rbp),%esi
mov    $0x1,%edx
call   1030 <bit_map_get@plt>
mov    %rax,%rcx
movslq -0x18(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1130 <bit_map_count_ones+0x20>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bit_map_count_ones>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
je     114c <bit_map_count_ones+0x3c>
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
call   1030 <bit_map_get@plt>
add    %eax,%ebx
add    $0x1,%ebp
add    $0xffffffff,%r14d
jne    1130 <bit_map_count_ones+0x20>
jmp    114e <bit_map_count_ones+0x3e>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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