#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*/ n;

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
void printbits(int n) {
  unsigned int i, step;
  int j = 1;
  if (0 == n) {
    printf("0000");
    return;
  }
  i = 1 << (sizeof(n) * 8 - 1);
  step = -1;
  step >>= 4;
  while (step >= n) {
    i >>= 4;
    step >>= 4;
  }
  while (i > 0) {
    if (n & i)
      printf("1");
    else
      printf("0");
    i >>= 1;
    if ((j++ % 4) == 0)
      printf(" ");
  }
}


x86 assembly (clang, -O0):
<printbits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x4(%rbp),%eax
jne    113e <printbits+0x2e>
lea    0xecc(%rip),%rdi
call   1030 <printf@plt>
jmp    11e9 <printbits+0xd9>
movl   $0x80000000,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x4,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jb     1178 <printbits+0x68>
mov    -0x8(%rbp),%eax
shr    $0x4,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x4,%eax
mov    %eax,-0xc(%rbp)
jmp    1155 <printbits+0x45>
jmp    117d <printbits+0x6d>
cmpl   $0x0,-0x8(%rbp)
jbe    11e9 <printbits+0xd9>
mov    -0x4(%rbp),%eax
and    -0x8(%rbp),%eax
cmp    $0x0,%eax
je     11a7 <printbits+0x97>
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
jmp    11b3 <printbits+0xa3>
lea    0xe55(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11e4 <printbits+0xd4>
lea    0xe28(%rip),%rdi
call   1030 <printf@plt>
jmp    117d <printbits+0x6d>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printbits>:
test   %edi,%edi
je     11a4 <printbits+0x84>
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    $0x80000000,%ebp
cmp    $0xfffffff,%edi
ja     1167 <printbits+0x47>
mov    $0x80000000,%ebp
mov    $0xfffffff,%eax
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%ecx
shr    $0x4,%ebp
shr    $0x4,%eax
cmp    %r14d,%eax
jae    1150 <printbits+0x30>
cmp    $0x10,%ecx
jae    1167 <printbits+0x47>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0x1,%ebx
jmp    117e <printbits+0x5e>
xchg   %ax,%ax
mov    %ebp,%eax
shr    %eax
add    $0x1,%ebx
cmp    $0x1,%ebp
mov    %eax,%ebp
jbe    1162 <printbits+0x42>
mov    %ebp,%eax
and    %r14d,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
test   $0x3,%bl
jne    1170 <printbits+0x50>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1170 <printbits+0x50>
lea    0xe55(%rip),%rdi
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"0000\00"
@.str.1 = [2 x i8] c"1\00"
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [2 x i8] c" \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 1, i32* %5
%6 = load i32, i32* %2
%7 = icmp eq i32 0, %6
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %45
10: ; preds = %1
store i32 -2147483648, i32* %3
store i32 -1, i32* %4
%11 = load i32, i32* %4
%12 = lshr i32 %11, 4
store i32 %12, i32* %4
br label %13
13: ; preds = %17, %10
%14 = load i32, i32* %4
%15 = load i32, i32* %2
%16 = icmp uge i32 %14, %15
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i32, i32* %3
%19 = lshr i32 %18, 4
store i32 %19, i32* %3
%20 = load i32, i32* %4
%21 = lshr i32 %20, 4
store i32 %21, i32* %4
br label %13
22: ; preds = %13
br label %23
23: ; preds = %44, %22
%24 = load i32, i32* %3
%25 = icmp ugt i32 %24, 0
br i1 %25, label %26, label %45
26: ; preds = %23
%27 = load i32, i32* %2
%28 = load i32, i32* %3
%29 = and i32 %27, %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %35
33: ; preds = %26
%34 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33, %31
%36 = load i32, i32* %3
%37 = lshr i32 %36, 1
store i32 %37, i32* %3
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
%40 = srem i32 %38, 4
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %35
%43 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %42, %35
br label %23
45: ; preds = %8, %23
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"0000\00"
define void @printbits(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %5, label %3
3: ; preds = %1
%4 = icmp ugt i32 %0, 268435455
br i1 %4, label %9, label %11
5: ; preds = %1
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %32
7: ; preds = %11
%8 = icmp ult i32 %13, 16
br i1 %8, label %32, label %9
9: ; preds = %3, %7
%10 = phi i32 [ %14, %7 ], [ -2147483648, %3 ]
br label %17
11: ; preds = %3, %11
%12 = phi i32 [ %15, %11 ], [ 268435455, %3 ]
%13 = phi i32 [ %14, %11 ], [ -2147483648, %3 ]
%14 = lshr i32 %13, 4
%15 = lshr i32 %12, 4
%16 = icmp ult i32 %15, %0
br i1 %16, label %7, label %11
17: ; preds = %9, %30
%18 = phi i32 [ %25, %30 ], [ 1, %9 ]
%19 = phi i32 [ %24, %30 ], [ %10, %9 ]
%20 = and i32 %19, %0
%21 = icmp eq i32 %20, 0
%22 = select i1 %21, i32 48, i32 49
%23 = tail call i32 @putchar(i32 %22)
%24 = lshr i32 %19, 1
%25 = add nuw nsw i32 %18, 1
%26 = and i32 %18, 3
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %17
%29 = tail call i32 @putchar(i32 32)
br label %30
30: ; preds = %28, %17
%31 = icmp ult i32 %19, 2
br i1 %31, label %32, label %17
32: ; preds = %30, %7, %5
ret void
}