#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_32(int a) {
  int i;
  for (i = 31; i > -1; i--) {
    printf("%d", ((a >> i) & 0x1));
    if (i % 8 == 0)
      printf(" ");
  }
}


x86 assembly (clang, -O0):
<print_bits_32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1f,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jle    117a <print_bits_32+0x6a>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%ecx
sar    %cl,%esi
and    $0x1,%esi
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1167 <print_bits_32+0x57>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    116c <print_bits_32+0x5c>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1122 <print_bits_32+0x12>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bits_32>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
mov    $0x1f,%ebp
lea    0xece(%rip),%r14
jmp    1145 <print_bits_32+0x25>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffff,%ebp
jae    116a <print_bits_32+0x4a>
mov    %ebx,%esi
mov    %ebp,%ecx
shr    %cl,%esi
and    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x7,%bpl
jne    1140 <print_bits_32+0x20>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1140 <print_bits_32+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define void @print_bits_32(i32 %0) {
br label %2
2: ; preds = %1, %11
%3 = phi i32 [ 31, %1 ], [ %12, %11 ]
%4 = lshr i32 %0, %3
%5 = and i32 %4, 1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = and i32 %3, 7
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @putchar(i32 32)
br label %11
11: ; preds = %2, %9
%12 = add nsw i32 %3, -1
%13 = icmp eq i32 %3, 0
br i1 %13, label %14, label %2
14: ; preds = %11
ret void
}