#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_n(int n, int num) {
  unsigned int i, step;
  int j = 1;
  int k = 0;
  int x = 1;
  if (0 == n) {
    j = num / 4;
    while (j > 0) {
      printf("0000 ");
      j--;
    }
    return;
  }
  i = 1 << (sizeof(n) * 8 - 1);
  step = -1;
  step >>= 4;
  while (step >= n) {
    i >>= 4;
    step >>= 4;
  }
  k = i;
  while ((k >>= 1) != 0) {
    x++;
  }
  j = 1;
  while (x < num) {
    printf("0");
    if ((j++ % 4) == 0)
      printf(" ");
    x++;
  }
  j = 1;
  while (i > 0) {
    if (n & i)
      printf("1");
    else
      printf("0");
    i >>= 1;
    if ((j++ % 4) == 0)
      printf(" ");
  }
}


x86 assembly (clang, -O0):
<printbits_n>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
xor    %eax,%eax
cmp    -0x4(%rbp),%eax
jne    1175 <printbits_n+0x65>
mov    -0x8(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1170 <printbits_n+0x60>
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    114c <printbits_n+0x3c>
jmp    129d <printbits_n+0x18d>
movl   $0x80000000,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    -0x10(%rbp),%eax
shr    $0x4,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jb     11af <printbits_n+0x9f>
mov    -0xc(%rbp),%eax
shr    $0x4,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
shr    $0x4,%eax
mov    %eax,-0x10(%rbp)
jmp    118c <printbits_n+0x7c>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     11d5 <printbits_n+0xc5>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b5 <printbits_n+0xa5>
movl   $0x1,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    122a <printbits_n+0x11a>
lea    0xe17(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    121c <printbits_n+0x10c>
lea    0xded(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11dc <printbits_n+0xcc>
movl   $0x1,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
jbe    129d <printbits_n+0x18d>
mov    -0x4(%rbp),%eax
and    -0xc(%rbp),%eax
cmp    $0x0,%eax
je     125b <printbits_n+0x14b>
lea    0xdb7(%rip),%rdi
call   1030 <printf@plt>
jmp    1267 <printbits_n+0x157>
lea    0xda4(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1298 <printbits_n+0x188>
lea    0xd71(%rip),%rdi
call   1030 <printf@plt>
jmp    1231 <printbits_n+0x121>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printbits_n>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
test   %edi,%edi
je     1205 <printbits_n+0xe5>
mov    %edi,%r14d
mov    $0x80000000,%ebx
cmp    $0xfffffff,%edi
ja     1167 <printbits_n+0x47>
mov    $0x80000000,%ebx
mov    $0xfffffff,%eax
nopl   (%rax)
mov    %ebx,%ecx
shr    $0x4,%ebx
shr    $0x4,%eax
cmp    %r14d,%eax
jae    1150 <printbits_n+0x30>
mov    $0x1,%ebp
cmp    $0x20,%ecx
jb     117c <printbits_n+0x5c>
mov    $0x1,%ebp
mov    %ebx,%ecx
mov    %ebx,%eax
sar    %eax
add    $0x1,%ebp
cmp    $0x4,%ecx
mov    %eax,%ecx
jae    1170 <printbits_n+0x50>
sub    %r15d,%ebp
jge    11bd <printbits_n+0x9d>
mov    $0x1,%r15d
jmp    1199 <printbits_n+0x79>
nopl   0x0(%rax)
lea    (%r15,%rbp,1),%eax
cmp    $0x1,%eax
je     11bd <printbits_n+0x9d>
mov    %r15d,%r12d
mov    $0x30,%edi
call   1030 <putchar@plt>
lea    0x1(%r12),%r15d
test   $0x3,%r12b
jne    1190 <printbits_n+0x70>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1190 <printbits_n+0x70>
test   %ebx,%ebx
je     1232 <printbits_n+0x112>
mov    $0x1,%ebp
jmp    11de <printbits_n+0xbe>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%eax
shr    %eax
add    $0x1,%ebp
cmp    $0x1,%ebx
mov    %eax,%ebx
jbe    1232 <printbits_n+0x112>
mov    %ebx,%eax
and    %r14d,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
test   $0x3,%bpl
jne    11d0 <printbits_n+0xb0>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    11d0 <printbits_n+0xb0>
cmp    $0x4,%r15d
jl     1232 <printbits_n+0x112>
shr    $0x2,%r15d
add    $0x1,%r15d
lea    0xde6(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <printf@plt>
add    $0xffffffff,%r15d
cmp    $0x1,%r15d
ja     1220 <printbits_n+0x100>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"0000 \00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"1\00"
define void @printbits_n(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 1, i32* %7
store i32 0, i32* %8
store i32 1, i32* %9
%10 = load i32, i32* %3
%11 = icmp eq i32 0, %10
br i1 %11, label %12, label %23
12: ; preds = %2
%13 = load i32, i32* %4
%14 = sdiv i32 %13, 4
store i32 %14, i32* %7
br label %15
15: ; preds = %18, %12
%16 = load i32, i32* %7
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* %7
%21 = add nsw i32 %20, -1
store i32 %21, i32* %7
br label %15
22: ; preds = %15
br label %83
23: ; preds = %2
store i32 -2147483648, i32* %5
store i32 -1, i32* %6
%24 = load i32, i32* %6
%25 = lshr i32 %24, 4
store i32 %25, i32* %6
br label %26
26: ; preds = %30, %23
%27 = load i32, i32* %6
%28 = load i32, i32* %3
%29 = icmp uge i32 %27, %28
br i1 %29, label %30, label %35
30: ; preds = %26
%31 = load i32, i32* %5
%32 = lshr i32 %31, 4
store i32 %32, i32* %5
%33 = load i32, i32* %6
%34 = lshr i32 %33, 4
store i32 %34, i32* %6
br label %26
35: ; preds = %26
%36 = load i32, i32* %5
store i32 %36, i32* %8
br label %37
37: ; preds = %41, %35
%38 = load i32, i32* %8
%39 = ashr i32 %38, 1
store i32 %39, i32* %8
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %37
44: ; preds = %37
store i32 1, i32* %7
br label %45
45: ; preds = %57, %44
%46 = load i32, i32* %9
%47 = load i32, i32* %4
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %60
49: ; preds = %45
%50 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
%53 = srem i32 %51, 4
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %49
%56 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %57
57: ; preds = %55, %49
%58 = load i32, i32* %9
%59 = add nsw i32 %58, 1
store i32 %59, i32* %9
br label %45
60: ; preds = %45
store i32 1, i32* %7
br label %61
61: ; preds = %82, %60
%62 = load i32, i32* %5
%63 = icmp ugt i32 %62, 0
br i1 %63, label %64, label %83
64: ; preds = %61
%65 = load i32, i32* %3
%66 = load i32, i32* %5
%67 = and i32 %65, %66
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %64
%70 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %73
71: ; preds = %64
%72 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %73
73: ; preds = %71, %69
%74 = load i32, i32* %5
%75 = lshr i32 %74, 1
store i32 %75, i32* %5
%76 = load i32, i32* %7
%77 = add nsw i32 %76, 1
store i32 %77, i32* %7
%78 = srem i32 %76, 4
%79 = icmp eq i32 %78, 0
br i1 %79, label %80, label %82
80: ; preds = %73
%81 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %82
82: ; preds = %80, %73
br label %61
83: ; preds = %22, %61
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"0000 \00"
define void @printbits_n(i32 %0, i32 %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = icmp ugt i32 %0, 268435455
br i1 %5, label %17, label %19
6: ; preds = %2
%7 = icmp sgt i32 %1, 3
br i1 %7, label %8, label %65
8: ; preds = %6
%9 = lshr i32 %1, 2
br label %10
10: ; preds = %8, %10
%11 = phi i32 [ %13, %10 ], [ %9, %8 ]
%12 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = add nsw i32 %11, -1
%14 = icmp ugt i32 %11, 1
br i1 %14, label %10, label %65
15: ; preds = %19
%16 = icmp ult i32 %21, 32
br i1 %16, label %25, label %17
17: ; preds = %4, %15
%18 = phi i32 [ %22, %15 ], [ -2147483648, %4 ]
br label %32
19: ; preds = %4, %19
%20 = phi i32 [ %23, %19 ], [ 268435455, %4 ]
%21 = phi i32 [ %22, %19 ], [ -2147483648, %4 ]
%22 = lshr i32 %21, 4
%23 = lshr i32 %20, 4
%24 = icmp ult i32 %23, %0
br i1 %24, label %15, label %19
25: ; preds = %32, %15
%26 = phi i32 [ %22, %15 ], [ %18, %32 ]
%27 = phi i32 [ 1, %15 ], [ %36, %32 ]
%28 = icmp slt i32 %27, %1
br i1 %28, label %29, label %38
29: ; preds = %25
%30 = add i32 %1, 1
%31 = sub i32 %30, %27
br label %40
32: ; preds = %17, %32
%33 = phi i32 [ %36, %32 ], [ 1, %17 ]
%34 = phi i32 [ %35, %32 ], [ %18, %17 ]
%35 = ashr i32 %34, 1
%36 = add nuw nsw i32 %33, 1
%37 = icmp ult i32 %34, 4
br i1 %37, label %25, label %32
38: ; preds = %48, %25
%39 = icmp eq i32 %26, 0
br i1 %39, label %65, label %50
40: ; preds = %29, %48
%41 = phi i32 [ %43, %48 ], [ 1, %29 ]
%42 = tail call i32 @putchar(i32 48)
%43 = add nuw i32 %41, 1
%44 = and i32 %41, 3
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %40
%47 = tail call i32 @putchar(i32 32)
br label %48
48: ; preds = %46, %40
%49 = icmp eq i32 %43, %31
br i1 %49, label %38, label %40
50: ; preds = %38, %63
%51 = phi i32 [ %58, %63 ], [ 1, %38 ]
%52 = phi i32 [ %57, %63 ], [ %26, %38 ]
%53 = and i32 %52, %0
%54 = icmp eq i32 %53, 0
%55 = select i1 %54, i32 48, i32 49
%56 = tail call i32 @putchar(i32 %55)
%57 = lshr i32 %52, 1
%58 = add nuw nsw i32 %51, 1
%59 = and i32 %51, 3
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %50
%62 = tail call i32 @putchar(i32 32)
br label %63
63: ; preds = %61, %50
%64 = icmp ult i32 %52, 2
br i1 %64, label %65, label %50
65: ; preds = %63, %10, %38, %6
ret void
}