#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 = (int)log(UINT_MAX) / log(2);
  for (e = maxbit; e >= 0; --e) {
    printf("%u", x >> e);
    x = x << maxbit - (e - 1);
    x = x >> maxbit - (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     11b9 <showbits+0x89>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%ecx
shr    %cl,%esi
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
sub    %edx,%ecx
shl    %cl,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
sub    %edx,%ecx
shr    %cl,%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   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2ea8(%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     118e <showbits+0x5e>
mov    %eax,%r14d
mov    $0x1,%ebp
lea    0xe93(%rip),%r15
nopl   (%rax)
mov    %ebx,%esi
mov    %r14d,%ecx
shr    %cl,%esi
mov    %r15,%rdi
call   1040 <printf@plt>
mov    %ebp,%ecx
shl    %cl,%ebx
shr    %cl,%ebx
add    $0x1,%ebp
add    $0xffffffff,%r14d
jb     1170 <showbits+0x40>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
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 = %30, %1
%11 = load i32, i32* %3
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %33
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* %4
%20 = load i32, i32* %3
%21 = sub nsw i32 %20, 1
%22 = sub nsw i32 %19, %21
%23 = shl i32 %18, %22
store i32 %23, i32* %2
%24 = load i32, i32* %2
%25 = load i32, i32* %4
%26 = load i32, i32* %3
%27 = sub nsw i32 %26, 1
%28 = sub nsw i32 %25, %27
%29 = lshr i32 %24, %28
store i32 %29, i32* %2
br label %30
30: ; preds = %13
%31 = load i32, i32* %3
%32 = add nsw i32 %31, -1
store i32 %32, i32* %3
br label %10
33: ; preds = %10
%34 = 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 [ %15, %7 ], [ %0, %1 ]
%9 = phi i32 [ %12, %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 = add nsw i32 %9, -1
%13 = sub nsw i32 %5, %12
%14 = lshr i32 -1, %13
%15 = and i32 %14, %8
%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
}