#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 SHRT_MIN;
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *binarystr(unsigned short val) {
  static char buffer[18];
  memset(buffer, 0, 18);
  int mask = SHRT_MIN;
  int count;
  for (count = 0; count < 16; count++) {
    char ch = (val & mask) ? '1' : '0';
    val = val << 1;
    buffer[count] = ch;
  }
  buffer[count] = 'b';
  return buffer;
}


x86 assembly (clang, -O0):
<binarystr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
lea    0x2f1a(%rip),%rdi
xor    %esi,%esi
mov    $0x12,%edx
call   1030 <memset@plt>
mov    0x2ea7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x10,-0xc(%rbp)
jge    1193 <binarystr+0x83>
movzwl -0x2(%rbp),%edx
and    -0x8(%rbp),%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0xd(%rbp)
movzwl -0x2(%rbp),%eax
shl    $0x1,%eax
mov    %ax,-0x2(%rbp)
mov    -0xd(%rbp),%dl
movslq -0xc(%rbp),%rcx
lea    0x2ebe(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1145 <binarystr+0x35>
movslq -0xc(%rbp),%rcx
lea    0x2ea2(%rip),%rax
movb   $0x62,(%rax,%rcx,1)
lea    0x2e97(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binarystr>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0x2f24(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x12,%edx
call   1030 <memset@plt>
movd   %ebp,%xmm0
add    %ebp,%ebp
pshuflw $0x0,%xmm0,%xmm1
movdqa 0xec2(%rip),%xmm3
pmullw %xmm1,%xmm3
pshufd $0x0,%xmm1,%xmm2
pmullw 0xec1(%rip),%xmm1
pmullw 0xec9(%rip),%xmm2
pinsrw $0x1,%ebp,%xmm0
mov    0x2e7d(%rip),%rax
punpckldq %xmm3,%xmm0
pxor   %xmm3,%xmm3
movdqa %xmm2,%xmm4
punpckhwd %xmm3,%xmm4
punpcklwd %xmm3,%xmm2
punpcklwd %xmm3,%xmm1
punpcklwd %xmm3,%xmm0
movd   (%rax),%xmm5
pshufd $0x0,%xmm5,%xmm5
pand   %xmm5,%xmm0
pand   %xmm5,%xmm1
pand   %xmm5,%xmm2
pand   %xmm5,%xmm4
pcmpeqd %xmm3,%xmm4
pcmpeqd %xmm3,%xmm2
packssdw %xmm4,%xmm2
pcmpeqd %xmm3,%xmm1
pcmpeqd %xmm3,%xmm0
packssdw %xmm1,%xmm0
packsswb %xmm2,%xmm0
paddb  0xe74(%rip),%xmm0
movdqa %xmm0,0x2e7c(%rip)
movb   $0x62,0x2e85(%rip)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@binarystr.buffer = internal global [18 x i8] zeroinitializer
@SHRT_MIN = global i32 0
define i8* @binarystr(i16 zeroext %0) {
%2 = alloca i16
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i16 %0, i16* %2
%6 = call i32 @memset(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @binarystr.buffer, i64 0, i64 0), i32 0, i32 18)
%7 = load i32, i32* @SHRT_MIN
store i32 %7, i32* %3
store i32 0, i32* %4
br label %8
8: ; preds = %28, %1
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 16
br i1 %10, label %11, label %31
11: ; preds = %8
%12 = load i16, i16* %2
%13 = zext i16 %12 to i32
%14 = load i32, i32* %3
%15 = and i32 %13, %14
%16 = icmp ne i32 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, i32 49, i32 48
%19 = trunc i32 %18 to i8
store i8 %19, i8* %5
%20 = load i16, i16* %2
%21 = zext i16 %20 to i32
%22 = shl i32 %21, 1
%23 = trunc i32 %22 to i16
store i16 %23, i16* %2
%24 = load i8, i8* %5
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [18 x i8], [18 x i8]* @binarystr.buffer, i64 0, i64 %26
store i8 %24, i8* %27
br label %28
28: ; preds = %11
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %8
31: ; preds = %8
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [18 x i8], [18 x i8]* @binarystr.buffer, i64 0, i64 %33
store i8 98, i8* %34
ret i8* getelementptr inbounds ([18 x i8], [18 x i8]* @binarystr.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@binarystr.buffer = internal global [18 x i8] zeroinitializer
@SHRT_MIN = global i32 0
define i8* @binarystr(i16 zeroext %0) {
%2 = tail call i32 @memset(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @binarystr.buffer, i64 0, i64 0), i32 0, i32 18)
%3 = load i32, i32* @SHRT_MIN
%4 = shl i16 %0, 1
%5 = insertelement <2 x i16> poison, i16 %0, i64 0
%6 = shufflevector <2 x i16> %5, <2 x i16> poison, <2 x i32> zeroinitializer
%7 = shl <2 x i16> %6, <i16 2, i16 3>
%8 = insertelement <4 x i16> poison, i16 %0, i64 0
%9 = shufflevector <4 x i16> %8, <4 x i16> poison, <4 x i32> zeroinitializer
%10 = shl <4 x i16> %9, <i16 4, i16 5, i16 6, i16 7>
%11 = insertelement <8 x i16> poison, i16 %0, i64 0
%12 = shufflevector <8 x i16> %11, <8 x i16> poison, <8 x i32> zeroinitializer
%13 = shl <8 x i16> %12, <i16 8, i16 9, i16 10, i16 11, i16 12, i16 13, i16 14, i16 15>
%14 = insertelement <16 x i16> poison, i16 %0, i64 0
%15 = insertelement <16 x i16> %14, i16 %4, i64 1
%16 = shufflevector <2 x i16> %7, <2 x i16> poison, <16 x i32> <i32 0, i32 1, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
%17 = shufflevector <16 x i16> %15, <16 x i16> %16, <16 x i32> <i32 0, i32 1, i32 16, i32 17, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
%18 = shufflevector <4 x i16> %10, <4 x i16> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
%19 = shufflevector <16 x i16> %17, <16 x i16> %18, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 16, i32 17, i32 18, i32 19, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
%20 = shufflevector <8 x i16> %13, <8 x i16> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
%21 = shufflevector <16 x i16> %19, <16 x i16> %20, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23>
%22 = zext <16 x i16> %21 to <16 x i32>
%23 = insertelement <16 x i32> poison, i32 %3, i64 0
%24 = shufflevector <16 x i32> %23, <16 x i32> poison, <16 x i32> zeroinitializer
%25 = and <16 x i32> %24, %22
%26 = icmp eq <16 x i32> %25, zeroinitializer
%27 = select <16 x i1> %26, <16 x i8> <i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48>, <16 x i8> <i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49>
store <16 x i8> %27, <16 x i8>* bitcast ([18 x i8]* @binarystr.buffer to <16 x i8>*)
store i8 98, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @binarystr.buffer, i64 0, i64 16)
ret i8* getelementptr inbounds ([18 x i8], [18 x i8]* @binarystr.buffer, i64 0, i64 0)
}