#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*/ assert(int);
int /*<<< orphan*/ printf(char *, int);
void print_bits(unsigned integer, unsigned bits) {
  assert(bits > 0);
  register int i;
  for (i = (1 << (bits - 1)); i >= 1; i >>= 1) {
    printf("%d", ((integer & i) == i) ? 1 : 0);
  }
}


x86 assembly (clang, -O0):
<print_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jl     1188 <print_bits+0x68>
mov    -0x4(%rbp),%ecx
and    -0xc(%rbp),%ecx
mov    -0xc(%rbp),%edx
xor    %esi,%esi
mov    $0x1,%eax
cmp    %edx,%ecx
cmove  %eax,%esi
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114f <print_bits+0x2f>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bits>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%r15d
xor    %edi,%edi
add    $0xffffffff,%r14d
setb   %dil
call   1040 <assert@plt>
cmp    $0x1f,%r14d
je     117a <print_bits+0x5a>
mov    $0x1,%ebx
mov    %r14d,%ecx
shl    %cl,%ebx
not    %r15d
lea    0xeaa(%rip),%r14
mov    %ebx,%ebp
nopl   0x0(%rax,%rax,1)
xor    %esi,%esi
test   %r15d,%ebx
sete   %sil
mov    %r14,%rdi
call   1030 <printf@plt>
shr    %ebp
cmp    $0x1,%ebx
mov    %ebp,%ebx
ja     1160 <print_bits+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define void @print_bits(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 = icmp ugt i32 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* %4
%11 = sub i32 %10, 1
%12 = shl i32 1, %11
store i32 %12, i32* %5
br label %13
13: ; preds = %25, %2
%14 = load i32, i32* %5
%15 = icmp sge i32 %14, 1
br i1 %15, label %16, label %28
16: ; preds = %13
%17 = load i32, i32* %3
%18 = load i32, i32* %5
%19 = and i32 %17, %18
%20 = load i32, i32* %5
%21 = icmp eq i32 %19, %20
%22 = zext i1 %21 to i64
%23 = select i1 %21, i32 1, i32 0
%24 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %16
%26 = load i32, i32* %5
%27 = ashr i32 %26, 1
store i32 %27, i32* %5
br label %13
28: ; preds = %13
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define void @print_bits(i32 %0, i32 %1) {
%3 = icmp ne i32 %1, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = add i32 %1, -1
%7 = icmp eq i32 %6, 31
br i1 %7, label %18, label %8
8: ; preds = %2
%9 = shl nuw nsw i32 1, %6
br label %10
10: ; preds = %8, %10
%11 = phi i32 [ %16, %10 ], [ %9, %8 ]
%12 = and i32 %11, %0
%13 = icmp eq i32 %12, %11
%14 = zext i1 %13 to i32
%15 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = lshr i32 %11, 1
%17 = icmp ult i32 %11, 2
br i1 %17, label %18, label %10
18: ; preds = %10, %2
ret void
}