#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int uint8_t;

/* Variables and functions */
void binary(uint8_t value, char **result) {
  uint8_t pos = 0;
  for (int i = 7; i >= 0; i--) {
    (*result)[pos++] = (value & (1 << i)) ? '1' : '0';
  }
}


x86 assembly (clang, -O0):
<binary>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x7,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     116a <binary+0x6a>
mov    -0x4(%rbp),%edx
mov    -0x18(%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    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1119 <binary+0x19>
pop    %rbp
ret

x86 assembly (clang, -O2):
<binary>:
push   %rbx
movd   %edi,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xeee(%rip),%xmm1
pand   %xmm0,%xmm1
pand   0xef2(%rip),%xmm0
pxor   %xmm2,%xmm2
pcmpeqd %xmm2,%xmm0
pcmpeqd %xmm2,%xmm1
packssdw %xmm0,%xmm1
packsswb %xmm1,%xmm1
pmovmskb %xmm1,%edi
mov    %edi,%r11d
and    $0x2,%r11b
shr    %r11b
mov    %edi,%r8d
and    $0x4,%r8b
shr    $0x2,%r8b
mov    %edi,%r9d
and    $0x8,%r9b
shr    $0x3,%r9b
mov    %edi,%r10d
and    $0x10,%r10b
shr    $0x4,%r10b
mov    %edi,%ecx
and    $0x20,%cl
shr    $0x5,%cl
mov    %edi,%edx
and    $0x40,%dl
shr    $0x6,%dl
mov    %edi,%eax
sar    $0x7,%al
add    $0x31,%al
mov    (%rsi),%rbx
mov    %al,(%rbx)
xor    $0x31,%dl
mov    (%rsi),%rax
mov    %dl,0x1(%rax)
xor    $0x31,%cl
mov    (%rsi),%rax
mov    %cl,0x2(%rax)
xor    $0x31,%r10b
mov    (%rsi),%rax
mov    %r10b,0x3(%rax)
xor    $0x31,%r9b
mov    (%rsi),%rax
mov    %r9b,0x4(%rax)
xor    $0x31,%r8b
mov    (%rsi),%rax
mov    %r8b,0x5(%rax)
xor    $0x31,%r11b
mov    (%rsi),%rax
mov    %r11b,0x6(%rax)
and    $0x1,%dil
xor    $0x31,%dil
mov    (%rsi),%rax
mov    %dil,0x7(%rax)
pop    %rbx
ret

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

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