char *binString(int n) {
  static char bin[17];
  int x;
  for (x = 0; x < 16; x++) {
    bin[x] = n & 0x8000 ? '1' : '0';
    n <<= 1;
  }
  bin[16] = '\0';
  return (bin);
}


x86 assembly (clang, -O0):
<binString>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x10,-0x8(%rbp)
jge    1158 <binString+0x58>
mov    -0x4(%rbp),%edx
and    $0x8000,%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%dl
movslq -0x8(%rbp),%rcx
lea    0x2ef2(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    110e <binString+0xe>
movb   $0x0,0x2ee1(%rip)
lea    0x2eca(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<binString>:
movd   %edi,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xeef(%rip),%xmm1
pand   %xmm0,%xmm1
movdqa 0xef3(%rip),%xmm2
pand   %xmm0,%xmm2
movdqa 0xef7(%rip),%xmm3
pand   %xmm0,%xmm3
pand   0xefb(%rip),%xmm0
pxor   %xmm4,%xmm4
pcmpeqd %xmm4,%xmm0
pcmpeqd %xmm4,%xmm3
packssdw %xmm0,%xmm3
pcmpeqd %xmm4,%xmm2
pcmpeqd %xmm4,%xmm1
packssdw %xmm2,%xmm1
packsswb %xmm3,%xmm1
paddb  0xee3(%rip),%xmm1
movdqa %xmm1,0x2ecb(%rip)
lea    0x2ec4(%rip),%rax
movb   $0x0,0x2ecd(%rip)
ret

LLVM IR (-O0):
@binString.bin = internal global [17 x i8] zeroinitializer
define i8* @binString(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
br label %4
4: ; preds = %19, %1
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 16
br i1 %6, label %7, label %22
7: ; preds = %4
%8 = load i32, i32* %2
%9 = and i32 %8, 32768
%10 = icmp ne i32 %9, 0
%11 = zext i1 %10 to i64
%12 = select i1 %10, i32 49, i32 48
%13 = trunc i32 %12 to i8
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [17 x i8], [17 x i8]* @binString.bin, i64 0, i64 %15
store i8 %13, i8* %16
%17 = load i32, i32* %2
%18 = shl i32 %17, 1
store i32 %18, i32* %2
br label %19
19: ; preds = %7
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %4
22: ; preds = %4
store i8 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @binString.bin, i64 0, i64 16)
ret i8* getelementptr inbounds ([17 x i8], [17 x i8]* @binString.bin, i64 0, i64 0)
}

LLVM IR (-O2):
@binString.bin = internal global [17 x i8] zeroinitializer
define i8* @binString(i32 %0) {
%2 = insertelement <16 x i32> poison, i32 %0, i64 0
%3 = shufflevector <16 x i32> %2, <16 x i32> poison, <16 x i32> zeroinitializer
%4 = and <16 x i32> %3, <i32 32768, i32 16384, i32 8192, i32 4096, i32 2048, i32 1024, i32 512, i32 256, i32 128, i32 64, i32 32, i32 16, i32 8, i32 4, i32 2, i32 1>
%5 = icmp eq <16 x i32> %4, zeroinitializer
%6 = select <16 x i1> %5, <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> %6, <16 x i8>* bitcast ([17 x i8]* @binString.bin to <16 x i8>*)
store i8 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @binString.bin, i64 0, i64 16)
ret i8* getelementptr inbounds ([17 x i8], [17 x i8]* @binString.bin, i64 0, i64 0)
}