#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 UINT_MAX;
int log(int);
int /*<<< orphan*/ printf(char *, unsigned int);
int /*<<< orphan*/ putchar(char);
void showbits(unsigned x) {
  int e;
  int maxbit = (unsigned)(log(UINT_MAX) / log(2));
  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),%edi
call   1050 <log@plt>
mov    %eax,-0x10(%rbp)
mov    $0x2,%edi
call   1050 <log@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11aa <showbits+0x7a>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%ecx
shr    %cl,%esi
lea    0xe80(%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    1167 <showbits+0x37>
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    %edi,%ebx
mov    0x2eab(%rip),%rax
mov    (%rax),%edi
call   1050 <log@plt>
mov    %eax,%ebp
mov    $0x2,%edi
call   1050 <log@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
test   %eax,%eax
js     1190 <showbits+0x60>
mov    %eax,%ebp
lea    0xe9c(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
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     1170 <showbits+0x40>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>

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

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