unsigned char *bit_representation(unsigned char value, unsigned char *result) {
  for (int i = 7; i >= 0; i--) {
    result[i] = (value % 2) ? '1' : '0';
    value /= 2;
  }
  result[8] = '\0';
  return result;
}


x86 assembly (clang, -O0):
<bit_representation>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x7,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1165 <bit_representation+0x65>
movzbl -0x1(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movzbl -0x1(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %al,-0x1(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1115 <bit_representation+0x15>
mov    -0x10(%rbp),%rax
movb   $0x0,0x8(%rax)
mov    -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<bit_representation>:
mov    %rsi,%rax
mov    %edi,%ecx
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x7(%rsi)
mov    %edi,%ecx
shr    %cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x6(%rsi)
mov    %edi,%ecx
shr    $0x2,%cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x5(%rsi)
mov    %edi,%ecx
shr    $0x3,%cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x4(%rsi)
mov    %edi,%ecx
shr    $0x4,%cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x3(%rsi)
mov    %edi,%ecx
shr    $0x5,%cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x2(%rsi)
mov    %edi,%ecx
shr    $0x6,%cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x1(%rsi)
shr    $0x7,%dil
or     $0x30,%dil
mov    %dil,(%rsi)
movb   $0x0,0x8(%rsi)
ret

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

LLVM IR (-O2):
define i8* @bit_representation(i8 zeroext %0, i8* returned writeonly %1) {
%3 = and i8 %0, 1
%4 = or i8 %3, 48
%5 = getelementptr inbounds i8, i8* %1, i64 7
store i8 %4, i8* %5
%6 = lshr i8 %0, 1
%7 = and i8 %6, 1
%8 = or i8 %7, 48
%9 = getelementptr inbounds i8, i8* %1, i64 6
store i8 %8, i8* %9
%10 = lshr i8 %0, 2
%11 = and i8 %10, 1
%12 = or i8 %11, 48
%13 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %12, i8* %13
%14 = lshr i8 %0, 3
%15 = and i8 %14, 1
%16 = or i8 %15, 48
%17 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %16, i8* %17
%18 = lshr i8 %0, 4
%19 = and i8 %18, 1
%20 = or i8 %19, 48
%21 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %20, i8* %21
%22 = lshr i8 %0, 5
%23 = and i8 %22, 1
%24 = or i8 %23, 48
%25 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %24, i8* %25
%26 = lshr i8 %0, 6
%27 = and i8 %26, 1
%28 = or i8 %27, 48
%29 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %28, i8* %29
%30 = lshr i8 %0, 7
%31 = or i8 %30, 48
store i8 %31, i8* %1
%32 = getelementptr inbounds i8, i8* %1, i64 8
store i8 0, i8* %32
ret i8* %1
}