#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 */

/* Variables and functions */
char *malloc(int);
char *blackstrap_stringify_uchar_bin(unsigned char value) {
  char *string = malloc(9);
  string[8] = 0;
  for (int i = 7; i >= 0; i--)
    string[7 - i] = (value & (1 << i)) ? '1' : '0';
  return string;
}


x86 assembly (clang, -O0):
<blackstrap_stringify_uchar_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    $0x9,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,0x8(%rax)
movl   $0x7,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1187 <blackstrap_stringify_uchar_bin+0x77>
movzbl -0x1(%rbp),%edx
mov    -0x14(%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    $0x7,%ecx
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    113b <blackstrap_stringify_uchar_bin+0x2b>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blackstrap_stringify_uchar_bin>:
push   %rbx
mov    %edi,%ebx
mov    $0x9,%edi
call   1030 <malloc@plt>
movb   $0x0,0x8(%rax)
movd   %ebx,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xece(%rip),%xmm1
pand   %xmm0,%xmm1
pand   0xed2(%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,%ebx
and    $0x40,%bl
shr    $0x6,%bl
mov    %esi,%ecx
sar    $0x7,%cl
add    $0x31,%cl
mov    %cl,(%rax)
xor    $0x31,%bl
mov    %bl,0x1(%rax)
xor    $0x31,%dl
mov    %dl,0x2(%rax)
xor    $0x31,%r9b
mov    %r9b,0x3(%rax)
xor    $0x31,%r8b
mov    %r8b,0x4(%rax)
xor    $0x31,%dil
mov    %dil,0x5(%rax)
xor    $0x31,%r10b
mov    %r10b,0x6(%rax)
and    $0x1,%sil
xor    $0x31,%sil
mov    %sil,0x7(%rax)
pop    %rbx
ret

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

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