#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 */
unsigned int bit_next_biggest_number_same_num_ones(unsigned int);
unsigned int bit_next_smallest_number_same_num_ones(unsigned int);
int /*<<< orphan*/ print_integer_in_binary(int);
int bit_generate_arrangements(unsigned x, void (*fn)(unsigned x)) {
  int cnt = 0;
  unsigned orig_x = x;
  while (x) {
    cnt++;
    print_integer_in_binary((int)x);
    if (fn)
      fn(x);
    x = bit_next_smallest_number_same_num_ones(x);
  }
  x = bit_next_biggest_number_same_num_ones(orig_x);
  while (x) {
    cnt++;
    print_integer_in_binary((int)x);
    if (fn)
      fn(x);
    x = bit_next_biggest_number_same_num_ones(x);
  }
  return cnt;
}


x86 assembly (clang, -O0):
<bit_generate_arrangements>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     118b <bit_generate_arrangements+0x5b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <print_integer_in_binary@plt>
cmpq   $0x0,-0x10(%rbp)
je     117b <bit_generate_arrangements+0x4b>
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%edi
call   *%rax
mov    -0x4(%rbp),%edi
call   1030 <bit_next_smallest_number_same_num_ones@plt>
mov    %eax,-0x4(%rbp)
jmp    114c <bit_generate_arrangements+0x1c>
mov    -0x18(%rbp),%edi
call   1040 <bit_next_biggest_number_same_num_ones@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11d5 <bit_generate_arrangements+0xa5>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <print_integer_in_binary@plt>
cmpq   $0x0,-0x10(%rbp)
je     11c5 <bit_generate_arrangements+0x95>
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%edi
call   *%rax
mov    -0x4(%rbp),%edi
call   1040 <bit_next_biggest_number_same_num_ones@plt>
mov    %eax,-0x4(%rbp)
jmp    1196 <bit_generate_arrangements+0x66>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bit_generate_arrangements>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r14d
xor    %ebp,%ebp
test   %edi,%edi
je     1173 <bit_generate_arrangements+0x43>
mov    %r14d,%ebx
jmp    1160 <bit_generate_arrangements+0x30>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1030 <bit_next_smallest_number_same_num_ones@plt>
mov    %eax,%ebx
add    $0x1,%ebp
test   %eax,%eax
je     1173 <bit_generate_arrangements+0x43>
mov    %ebx,%edi
call   1050 <print_integer_in_binary@plt>
test   %r15,%r15
je     1150 <bit_generate_arrangements+0x20>
mov    %ebx,%edi
call   *%r15
jmp    1150 <bit_generate_arrangements+0x20>
mov    %r14d,%edi
call   1040 <bit_next_biggest_number_same_num_ones@plt>
test   %eax,%eax
je     11b3 <bit_generate_arrangements+0x83>
mov    %eax,%ebx
jmp    11a0 <bit_generate_arrangements+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
call   1040 <bit_next_biggest_number_same_num_ones@plt>
mov    %eax,%ebx
add    $0x1,%ebp
test   %eax,%eax
je     11b3 <bit_generate_arrangements+0x83>
mov    %ebx,%edi
call   1050 <print_integer_in_binary@plt>
test   %r15,%r15
je     1190 <bit_generate_arrangements+0x60>
mov    %ebx,%edi
call   *%r15
jmp    1190 <bit_generate_arrangements+0x60>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bit_generate_arrangements(i32 %0, void (i32)* %1) {
%3 = alloca i32
%4 = alloca void (i32)*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store void (i32)* %1, void (i32)** %4
store i32 0, i32* %5
%7 = load i32, i32* %3
store i32 %7, i32* %6
br label %8
8: ; preds = %21, %2
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %8
%12 = load i32, i32* %5
%13 = add nsw i32 %12, 1
store i32 %13, i32* %5
%14 = load i32, i32* %3
%15 = call i32 @print_integer_in_binary(i32 %14)
%16 = load void (i32)*, void (i32)** %4
%17 = icmp ne void (i32)* %16, null
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load void (i32)*, void (i32)** %4
%20 = load i32, i32* %3
br label %21
21: ; preds = %18, %11
%22 = load i32, i32* %3
%23 = call i32 @bit_next_smallest_number_same_num_ones(i32 %22)
store i32 %23, i32* %3
br label %8
24: ; preds = %8
%25 = load i32, i32* %6
%26 = call i32 @bit_next_biggest_number_same_num_ones(i32 %25)
store i32 %26, i32* %3
br label %27
27: ; preds = %40, %24
%28 = load i32, i32* %3
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %43
30: ; preds = %27
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
%33 = load i32, i32* %3
%34 = call i32 @print_integer_in_binary(i32 %33)
%35 = load void (i32)*, void (i32)** %4
%36 = icmp ne void (i32)* %35, null
br i1 %36, label %37, label %40
37: ; preds = %30
%38 = load void (i32)*, void (i32)** %4
%39 = load i32, i32* %3
br label %40
40: ; preds = %37, %30
%41 = load i32, i32* %3
%42 = call i32 @bit_next_biggest_number_same_num_ones(i32 %41)
store i32 %42, i32* %3
br label %27
43: ; preds = %27
%44 = load i32, i32* %5
ret i32 %44
}

LLVM IR (-O2):
define i32 @bit_generate_arrangements(i32 %0, void (i32)* %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = icmp eq void (i32)* %1, null
br label %6
6: ; preds = %4, %12
%7 = phi i32 [ %0, %4 ], [ %13, %12 ]
%8 = phi i32 [ 0, %4 ], [ %9, %12 ]
%9 = add nuw nsw i32 %8, 1
%10 = tail call i32 @print_integer_in_binary(i32 %7)
br i1 %5, label %12, label %11
11: ; preds = %6
tail call void %1(i32 %7)
br label %12
12: ; preds = %11, %6
%13 = tail call i32 @bit_next_smallest_number_same_num_ones(i32 %7)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %6
15: ; preds = %12, %2
%16 = phi i32 [ 0, %2 ], [ %9, %12 ]
%17 = tail call i32 @bit_next_biggest_number_same_num_ones(i32 %0)
%18 = icmp eq i32 %17, 0
br i1 %18, label %30, label %19
19: ; preds = %15
%20 = icmp eq void (i32)* %1, null
br label %21
21: ; preds = %19, %27
%22 = phi i32 [ %17, %19 ], [ %28, %27 ]
%23 = phi i32 [ %16, %19 ], [ %24, %27 ]
%24 = add nuw nsw i32 %23, 1
%25 = tail call i32 @print_integer_in_binary(i32 %22)
br i1 %20, label %27, label %26
26: ; preds = %21
tail call void %1(i32 %22)
br label %27
27: ; preds = %26, %21
%28 = tail call i32 @bit_next_biggest_number_same_num_ones(i32 %22)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %21
30: ; preds = %27, %15
%31 = phi i32 [ %16, %15 ], [ %24, %27 ]
ret i32 %31
}