char *binaryString(char value) {
  static char bits[9];
  int i;
  for (i = 0; i < 8; i++) {
    bits[7 - i] = '0' + ((value >> i) & 1);
  }
  return bits;
}


x86 assembly (clang, -O0):
<binaryString>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jge    114f <binaryString+0x4f>
movsbl -0x1(%rbp),%eax
mov    -0x8(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
add    $0x30,%eax
mov    %al,%dl
mov    $0x7,%eax
sub    -0x8(%rbp),%eax
movslq %eax,%rcx
lea    0x2ee3(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1111 <binaryString+0x11>
lea    0x2ecb(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<binaryString>:
mov    %edi,%eax
and    $0x1,%al
or     $0x30,%al
mov    %al,0x2f1c(%rip)
lea    0x2f0e(%rip),%rax
mov    %edi,%ecx
shr    %cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x2f04(%rip)
mov    %edi,%ecx
shr    $0x2,%cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x2ef2(%rip)
mov    %edi,%ecx
shr    $0x3,%cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x2ee0(%rip)
mov    %edi,%ecx
shr    $0x4,%cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x2ece(%rip)
mov    %edi,%ecx
shr    $0x5,%cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x2ebc(%rip)
mov    %edi,%ecx
shr    $0x6,%cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x2eaa(%rip)
shr    $0x7,%dil
or     $0x30,%dil
mov    %dil,0x2e9a(%rip)
ret

LLVM IR (-O0):
@binaryString.bits = internal global [9 x i8] zeroinitializer
define i8* @binaryString(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
store i8 %0, i8* %2
store i32 0, i32* %3
br label %4
4: ; preds = %19, %1
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 8
br i1 %6, label %7, label %22
7: ; preds = %4
%8 = load i8, i8* %2
%9 = sext i8 %8 to i32
%10 = load i32, i32* %3
%11 = ashr i32 %9, %10
%12 = and i32 %11, 1
%13 = add nsw i32 48, %12
%14 = trunc i32 %13 to i8
%15 = load i32, i32* %3
%16 = sub nsw i32 7, %15
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [9 x i8], [9 x i8]* @binaryString.bits, i64 0, i64 %17
store i8 %14, i8* %18
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
ret i8* getelementptr inbounds ([9 x i8], [9 x i8]* @binaryString.bits, i64 0, i64 0)
}

LLVM IR (-O2):
@binaryString.bits = internal global [9 x i8] zeroinitializer
define i8* @binaryString(i8 signext %0) {
%2 = and i8 %0, 1
%3 = or i8 %2, 48
store i8 %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @binaryString.bits, i64 0, i64 7)
%4 = lshr i8 %0, 1
%5 = and i8 %4, 1
%6 = or i8 %5, 48
store i8 %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @binaryString.bits, i64 0, i64 6)
%7 = lshr i8 %0, 2
%8 = and i8 %7, 1
%9 = or i8 %8, 48
store i8 %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @binaryString.bits, i64 0, i64 5)
%10 = lshr i8 %0, 3
%11 = and i8 %10, 1
%12 = or i8 %11, 48
store i8 %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @binaryString.bits, i64 0, i64 4)
%13 = lshr i8 %0, 4
%14 = and i8 %13, 1
%15 = or i8 %14, 48
store i8 %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @binaryString.bits, i64 0, i64 3)
%16 = lshr i8 %0, 5
%17 = and i8 %16, 1
%18 = or i8 %17, 48
store i8 %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @binaryString.bits, i64 0, i64 2)
%19 = lshr i8 %0, 6
%20 = and i8 %19, 1
%21 = or i8 %20, 48
store i8 %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @binaryString.bits, i64 0, i64 1)
%22 = lshr i8 %0, 7
%23 = or i8 %22, 48
store i8 %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @binaryString.bits, i64 0, i64 0)
ret i8* getelementptr inbounds ([9 x i8], [9 x i8]* @binaryString.bits, i64 0, i64 0)
}