#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 bitconvert(char *buffer, uint8_t byte) {
  uint8_t rack;
  int bitpos;
  rack = 0x80;
  bitpos = 0;
  while (rack) {
    buffer[bitpos] = byte & rack ? '1' : '0';
    rack >>= 1;
    bitpos++;
  }
  buffer[bitpos] = '\n';
  buffer[bitpos + 1] = '\0';
}


x86 assembly (clang, -O0):
<bitconvert>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x80,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     115d <bitconvert+0x5d>
mov    -0xc(%rbp),%edx
and    -0x10(%rbp),%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1119 <bitconvert+0x19>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0xa,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitconvert>:
movd   %esi,%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,%r11d
and    $0x2,%r11b
shr    %r11b
mov    %esi,%r8d
and    $0x4,%r8b
shr    $0x2,%r8b
mov    %esi,%r9d
and    $0x8,%r9b
shr    $0x3,%r9b
mov    %esi,%r10d
and    $0x10,%r10b
shr    $0x4,%r10b
mov    %esi,%ecx
and    $0x20,%cl
shr    $0x5,%cl
mov    %esi,%edx
and    $0x40,%dl
shr    $0x6,%dl
mov    %esi,%eax
sar    $0x7,%al
add    $0x31,%al
mov    %al,(%rdi)
xor    $0x31,%dl
mov    %dl,0x1(%rdi)
xor    $0x31,%cl
mov    %cl,0x2(%rdi)
xor    $0x31,%r10b
mov    %r10b,0x3(%rdi)
xor    $0x31,%r9b
mov    %r9b,0x4(%rdi)
xor    $0x31,%r8b
mov    %r8b,0x5(%rdi)
xor    $0x31,%r11b
mov    %r11b,0x6(%rdi)
and    $0x1,%sil
xor    $0x31,%sil
mov    %sil,0x7(%rdi)
movw   $0xa,0x8(%rdi)
ret

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

LLVM IR (-O2):
define void @bitconvert(i8* nocapture writeonly %0, i32 %1) {
%3 = insertelement <8 x i32> poison, i32 %1, 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
store i8 %8, i8* %0
%9 = extractelement <8 x i1> %6, i64 6
%10 = select i1 %9, i8 48, i8 49
%11 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %10, i8* %11
%12 = extractelement <8 x i1> %6, i64 5
%13 = select i1 %12, i8 48, i8 49
%14 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %13, i8* %14
%15 = extractelement <8 x i1> %6, i64 4
%16 = select i1 %15, i8 48, i8 49
%17 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %16, i8* %17
%18 = extractelement <8 x i1> %6, i64 3
%19 = select i1 %18, i8 48, i8 49
%20 = getelementptr inbounds i8, i8* %0, i64 4
store i8 %19, i8* %20
%21 = extractelement <8 x i1> %6, i64 2
%22 = select i1 %21, i8 48, i8 49
%23 = getelementptr inbounds i8, i8* %0, i64 5
store i8 %22, i8* %23
%24 = extractelement <8 x i1> %6, i64 1
%25 = select i1 %24, i8 48, i8 49
%26 = getelementptr inbounds i8, i8* %0, i64 6
store i8 %25, i8* %26
%27 = extractelement <8 x i1> %6, i64 0
%28 = select i1 %27, i8 48, i8 49
%29 = getelementptr inbounds i8, i8* %0, i64 7
store i8 %28, i8* %29
%30 = getelementptr inbounds i8, i8* %0, i64 8
store i8 10, i8* %30
%31 = getelementptr inbounds i8, i8* %0, i64 9
store i8 0, i8* %31
ret void
}