#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 *, ...);
void print_bits(int i) {
  int index;
  printf("% i = 0b", i);
  for (index = 8; index >= 0; index--) {
    if (i & (1 << index)) {
      printf("1");
    } else {
      printf("0");
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xedb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x8,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     118b <print_bits+0x7b>
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     116a <print_bits+0x5a>
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1178 <print_bits+0x68>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    117d <print_bits+0x6d>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1133 <print_bits+0x23>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bits>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %edi,0x4(%rsp)
lea    0xee8(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movd   %ebx,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xeae(%rip),%xmm1
pand   %xmm0,%xmm1
pand   0xeb2(%rip),%xmm0
pxor   %xmm2,%xmm2
pcmpeqd %xmm2,%xmm0
pcmpeqd %xmm2,%xmm1
packssdw %xmm0,%xmm1
packsswb %xmm1,%xmm1
pmovmskb %xmm1,%ebp
mov    %ebp,%eax
and    $0x2,%al
shr    %al
mov    %al,0x3(%rsp)
mov    %ebp,%r12d
and    $0x4,%r12b
shr    $0x2,%r12b
mov    %ebp,%r13d
and    $0x8,%r13b
shr    $0x3,%r13b
mov    %ebp,%ebx
and    $0x10,%bl
shr    $0x4,%bl
mov    %ebp,%r14d
and    $0x20,%r14b
shr    $0x5,%r14b
mov    %ebp,%r15d
and    $0x40,%r15b
shr    $0x6,%r15b
mov    %ebp,%eax
shr    $0x7,%al
movzbl %al,%edi
xor    $0x31,%edi
call   1030 <putchar@plt>
movzbl %r15b,%edi
xor    $0x31,%edi
call   1030 <putchar@plt>
movzbl %r14b,%edi
xor    $0x31,%edi
call   1030 <putchar@plt>
movzbl %bl,%edi
xor    $0x31,%edi
call   1030 <putchar@plt>
movzbl %r13b,%edi
xor    $0x31,%edi
call   1030 <putchar@plt>
movzbl %r12b,%edi
xor    $0x31,%edi
call   1030 <putchar@plt>
movzbl 0x3(%rsp),%edi
xor    $0x31,%edi
call   1030 <putchar@plt>
and    $0x1,%ebp
xor    $0x31,%ebp
mov    %ebp,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%edi
and    $0x1,%edi
or     $0x30,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str = [9 x i8] c"% i = 0b\00"
define void @print_bits(i32 %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = insertelement <8 x i32> poison, i32 %0, i64 0
%4 = shufflevector <8 x i32> %3, <8 x i32> poison, <8 x i32> zeroinitializer
%5 = and <8 x i32> %4, <i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128, i32 256>
%6 = icmp eq <8 x i32> %5, zeroinitializer
%7 = extractelement <8 x i1> %6, i64 7
%8 = select i1 %7, i32 48, i32 49
%9 = tail call i32 @putchar(i32 %8)
%10 = extractelement <8 x i1> %6, i64 6
%11 = select i1 %10, i32 48, i32 49
%12 = tail call i32 @putchar(i32 %11)
%13 = extractelement <8 x i1> %6, i64 5
%14 = select i1 %13, i32 48, i32 49
%15 = tail call i32 @putchar(i32 %14)
%16 = extractelement <8 x i1> %6, i64 4
%17 = select i1 %16, i32 48, i32 49
%18 = tail call i32 @putchar(i32 %17)
%19 = extractelement <8 x i1> %6, i64 3
%20 = select i1 %19, i32 48, i32 49
%21 = tail call i32 @putchar(i32 %20)
%22 = extractelement <8 x i1> %6, i64 2
%23 = select i1 %22, i32 48, i32 49
%24 = tail call i32 @putchar(i32 %23)
%25 = extractelement <8 x i1> %6, i64 1
%26 = select i1 %25, i32 48, i32 49
%27 = tail call i32 @putchar(i32 %26)
%28 = extractelement <8 x i1> %6, i64 0
%29 = select i1 %28, i32 48, i32 49
%30 = tail call i32 @putchar(i32 %29)
%31 = and i32 %0, 1
%32 = or i32 %31, 48
%33 = tail call i32 @putchar(i32 %32)
%34 = tail call i32 @putchar(i32 10)
ret void
}