void gt_byte2string(char *buffer, unsigned char bs) {
  unsigned int i;
  unsigned char mask;
  for (i = 0, mask = (unsigned char)128; i < 8U; i++, mask >>= 1) {
    buffer[i] = (bs & mask) ? '1' : '0';
  }
  buffer[8] = '\0';
}


x86 assembly (clang, -O0):
<gt_byte2string>:
push   %rbp
mov    %rsp,%rbp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0x0,-0x10(%rbp)
movb   $0x80,-0x11(%rbp)
cmpl   $0x8,-0x10(%rbp)
jae    1161 <gt_byte2string+0x61>
movzbl -0x9(%rbp),%edx
movzbl -0x11(%rbp),%eax
and    %eax,%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
movzbl -0x11(%rbp),%eax
sar    $0x1,%eax
mov    %al,-0x11(%rbp)
jmp    1119 <gt_byte2string+0x19>
mov    -0x8(%rbp),%rax
movb   $0x0,0x8(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<gt_byte2string>:
movd   %esi,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xeef(%rip),%xmm1
pand   %xmm0,%xmm1
pand   0xef3(%rip),%xmm0
pxor   %xmm2,%xmm2
pcmpeqd %xmm2,%xmm0
pcmpeqd %xmm2,%xmm1
packssdw %xmm0,%xmm1
packsswb %xmm1,%xmm1
pmovmskb %xmm1,%esi
mov    %esi,%r11d
and    $0x2,%r11b
shr    %r11b
mov    %esi,%r8d
and    $0x4,%r8b
shr    $0x2,%r8b
mov    %esi,%r9d
and    $0x8,%r9b
shr    $0x3,%r9b
mov    %esi,%r10d
and    $0x10,%r10b
shr    $0x4,%r10b
mov    %esi,%ecx
and    $0x20,%cl
shr    $0x5,%cl
mov    %esi,%edx
and    $0x40,%dl
shr    $0x6,%dl
mov    %esi,%eax
sar    $0x7,%al
add    $0x31,%al
mov    %al,(%rdi)
xor    $0x31,%dl
mov    %dl,0x1(%rdi)
xor    $0x31,%cl
mov    %cl,0x2(%rdi)
xor    $0x31,%r10b
mov    %r10b,0x3(%rdi)
xor    $0x31,%r9b
mov    %r9b,0x4(%rdi)
xor    $0x31,%r8b
mov    %r8b,0x5(%rdi)
xor    $0x31,%r11b
mov    %r11b,0x6(%rdi)
and    $0x1,%sil
xor    $0x31,%sil
mov    %sil,0x7(%rdi)
movb   $0x0,0x8(%rdi)
ret

LLVM IR (-O0):
define void @gt_byte2string(i8* %0, i8 zeroext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = alloca i8
store i8* %0, i8** %3
store i8 %1, i8* %4
store i32 0, i32* %5
store i8 -128, i8* %6
br label %7
7: ; preds = %24, %2
%8 = load i32, i32* %5
%9 = icmp ult i32 %8, 8
br i1 %9, label %10, label %31
10: ; preds = %7
%11 = load i8, i8* %4
%12 = zext i8 %11 to i32
%13 = load i8, i8* %6
%14 = zext i8 %13 to i32
%15 = and i32 %12, %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
%20 = load i8*, i8** %3
%21 = load i32, i32* %5
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 %19, i8* %23
br label %24
24: ; preds = %10
%25 = load i32, i32* %5
%26 = add i32 %25, 1
store i32 %26, i32* %5
%27 = load i8, i8* %6
%28 = zext i8 %27 to i32
%29 = ashr i32 %28, 1
%30 = trunc i32 %29 to i8
store i8 %30, i8* %6
br label %7
31: ; preds = %7
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i64 8
store i8 0, i8* %33
ret void
}

LLVM IR (-O2):
define void @gt_byte2string(i8* nocapture writeonly %0, i8 zeroext %1) {
%3 = zext i8 %1 to i32
%4 = insertelement <8 x i32> poison, i32 %3, i64 0
%5 = shufflevector <8 x i32> %4, <8 x i32> poison, <8 x i32> zeroinitializer
%6 = and <8 x i32> %5, <i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128>
%7 = icmp eq <8 x i32> %6, zeroinitializer
%8 = extractelement <8 x i1> %7, i64 7
%9 = select i1 %8, i8 48, i8 49
store i8 %9, i8* %0
%10 = extractelement <8 x i1> %7, i64 6
%11 = select i1 %10, i8 48, i8 49
%12 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %11, i8* %12
%13 = extractelement <8 x i1> %7, i64 5
%14 = select i1 %13, i8 48, i8 49
%15 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %14, i8* %15
%16 = extractelement <8 x i1> %7, i64 4
%17 = select i1 %16, i8 48, i8 49
%18 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %17, i8* %18
%19 = extractelement <8 x i1> %7, i64 3
%20 = select i1 %19, i8 48, i8 49
%21 = getelementptr inbounds i8, i8* %0, i64 4
store i8 %20, i8* %21
%22 = extractelement <8 x i1> %7, i64 2
%23 = select i1 %22, i8 48, i8 49
%24 = getelementptr inbounds i8, i8* %0, i64 5
store i8 %23, i8* %24
%25 = extractelement <8 x i1> %7, i64 1
%26 = select i1 %25, i8 48, i8 49
%27 = getelementptr inbounds i8, i8* %0, i64 6
store i8 %26, i8* %27
%28 = extractelement <8 x i1> %7, i64 0
%29 = select i1 %28, i8 48, i8 49
%30 = getelementptr inbounds i8, i8* %0, i64 7
store i8 %29, i8* %30
%31 = getelementptr inbounds i8, i8* %0, i64 8
store i8 0, i8* %31
ret void
}