const char *byte_to_binary(int x) {
  static char b[9];
  int pos;
  for (pos = 0; pos < 8; pos++)
    b[7 - pos] = (x & (1 << pos)) ? '1' : '0';
  b[8] = '\0';
  return b;
}


x86 assembly (clang, -O0):
<byte_to_binary>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jge    115c <byte_to_binary+0x5c>
mov    -0x4(%rbp),%edx
mov    -0x8(%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
mov    $0x7,%eax
sub    -0x8(%rbp),%eax
movslq %eax,%rcx
lea    0x2ed6(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    110e <byte_to_binary+0xe>
movb   $0x0,0x2ec6(%rip)
lea    0x2eb7(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<byte_to_binary>:
movd   %edi,%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,%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,%edx
and    $0x20,%dl
shr    $0x5,%dl
mov    %esi,%ecx
and    $0x40,%cl
shr    $0x6,%cl
mov    %esi,%eax
sar    $0x7,%al
add    $0x31,%al
mov    %al,0x2eac(%rip)
lea    0x2e9e(%rip),%rax
xor    $0x31,%cl
mov    %cl,0x2e9b(%rip)
xor    $0x31,%dl
mov    %dl,0x2e91(%rip)
xor    $0x31,%r9b
mov    %r9b,0x2e85(%rip)
xor    $0x31,%r8b
mov    %r8b,0x2e79(%rip)
xor    $0x31,%dil
mov    %dil,0x2e6d(%rip)
xor    $0x31,%r10b
mov    %r10b,0x2e61(%rip)
and    $0x1,%sil
xor    $0x31,%sil
mov    %sil,0x2e51(%rip)
movb   $0x0,0x2e52(%rip)
ret

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

LLVM IR (-O2):
@byte_to_binary.b = internal global [9 x i8] zeroinitializer
define i8* @byte_to_binary(i32 %0) {
%2 = insertelement <8 x i32> poison, i32 %0, i64 0
%3 = shufflevector <8 x i32> %2, <8 x i32> poison, <8 x i32> zeroinitializer
%4 = and <8 x i32> %3, <i32 128, i32 64, i32 32, i32 16, i32 8, i32 4, i32 2, i32 1>
%5 = icmp eq <8 x i32> %4, zeroinitializer
%6 = extractelement <8 x i1> %5, i64 7
%7 = select i1 %6, i8 48, i8 49
store i8 %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @byte_to_binary.b, i64 0, i64 7)
%8 = extractelement <8 x i1> %5, i64 6
%9 = select i1 %8, i8 48, i8 49
store i8 %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @byte_to_binary.b, i64 0, i64 6)
%10 = extractelement <8 x i1> %5, i64 5
%11 = select i1 %10, i8 48, i8 49
store i8 %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @byte_to_binary.b, i64 0, i64 5)
%12 = extractelement <8 x i1> %5, i64 4
%13 = select i1 %12, i8 48, i8 49
store i8 %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @byte_to_binary.b, i64 0, i64 4)
%14 = extractelement <8 x i1> %5, i64 3
%15 = select i1 %14, i8 48, i8 49
store i8 %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @byte_to_binary.b, i64 0, i64 3)
%16 = extractelement <8 x i1> %5, i64 2
%17 = select i1 %16, i8 48, i8 49
store i8 %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @byte_to_binary.b, i64 0, i64 2)
%18 = extractelement <8 x i1> %5, i64 1
%19 = select i1 %18, i8 48, i8 49
store i8 %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @byte_to_binary.b, i64 0, i64 1)
%20 = extractelement <8 x i1> %5, i64 0
%21 = select i1 %20, i8 48, i8 49
store i8 %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @byte_to_binary.b, i64 0, i64 0)
store i8 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @byte_to_binary.b, i64 0, i64 8)
ret i8* getelementptr inbounds ([9 x i8], [9 x i8]* @byte_to_binary.b, i64 0, i64 0)
}