void decbin(char *s, unsigned int i) {
  int j;
  for (j = 0; j < 16; j++) {
    if (i & (1 << j)) {
      s[15 - j] = '1';
    } else {
      s[15 - j] = '0';
    }
  }
  s[16] = '\0';
}


x86 assembly (clang, -O0):
<decbin>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x10,-0x10(%rbp)
jge    1174 <decbin+0x74>
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     114e <decbin+0x4e>
mov    -0x8(%rbp),%rax
mov    $0xf,%ecx
sub    -0x10(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x31,(%rax,%rcx,1)
jmp    1161 <decbin+0x61>
mov    -0x8(%rbp),%rax
mov    $0xf,%ecx
sub    -0x10(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x30,(%rax,%rcx,1)
jmp    1166 <decbin+0x66>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1112 <decbin+0x12>
mov    -0x8(%rbp),%rax
movb   $0x0,0x10(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<decbin>:
movd   %esi,%xmm0
pshufd $0x0,%xmm0,%xmm1
movdqa 0xeef(%rip),%xmm0
pand   %xmm1,%xmm0
movdqa 0xef3(%rip),%xmm2
pand   %xmm1,%xmm2
movdqa 0xef7(%rip),%xmm3
pand   %xmm1,%xmm3
pand   0xefb(%rip),%xmm1
pxor   %xmm4,%xmm4
pcmpeqd %xmm4,%xmm1
pcmpeqd %xmm4,%xmm3
packssdw %xmm1,%xmm3
pcmpeqd %xmm4,%xmm2
pcmpeqd %xmm4,%xmm0
packssdw %xmm2,%xmm0
packsswb %xmm3,%xmm0
paddb  0xee3(%rip),%xmm0
movdqa %xmm0,%xmm1
punpcklbw %xmm4,%xmm1
pshufd $0x4e,%xmm1,%xmm1
pshuflw $0x1b,%xmm1,%xmm1
pshufhw $0x1b,%xmm1,%xmm1
punpckhbw %xmm4,%xmm0
pshufd $0x4e,%xmm0,%xmm0
pshuflw $0x1b,%xmm0,%xmm0
pshufhw $0x1b,%xmm0,%xmm0
packuswb %xmm1,%xmm0
movdqu %xmm0,(%rdi)
movb   $0x0,0x10(%rdi)
ret

LLVM IR (-O0):
define void @decbin(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %28, %2
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 16
br i1 %8, label %9, label %31
9: ; preds = %6
%10 = load i32, i32* %4
%11 = load i32, i32* %5
%12 = shl i32 1, %11
%13 = and i32 %10, %12
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %9
%16 = load i8*, i8** %3
%17 = load i32, i32* %5
%18 = sub nsw i32 15, %17
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
store i8 49, i8* %20
br label %27
21: ; preds = %9
%22 = load i8*, i8** %3
%23 = load i32, i32* %5
%24 = sub nsw i32 15, %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8 48, i8* %26
br label %27
27: ; preds = %21, %15
br label %28
28: ; preds = %27
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %6
31: ; preds = %6
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i64 16
store i8 0, i8* %33
ret void
}

LLVM IR (-O2):
define void @decbin(i8* nocapture writeonly %0, i32 %1) {
%3 = insertelement <16 x i32> poison, i32 %1, i64 0
%4 = shufflevector <16 x i32> %3, <16 x i32> poison, <16 x i32> zeroinitializer
%5 = and <16 x i32> %4, <i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128, i32 256, i32 512, i32 1024, i32 2048, i32 4096, i32 8192, i32 16384, i32 32768>
%6 = icmp eq <16 x i32> %5, zeroinitializer
%7 = select <16 x i1> %6, <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>
%8 = shufflevector <16 x i8> %7, <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
%9 = bitcast i8* %0 to <16 x i8>*
store <16 x i8> %8, <16 x i8>* %9
%10 = getelementptr inbounds i8, i8* %0, i64 16
store i8 0, i8* %10
ret void
}