#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 */
typedef int /*<<< orphan*/ value;

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
void PrintBits(unsigned int value) {
  unsigned int bitcount = 0;
  unsigned int mask = 0;
  bitcount = sizeof(value) * 8;
  for (unsigned int i = bitcount; i > 0; --i) {
    mask = 1 << (i - 1);
    if ((value & mask) != 0)
      printf("1");
    else
      printf("0");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<PrintBits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x20,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jbe    118f <PrintBits+0x7f>
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
and    -0xc(%rbp),%eax
cmp    $0x0,%eax
je     1170 <PrintBits+0x60>
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
jmp    117c <PrintBits+0x6c>
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
jmp    1181 <PrintBits+0x71>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <PrintBits+0x26>
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PrintBits>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x1f,%ebp
nopw   0x0(%rax,%rax,1)
bt     %ebp,%ebx
mov    $0x31,%edi
adc    $0xffffffff,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jb     1120 <PrintBits+0x10>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
define void @PrintBits(i32 %0) {
br label %4
2: ; preds = %4
%3 = tail call i32 @putchar(i32 10)
ret void
4: ; preds = %1, %4
%5 = phi i32 [ 32, %1 ], [ %6, %4 ]
%6 = add nsw i32 %5, -1
%7 = shl nuw i32 1, %6
%8 = and i32 %7, %0
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, i32 48, i32 49
%11 = tail call i32 @putchar(i32 %10)
%12 = icmp eq i32 %6, 0
br i1 %12, label %2, label %4
}