#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 /*<<< orphan*/ print_integer_in_binary(int);
int bit_inplace_permutate(unsigned x, void (*fn)(unsigned x)) {
  int cnt = 0;
  unsigned n = 0;
  do {
    n = (n - x) & x;
    cnt++;
    print_integer_in_binary((int)n);
    if (fn)
      fn(n);
  } while (n);
  return cnt;
}


x86 assembly (clang, -O0):
<bit_inplace_permutate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x4(%rbp),%eax
and    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <print_integer_in_binary@plt>
cmpq   $0x0,-0x10(%rbp)
je     115e <bit_inplace_permutate+0x4e>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%edi
call   *%rax
jmp    1163 <bit_inplace_permutate+0x53>
cmpl   $0x0,-0x18(%rbp)
jne    112d <bit_inplace_permutate+0x1d>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bit_inplace_permutate>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    1137 <bit_inplace_permutate+0x27>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebp
test   %ebx,%ebx
je     1150 <bit_inplace_permutate+0x40>
sub    %r15d,%ebx
and    %r15d,%ebx
mov    %ebx,%edi
call   1030 <print_integer_in_binary@plt>
test   %r14,%r14
je     1130 <bit_inplace_permutate+0x20>
mov    %ebx,%edi
call   *%r14
jmp    1130 <bit_inplace_permutate+0x20>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bit_inplace_permutate(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
store i32 0, i32* %6
br label %7
7: ; preds = %23, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %3
%10 = sub i32 %8, %9
%11 = load i32, i32* %3
%12 = and i32 %10, %11
store i32 %12, i32* %6
%13 = load i32, i32* %5
%14 = add nsw i32 %13, 1
store i32 %14, i32* %5
%15 = load i32, i32* %6
%16 = call i32 @print_integer_in_binary(i32 %15)
%17 = load void (i32)*, void (i32)** %4
%18 = icmp ne void (i32)* %17, null
br i1 %18, label %19, label %22
19: ; preds = %7
%20 = load void (i32)*, void (i32)** %4
%21 = load i32, i32* %6
br label %22
22: ; preds = %19, %7
br label %23
23: ; preds = %22
%24 = load i32, i32* %6
%25 = icmp ne i32 %24, 0
br i1 %25, label %7, label %26
26: ; preds = %23
%27 = load i32, i32* %5
ret i32 %27
}

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