#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 uint64_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
void test_binary_printf(uint64_t n, int bits_num) {
  int i;
  for (i = bits_num - 1; i >= 0; i--) {
    if ((n >> i) & 1) {
      printf("1");
    } else {
      printf("0");
    }
    if (i % 4 == 0) {
      printf(" ");
    }
  }
}


x86 assembly (clang, -O0):
<test_binary_printf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1195 <test_binary_printf+0x85>
mov    -0x4(%rbp),%eax
mov    -0xc(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1156 <test_binary_printf+0x46>
lea    0xeb4(%rip),%rdi
call   1030 <printf@plt>
jmp    1162 <test_binary_printf+0x52>
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1182 <test_binary_printf+0x72>
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
jmp    1187 <test_binary_printf+0x77>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1127 <test_binary_printf+0x17>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_binary_printf>:
push   %rbp
push   %r14
push   %rbx
test   %esi,%esi
jle    115e <test_binary_printf+0x4e>
mov    %esi,%ebx
mov    %edi,%r14d
add    $0x1,%ebx
jmp    1138 <test_binary_printf+0x28>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
jbe    115e <test_binary_printf+0x4e>
lea    -0x2(%rbx),%ebp
bt     %ebp,%r14d
mov    $0x31,%edi
adc    $0xffffffff,%edi
call   1030 <putchar@plt>
test   $0x3,%bpl
jne    1130 <test_binary_printf+0x20>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1130 <test_binary_printf+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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