#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 *);
int /*<<< orphan*/ putchar(char);
void print_bits(int value) {
  int i;
  int s = sizeof(int) * 8;
  int mask = 1 << (s - 1);
  for (i = 1; i <= s; i++) {
    putchar(((value & mask) == 0) ? '0' : '1');
    value = value << 1;
    if (i % 8 == 0 && i < s) {
      printf(" ");
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x20,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x10(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11bb <print_bits+0x9b>
mov    -0x4(%rbp),%edx
and    -0x10(%rbp),%edx
mov    $0x31,%eax
mov    $0x30,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
movsbl %al,%edi
call   1030 <putchar@plt>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11a8 <print_bits+0x88>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a8 <print_bits+0x88>
lea    0xe5d(%rip),%rdi
call   1040 <printf@plt>
jmp    11ad <print_bits+0x8d>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1149 <print_bits+0x29>
lea    0xe40(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bits>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0xffffffe0,%ebx
jmp    1126 <print_bits+0x16>
nopl   0x0(%rax)
add    %ebp,%ebp
inc    %ebx
je     114c <print_bits+0x3c>
mov    %ebp,%edi
shr    $0x1f,%edi
or     $0x30,%edi
call   1030 <putchar@plt>
cmp    $0xffffffff,%ebx
je     1120 <print_bits+0x10>
lea    0x21(%rbx),%eax
and    $0x7,%eax
jne    1120 <print_bits+0x10>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1120 <print_bits+0x10>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @print_bits(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 32, i32* %4
%6 = load i32, i32* %4
%7 = sub nsw i32 %6, 1
%8 = shl i32 1, %7
store i32 %8, i32* %5
store i32 1, i32* %3
br label %9
9: ; preds = %34, %1
%10 = load i32, i32* %3
%11 = load i32, i32* %4
%12 = icmp sle i32 %10, %11
br i1 %12, label %13, label %37
13: ; preds = %9
%14 = load i32, i32* %2
%15 = load i32, i32* %5
%16 = and i32 %14, %15
%17 = icmp eq i32 %16, 0
%18 = zext i1 %17 to i64
%19 = select i1 %17, i32 48, i32 49
%20 = trunc i32 %19 to i8
%21 = call i32 @putchar(i8 signext %20)
%22 = load i32, i32* %2
%23 = shl i32 %22, 1
store i32 %23, i32* %2
%24 = load i32, i32* %3
%25 = srem i32 %24, 8
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %13
%28 = load i32, i32* %3
%29 = load i32, i32* %4
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %31, %27, %13
br label %34
34: ; preds = %33
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %9
37: ; preds = %9
%38 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
define void @print_bits(i32 %0) {
br label %2
2: ; preds = %1, %15
%3 = phi i32 [ %0, %1 ], [ %8, %15 ]
%4 = phi i32 [ 1, %1 ], [ %16, %15 ]
%5 = icmp sgt i32 %3, -1
%6 = select i1 %5, i8 48, i8 49
%7 = tail call i32 @putchar(i8 signext %6)
%8 = shl i32 %3, 1
%9 = and i32 %4, 7
%10 = icmp eq i32 %9, 0
%11 = icmp ne i32 %4, 32
%12 = and i1 %11, %10
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = tail call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 32)
br label %15
15: ; preds = %2, %13
%16 = add nuw nsw i32 %4, 1
%17 = icmp eq i32 %16, 33
br i1 %17, label %18, label %2
18: ; preds = %15
%19 = tail call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 10)
ret void
}