#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*/ putchar(char);
void binary(unsigned int n, unsigned long value) {
  unsigned int i;
  for (i = 0; i < n; i++, value <<= 1)
    (void)putchar((1 << (n - 1) & value) ? '1' : '0');
  (void)putchar('\n');
}


x86 assembly (clang, -O0):
<binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    1179 <binary+0x69>
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
movslq %eax,%rdx
and    -0x10(%rbp),%rdx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
movsbl %al,%edi
call   1030 <putchar@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1126 <binary+0x16>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binary>:
push   %r15
push   %r14
push   %rbx
test   %edi,%edi
je     1150 <binary+0x40>
mov    %rsi,%rbx
mov    %edi,%r14d
lea    -0x1(%r14),%ecx
mov    $0x1,%eax
shl    %cl,%eax
movslq %eax,%r15
nopl   (%rax)
mov    %rbx,%rax
and    %r15,%rax
cmp    $0x1,%rax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
add    %rbx,%rbx
add    $0xffffffff,%r14d
jne    1130 <binary+0x20>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

LLVM IR (-O0):
define void @binary(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
store i32 %0, i32* %3
store i64 %1, i64* %4
store i32 0, i32* %5
br label %6
6: ; preds = %22, %2
%7 = load i32, i32* %5
%8 = load i32, i32* %3
%9 = icmp ult i32 %7, %8
br i1 %9, label %10, label %27
10: ; preds = %6
%11 = load i32, i32* %3
%12 = sub i32 %11, 1
%13 = shl i32 1, %12
%14 = sext i32 %13 to i64
%15 = load i64, i64* %4
%16 = and i64 %14, %15
%17 = icmp ne i64 %16, 0
%18 = zext i1 %17 to i64
%19 = select i1 %17, i32 49, i32 48
%20 = trunc i32 %19 to i8
%21 = call i32 @putchar(i8 signext %20)
br label %22
22: ; preds = %10
%23 = load i32, i32* %5
%24 = add i32 %23, 1
store i32 %24, i32* %5
%25 = load i64, i64* %4
%26 = shl i64 %25, 1
store i64 %26, i64* %4
br label %6
27: ; preds = %6
%28 = call i32 @putchar(i8 signext 10)
ret void
}

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