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

/* Variables and functions */
int /*<<< orphan*/ free(unsigned char *);
int rl_getrange(struct rlite *, unsigned char const *, long, long, long,
                unsigned char **, long *);
scalar_t__ rl_redisPopcount(unsigned char *, long);
int rl_bitcount(struct rlite *db, const unsigned char *key, long keylen,
                long start, long stop, long *bitcount) {
  int retval;
  unsigned char *value;
  long valuelen;
  retval = rl_getrange(db, key, keylen, start, stop, &value, &valuelen);
  if (0 != retval)
    goto cleanup;
  ;
  *bitcount = (long)rl_redisPopcount(value, valuelen);
  free(value);
cleanup:
  return retval;
}


x86 assembly (clang, -O0):
<rl_bitcount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    -0x40(%rbp),%r9
lea    -0x48(%rbp),%rax
mov    %rax,(%rsp)
call   1040 <rl_getrange@plt>
mov    %eax,-0x34(%rbp)
xor    %eax,%eax
cmp    -0x34(%rbp),%eax
je     1188 <rl_bitcount+0x58>
jmp    11a8 <rl_bitcount+0x78>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1050 <rl_redisPopcount@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rl_bitcount>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %r9,%rbx
lea    0x10(%rsp),%rax
mov    %rax,(%rsp)
lea    0x8(%rsp),%r9
call   1040 <rl_getrange@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    116e <rl_bitcount+0x3e>
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
call   1050 <rl_redisPopcount@plt>
mov    %rax,(%rbx)
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.rlite = type { i32 }
define i32 @rl_bitcount(%struct.rlite* %0, i8* %1, i64 %2, i64 %3, i64 %4, i64* %5) {
%7 = alloca %struct.rlite*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i64
store %struct.rlite* %0, %struct.rlite** %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i64 %3, i64* %10
store i64 %4, i64* %11
store i64* %5, i64** %12
%16 = load %struct.rlite*, %struct.rlite** %7
%17 = load i8*, i8** %8
%18 = load i64, i64* %9
%19 = load i64, i64* %10
%20 = load i64, i64* %11
%21 = call i32 @rl_getrange(%struct.rlite* %16, i8* %17, i64 %18, i64 %19, i64 %20, i8** %14, i64* %15)
store i32 %21, i32* %13
%22 = load i32, i32* %13
%23 = icmp ne i32 0, %22
br i1 %23, label %24, label %25
24: ; preds = %6
br label %32
25: ; preds = %6
%26 = load i8*, i8** %14
%27 = load i64, i64* %15
%28 = call i64 @rl_redisPopcount(i8* %26, i64 %27)
%29 = load i64*, i64** %12
store i64 %28, i64* %29
%30 = load i8*, i8** %14
%31 = call i32 @free(i8* %30)
br label %32
32: ; preds = %25, %24
%33 = load i32, i32* %13
ret i32 %33
}

LLVM IR (-O2):
%struct.rlite = type { i32 }
define i32 @rl_bitcount(%struct.rlite* %0, i8* %1, i64 %2, i64 %3, i64 %4, i64* nocapture writeonly %5) {
%7 = alloca i8*
%8 = alloca i64
%9 = bitcast i8** %7 to i8*
%10 = bitcast i64* %8 to i8*
%11 = call i32 @rl_getrange(%struct.rlite* %0, i8* %1, i64 %2, i64 %3, i64 %4, i8** %7, i64* %8)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %6
%14 = load i8*, i8** %7
%15 = load i64, i64* %8
%16 = call i64 @rl_redisPopcount(i8* %14, i64 %15)
store i64 %16, i64* %5
%17 = load i8*, i8** %7
%18 = call i32 @free(i8* %17)
br label %19
19: ; preds = %6, %13
ret i32 %11
}