#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*/ printf(char *, unsigned int);
int /*<<< orphan*/ putchar(char);
void showbits(unsigned x) {
  extern unsigned maxbit;
  int e;
  for (e = maxbit; e >= 0; --e) {
    printf("%u", x >> e);
    x = x & ((1 << e) - 1);
  }
  putchar('\n');
}


x86 assembly (clang, -O0):
<showbits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2ea6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     117a <showbits+0x5a>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%ecx
shr    %cl,%esi
lea    0xeb0(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
sub    $0x1,%ecx
and    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1137 <showbits+0x17>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<showbits>:
push   %rbp
push   %r14
push   %rbx
mov    0x2ead(%rip),%rax
mov    (%rax),%ebp
test   %ebp,%ebp
js     1160 <showbits+0x40>
mov    %edi,%ebx
lea    0xec6(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %ebx,%esi
mov    %ebp,%ecx
shr    %cl,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
mov    %ebp,%ecx
shl    %cl,%eax
not    %eax
and    %eax,%ebx
add    $0xffffffff,%ebp
jb     1140 <showbits+0x20>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@maxbit = external global i32
@.str = [3 x i8] c"%u\00"
define void @showbits(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* @maxbit
store i32 %4, i32* %3
br label %5
5: ; preds = %18, %1
%6 = load i32, i32* %3
%7 = icmp sge i32 %6, 0
br i1 %7, label %8, label %21
8: ; preds = %5
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = lshr i32 %9, %10
%12 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = shl i32 1, %14
%16 = sub nsw i32 %15, 1
%17 = and i32 %13, %16
store i32 %17, i32* %2
br label %18
18: ; preds = %8
%19 = load i32, i32* %3
%20 = add nsw i32 %19, -1
store i32 %20, i32* %3
br label %5
21: ; preds = %5
%22 = call i32 @putchar(i8 signext 10)
ret void
}

LLVM IR (-O2):
@maxbit = external global i32
@.str = [3 x i8] c"%u\00"
define void @showbits(i32 %0) {
%2 = load i32, i32* @maxbit
%3 = icmp sgt i32 %2, -1
br i1 %3, label %4, label %14
4: ; preds = %1, %4
%5 = phi i32 [ %12, %4 ], [ %2, %1 ]
%6 = phi i32 [ %11, %4 ], [ %0, %1 ]
%7 = lshr i32 %6, %5
%8 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = shl nsw i32 -1, %5
%10 = xor i32 %9, -1
%11 = and i32 %6, %10
%12 = add nsw i32 %5, -1
%13 = icmp eq i32 %5, 0
br i1 %13, label %14, label %4
14: ; preds = %4, %1
%15 = tail call i32 @putchar(i8 signext 10)
ret void
}