#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 printbits_n_1(int n, int num) {
  int i;
  for (i = 0; i < 32 && i < num; i++) {
    if ((i % 4) == 0)
      printf(" ");
    printf("%c", ((n & 1) == 0) ? '0' : '1');
    n >>= 1;
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<printbits_n_1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x20,-0xc(%rbp)
mov    %al,-0xd(%rbp)
jge    1140 <printbits_n_1+0x30>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
setl   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1150 <printbits_n_1+0x40>
jmp    11ad <printbits_n_1+0x9d>
mov    -0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1172 <printbits_n_1+0x62>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%ecx
and    $0x1,%ecx
mov    $0x31,%esi
mov    $0x30,%eax
cmp    $0x0,%ecx
cmove  %eax,%esi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1125 <printbits_n_1+0x15>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printbits_n_1>:
push   %rbp
push   %r14
push   %rbx
test   %esi,%esi
jle    1169 <printbits_n_1+0x59>
mov    %edi,%ebx
add    $0xffffffff,%esi
cmp    $0x1f,%esi
mov    $0x1f,%r14d
cmovb  %esi,%r14d
add    $0x1,%r14d
xor    %ebp,%ebp
jmp    1157 <printbits_n_1+0x47>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
and    $0x1,%edi
or     $0x30,%edi
call   1030 <putchar@plt>
sar    %ebx
add    $0x1,%ebp
cmp    %ebp,%r14d
je     1169 <printbits_n_1+0x59>
test   $0x3,%bpl
jne    1140 <printbits_n_1+0x30>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1140 <printbits_n_1+0x30>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
define void @printbits_n_1(i32 %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %21
4: ; preds = %2
%5 = add nsw i32 %1, -1
%6 = call i32 @llvm.umin.i32(i32 %5, i32 31)
br label %7
7: ; preds = %4, %14
%8 = phi i32 [ %19, %14 ], [ 0, %4 ]
%9 = phi i32 [ %18, %14 ], [ %0, %4 ]
%10 = and i32 %8, 3
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @putchar(i32 32)
br label %14
14: ; preds = %12, %7
%15 = and i32 %9, 1
%16 = or i32 %15, 48
%17 = tail call i32 @putchar(i32 %16)
%18 = ashr i32 %9, 1
%19 = add nuw nsw i32 %8, 1
%20 = icmp eq i32 %8, %6
br i1 %20, label %21, label %7
21: ; preds = %14, %2
%22 = tail call i32 @putchar(i32 10)
ret void
}