char *libswd_bin8_string(char *data) {
  static char string[9];
  string[8] = 0;
  unsigned char i, bits = *data;
  for (i = 0; i < 8; i++)
    string[7 - i] = (bits & (1 << i)) ? '1' : '0';
  return string;
}


x86 assembly (clang, -O0):
<libswd_bin8_string>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movb   $0x0,0x2f1a(%rip)
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0xa(%rbp)
movb   $0x0,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
cmp    $0x8,%eax
jge    1171 <libswd_bin8_string+0x71>
movzbl -0xa(%rbp),%edx
movzbl -0x9(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
and    %eax,%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%dl
movzbl -0x9(%rbp),%ecx
mov    $0x7,%eax
sub    %ecx,%eax
movslq %eax,%rcx
lea    0x2ec0(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x9(%rbp),%al
add    $0x1,%al
mov    %al,-0x9(%rbp)
jmp    111c <libswd_bin8_string+0x1c>
lea    0x2ea9(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<libswd_bin8_string>:
movb   $0x0,0x2f22(%rip)
lea    0x2f13(%rip),%rax
movzbl (%rdi),%ecx
movd   %ecx,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xede(%rip),%xmm1
pand   %xmm0,%xmm1
pand   0xee2(%rip),%xmm0
pxor   %xmm2,%xmm2
pcmpeqd %xmm2,%xmm0
pcmpeqd %xmm2,%xmm1
packssdw %xmm0,%xmm1
packsswb %xmm1,%xmm1
pmovmskb %xmm1,%esi
mov    %esi,%r10d
and    $0x2,%r10b
shr    %r10b
mov    %esi,%edi
and    $0x4,%dil
shr    $0x2,%dil
mov    %esi,%r8d
and    $0x8,%r8b
shr    $0x3,%r8b
mov    %esi,%r9d
and    $0x10,%r9b
shr    $0x4,%r9b
mov    %esi,%r11d
and    $0x20,%r11b
shr    $0x5,%r11b
mov    %esi,%ecx
and    $0x40,%cl
shr    $0x6,%cl
mov    %esi,%edx
sar    $0x7,%dl
add    $0x31,%dl
mov    %dl,0x2e97(%rip)
xor    $0x31,%cl
mov    %cl,0x2e8d(%rip)
xor    $0x31,%r11b
mov    %r11b,0x2e81(%rip)
xor    $0x31,%r9b
mov    %r9b,0x2e75(%rip)
xor    $0x31,%r8b
mov    %r8b,0x2e69(%rip)
xor    $0x31,%dil
mov    %dil,0x2e5d(%rip)
xor    $0x31,%r10b
mov    %r10b,0x2e51(%rip)
and    $0x1,%sil
xor    $0x31,%sil
mov    %sil,0x2e41(%rip)
ret

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

LLVM IR (-O2):
@libswd_bin8_string.string = internal global [9 x i8] zeroinitializer
define i8* @libswd_bin8_string(i8* nocapture %0) {
store i8 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @libswd_bin8_string.string, i64 0, i64 8)
%2 = load i8, i8* %0
%3 = zext i8 %2 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 128, i32 64, i32 32, i32 16, i32 8, i32 4, i32 2, i32 1>
%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* getelementptr inbounds ([9 x i8], [9 x i8]* @libswd_bin8_string.string, i64 0, i64 7)
%10 = extractelement <8 x i1> %7, i64 6
%11 = select i1 %10, i8 48, i8 49
store i8 %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @libswd_bin8_string.string, i64 0, i64 6)
%12 = extractelement <8 x i1> %7, i64 5
%13 = select i1 %12, i8 48, i8 49
store i8 %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @libswd_bin8_string.string, i64 0, i64 5)
%14 = extractelement <8 x i1> %7, i64 4
%15 = select i1 %14, i8 48, i8 49
store i8 %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @libswd_bin8_string.string, i64 0, i64 4)
%16 = extractelement <8 x i1> %7, i64 3
%17 = select i1 %16, i8 48, i8 49
store i8 %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @libswd_bin8_string.string, i64 0, i64 3)
%18 = extractelement <8 x i1> %7, i64 2
%19 = select i1 %18, i8 48, i8 49
store i8 %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @libswd_bin8_string.string, i64 0, i64 2)
%20 = extractelement <8 x i1> %7, i64 1
%21 = select i1 %20, i8 48, i8 49
store i8 %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @libswd_bin8_string.string, i64 0, i64 1)
%22 = extractelement <8 x i1> %7, i64 0
%23 = select i1 %22, i8 48, i8 49
store i8 %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @libswd_bin8_string.string, i64 0, i64 0)
ret i8* getelementptr inbounds ([9 x i8], [9 x i8]* @libswd_bin8_string.string, i64 0, i64 0)
}