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

/* Variables and functions */
struct bitmap_t *bitmap_alloc_set(size_t);
struct bitmap_t *bitmap_alloc_zero();
int /*<<< orphan*/ bitmap_set_bit(size_t, int, struct bitmap_t *);
struct bitmap_t *bitmap_alloc_nr_bits(size_t nr_bits) {
  size_t bit;
  struct bitmap_t *set;
  if (nr_bits == 0)
    return bitmap_alloc_zero();
  bit = nr_bits - 1;
  set = bitmap_alloc_set(bit);
  while (bit > 0) {
    bit--;
    bitmap_set_bit(bit, 1, set);
  }
  return set;
}


x86 assembly (clang, -O0):
<bitmap_alloc_nr_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1157 <bitmap_alloc_nr_bits+0x27>
mov    $0x0,%al
call   1030 <bitmap_alloc_zero@plt>
mov    %rax,-0x8(%rbp)
jmp    11a6 <bitmap_alloc_nr_bits+0x76>
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <bitmap_alloc_set@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    119e <bitmap_alloc_nr_bits+0x6e>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x1,%esi
call   1050 <bitmap_set_bit@plt>
jmp    1170 <bitmap_alloc_nr_bits+0x40>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitmap_alloc_nr_bits>:
test   %rdi,%rdi
je     1181 <bitmap_alloc_nr_bits+0x51>
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
add    $0xffffffffffffffff,%rdi
call   1040 <bitmap_alloc_set@plt>
mov    %rax,%r14
mov    %rbx,%rax
add    $0xffffffffffffffff,%rax
je     1176 <bitmap_alloc_nr_bits+0x46>
add    $0xfffffffffffffffe,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
call   1050 <bitmap_set_bit@plt>
add    $0xffffffffffffffff,%rbx
jb     1160 <bitmap_alloc_nr_bits+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
jmp    1030 <bitmap_alloc_zero@plt>

LLVM IR (-O0):
%struct.bitmap_t = type { i32 }
define %struct.bitmap_t* @bitmap_alloc_nr_bits(i64 %0) {
%2 = alloca %struct.bitmap_t*
%3 = alloca i64
%4 = alloca i64
%5 = alloca %struct.bitmap_t*
store i64 %0, i64* %3
%6 = load i64, i64* %3
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call %struct.bitmap_t* (...) @bitmap_alloc_zero()
store %struct.bitmap_t* %9, %struct.bitmap_t** %2
br label %26
10: ; preds = %1
%11 = load i64, i64* %3
%12 = sub i64 %11, 1
store i64 %12, i64* %4
%13 = load i64, i64* %4
%14 = call %struct.bitmap_t* @bitmap_alloc_set(i64 %13)
store %struct.bitmap_t* %14, %struct.bitmap_t** %5
br label %15
15: ; preds = %18, %10
%16 = load i64, i64* %4
%17 = icmp ugt i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load i64, i64* %4
%20 = add i64 %19, -1
store i64 %20, i64* %4
%21 = load i64, i64* %4
%22 = load %struct.bitmap_t*, %struct.bitmap_t** %5
%23 = call i32 @bitmap_set_bit(i64 %21, i32 1, %struct.bitmap_t* %22)
br label %15
24: ; preds = %15
%25 = load %struct.bitmap_t*, %struct.bitmap_t** %5
store %struct.bitmap_t* %25, %struct.bitmap_t** %2
br label %26
26: ; preds = %24, %8
%27 = load %struct.bitmap_t*, %struct.bitmap_t** %2
ret %struct.bitmap_t* %27
}

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