#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*/ strcat(char *, char *);
const char *bin_n(unsigned short x, unsigned char n) {
  static char b[9];
  b[0] = '\0';
  for (unsigned short i = 1 << (n - 1); i > 0; i >>= 1)
    strcat(b, (x & i) ? "1" : "0");
  return b;
}


x86 assembly (clang, -O0):
<bin_n>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %di,%cx
mov    %cx,-0x2(%rbp)
mov    %al,-0x3(%rbp)
movb   $0x0,0x2efd(%rip)
movzbl -0x3(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %ax,-0x6(%rbp)
movzwl -0x6(%rbp),%eax
cmp    $0x0,%eax
jle    1186 <bin_n+0x76>
movzwl -0x2(%rbp),%ecx
movzwl -0x6(%rbp),%eax
and    %eax,%ecx
lea    0xea6(%rip),%rsi
lea    0xe9d(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0x2eb8(%rip),%rdi
call   1030 <strcat@plt>
movzwl -0x6(%rbp),%eax
sar    $0x1,%eax
mov    %ax,-0x6(%rbp)
jmp    113e <bin_n+0x2e>
lea    0x2e9c(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bin_n>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ecx
movb   $0x0,0x2f05(%rip)
add    $0xffffffff,%ecx
mov    $0x1,%eax
shl    %cl,%eax
cmp    $0xf,%ecx
ja     117d <bin_n+0x6d>
movzwl %ax,%ebx
movzwl %di,%r13d
lea    0xec1(%rip),%r15
lea    0xeb8(%rip),%r12
lea    0x2eda(%rip),%r14
mov    %ebx,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
test   %r13d,%eax
mov    %r12,%rsi
cmove  %r15,%rsi
mov    %r14,%rdi
call   1030 <strcat@plt>
shr    %ebp
mov    %ebp,%eax
cmp    $0x2,%ebx
mov    %ebp,%ebx
jae    1160 <bin_n+0x50>
lea    0x2ea5(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@bin_n.b = internal global [9 x i8] zeroinitializer
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
define i8* @bin_n(i16 zeroext %0, i8 zeroext %1) {
%3 = alloca i16
%4 = alloca i8
%5 = alloca i16
store i16 %0, i16* %3
store i8 %1, i8* %4
store i8 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @bin_n.b, i64 0, i64 0)
%6 = load i8, i8* %4
%7 = zext i8 %6 to i32
%8 = sub nsw i32 %7, 1
%9 = shl i32 1, %8
%10 = trunc i32 %9 to i16
store i16 %10, i16* %5
br label %11
11: ; preds = %25, %2
%12 = load i16, i16* %5
%13 = zext i16 %12 to i32
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = load i16, i16* %3
%17 = zext i16 %16 to i32
%18 = load i16, i16* %5
%19 = zext i16 %18 to i32
%20 = and i32 %17, %19
%21 = icmp ne i32 %20, 0
%22 = zext i1 %21 to i64
%23 = select i1 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%24 = call i32 @strcat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @bin_n.b, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %15
%26 = load i16, i16* %5
%27 = zext i16 %26 to i32
%28 = ashr i32 %27, 1
%29 = trunc i32 %28 to i16
store i16 %29, i16* %5
br label %11
30: ; preds = %11
ret i8* getelementptr inbounds ([9 x i8], [9 x i8]* @bin_n.b, i64 0, i64 0)
}

LLVM IR (-O2):
@bin_n.b = internal global [9 x i8] zeroinitializer
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
define i8* @bin_n(i16 zeroext %0, i8 zeroext %1) {
store i8 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @bin_n.b, i64 0, i64 0)
%3 = zext i8 %1 to i32
%4 = add nsw i32 %3, -1
%5 = shl nuw i32 1, %4
%6 = icmp ugt i32 %4, 15
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = and i32 %5, 65535
%9 = zext i16 %0 to i32
br label %11
10: ; preds = %11, %2
ret i8* getelementptr inbounds ([9 x i8], [9 x i8]* @bin_n.b, i64 0, i64 0)
11: ; preds = %7, %11
%12 = phi i32 [ %8, %7 ], [ %18, %11 ]
%13 = phi i32 [ %5, %7 ], [ %18, %11 ]
%14 = and i32 %13, %9
%15 = icmp eq i32 %14, 0
%16 = select i1 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%17 = tail call i32 @strcat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @bin_n.b, i64 0, i64 0), i8* %16)
%18 = lshr i32 %12, 1
%19 = icmp ult i32 %12, 2
br i1 %19, label %10, label %11
}