#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 */
int /*<<< orphan*/ ENOMEM;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *malloc(int);
char *byte_to_binary(uint8_t u8) {
  char *to_return = malloc(9);
  if (NULL == to_return)
    exit(-ENOMEM);
  uint8_t mask = 0x80;
  for (int pos = 0; pos < 8; pos++) {
    to_return[pos] = ((u8 & mask) == mask) ? '1' : '0';
    mask = mask >> 1;
  }
  to_return[8] = '\0';
  return to_return;
}


x86 assembly (clang, -O0):
<byte_to_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x9,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1155 <byte_to_binary+0x35>
xor    %edi,%edi
mov    0x2e92(%rip),%rax
sub    (%rax),%edi
call   1040 <exit@plt>
movl   $0x80,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x8,-0x18(%rbp)
jge    11a9 <byte_to_binary+0x89>
mov    -0x4(%rbp),%edx
and    -0x14(%rbp),%edx
mov    -0x14(%rbp),%esi
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1163 <byte_to_binary+0x43>
mov    -0x10(%rbp),%rax
movb   $0x0,0x8(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<byte_to_binary>:
push   %rbx
mov    %edi,%ebx
mov    $0x9,%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     11ed <byte_to_binary+0xcd>
movd   %ebx,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xeb9(%rip),%xmm1
pand   %xmm0,%xmm1
pand   0xebd(%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)
movb   $0x0,0x8(%rax)
pop    %rbx
ret
mov    0x2dec(%rip),%rax
xor    %edi,%edi
sub    (%rax),%edi
call   1040 <exit@plt>

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

LLVM IR (-O2):
@ENOMEM = global i32 0
define noalias i8* @byte_to_binary(i32 %0) {
%2 = tail call dereferenceable_or_null(9) i8* @malloc(i32 9)
%3 = icmp eq i8* %2, null
br i1 %3, label %33, label %4
4: ; preds = %1
%5 = insertelement <8 x i32> poison, i32 %0, 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
%32 = getelementptr inbounds i8, i8* %2, i64 8
store i8 0, i8* %32
ret i8* %2
33: ; preds = %1
%34 = load i32, i32* @ENOMEM
%35 = sub nsw i32 0, %34
%36 = tail call i32 @exit(i32 %35)
unreachable
}