#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 *convertByteToBin(unsigned char byte) {
  int n = 0;
  char *result = malloc((8 + 1) * sizeof(char));
  for (n = 0; n < 8; n++) {
    if ((byte & 0x80) != 0) {
      result[n] = '1';
    } else {
      result[n] = '0';
    }
    byte = byte << 1;
  }
  result[8] = '\0';
  return (result);
}


x86 assembly (clang, -O0):
<convertByteToBin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x9,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jge    118b <convertByteToBin+0x7b>
movzbl -0x1(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     1167 <convertByteToBin+0x57>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movb   $0x31,(%rax,%rcx,1)
jmp    1173 <convertByteToBin+0x63>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movb   $0x30,(%rax,%rcx,1)
movzbl -0x1(%rbp),%eax
shl    $0x1,%eax
mov    %al,-0x1(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    113a <convertByteToBin+0x2a>
mov    -0x10(%rbp),%rax
movb   $0x0,0x8(%rax)
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convertByteToBin>:
push   %rbx
mov    %edi,%ebx
mov    $0x9,%edi
call   1030 <malloc@plt>
mov    %ebx,%ecx
shr    $0x7,%cl
or     $0x30,%cl
mov    %cl,(%rax)
mov    %ebx,%ecx
and    $0x40,%cl
cmp    $0x1,%cl
mov    $0x31,%cl
mov    $0x31,%dl
sbb    $0x0,%dl
mov    %dl,0x1(%rax)
mov    %ebx,%edx
and    $0x20,%dl
cmp    $0x1,%dl
mov    $0x31,%dl
sbb    $0x0,%dl
mov    %dl,0x2(%rax)
mov    %ebx,%edx
and    $0x10,%dl
cmp    $0x1,%dl
mov    $0x31,%dl
sbb    $0x0,%dl
mov    %dl,0x3(%rax)
mov    %ebx,%edx
and    $0x8,%dl
cmp    $0x1,%dl
mov    $0x31,%dl
sbb    $0x0,%dl
mov    %dl,0x4(%rax)
mov    %ebx,%edx
and    $0x4,%dl
cmp    $0x1,%dl
mov    $0x31,%dl
sbb    $0x0,%dl
mov    %dl,0x5(%rax)
mov    %ebx,%edx
and    $0x2,%dl
cmp    $0x1,%dl
sbb    $0x0,%cl
mov    %cl,0x6(%rax)
and    $0x1,%bl
or     $0x30,%bl
mov    %bl,0x7(%rax)
movb   $0x0,0x8(%rax)
pop    %rbx
ret

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

LLVM IR (-O2):
define noalias i8* @convertByteToBin(i8 zeroext %0) {
%2 = tail call dereferenceable_or_null(9) i8* @malloc(i32 9)
%3 = icmp sgt i8 %0, -1
%4 = select i1 %3, i8 48, i8 49
store i8 %4, i8* %2
%5 = and i8 %0, 64
%6 = icmp eq i8 %5, 0
%7 = select i1 %6, i8 48, i8 49
%8 = getelementptr inbounds i8, i8* %2, i64 1
store i8 %7, i8* %8
%9 = and i8 %0, 32
%10 = icmp eq i8 %9, 0
%11 = select i1 %10, i8 48, i8 49
%12 = getelementptr inbounds i8, i8* %2, i64 2
store i8 %11, i8* %12
%13 = and i8 %0, 16
%14 = icmp eq i8 %13, 0
%15 = select i1 %14, i8 48, i8 49
%16 = getelementptr inbounds i8, i8* %2, i64 3
store i8 %15, i8* %16
%17 = and i8 %0, 8
%18 = icmp eq i8 %17, 0
%19 = select i1 %18, i8 48, i8 49
%20 = getelementptr inbounds i8, i8* %2, i64 4
store i8 %19, i8* %20
%21 = and i8 %0, 4
%22 = icmp eq i8 %21, 0
%23 = select i1 %22, i8 48, i8 49
%24 = getelementptr inbounds i8, i8* %2, i64 5
store i8 %23, i8* %24
%25 = and i8 %0, 2
%26 = icmp eq i8 %25, 0
%27 = select i1 %26, i8 48, i8 49
%28 = getelementptr inbounds i8, i8* %2, i64 6
store i8 %27, i8* %28
%29 = and i8 %0, 1
%30 = or i8 %29, 48
%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
}