#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 *get_byte(char byte) {
  int i;
  char *buf = malloc(sizeof(char) * 8);
  for (i = 0; i < 8; i++) {
    buf[i] = byte >> (8 - 1 - i) & 0x1;
  }
  return buf;
}


x86 assembly (clang, -O0):
<get_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    $0x8,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jge    1169 <get_byte+0x59>
movsbl -0x1(%rbp),%eax
mov    $0x7,%ecx
sub    -0x8(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1133 <get_byte+0x23>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_byte>:
push   %rbx
mov    %edi,%ebx
mov    $0x8,%edi
call   1030 <malloc@plt>
mov    %ebx,%ecx
shr    $0x7,%cl
mov    %cl,(%rax)
mov    %ebx,%ecx
shr    $0x6,%cl
and    $0x1,%cl
mov    %cl,0x1(%rax)
mov    %ebx,%ecx
shr    $0x5,%cl
and    $0x1,%cl
mov    %cl,0x2(%rax)
mov    %ebx,%ecx
shr    $0x4,%cl
and    $0x1,%cl
mov    %cl,0x3(%rax)
mov    %ebx,%ecx
shr    $0x3,%cl
and    $0x1,%cl
mov    %cl,0x4(%rax)
mov    %ebx,%ecx
shr    $0x2,%cl
and    $0x1,%cl
mov    %cl,0x5(%rax)
mov    %ebx,%ecx
shr    %cl
and    $0x1,%cl
mov    %cl,0x6(%rax)
and    $0x1,%bl
mov    %bl,0x7(%rax)
pop    %rbx
ret

LLVM IR (-O0):
define i8* @get_byte(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i8*
store i8 %0, i8* %2
%5 = call i8* @malloc(i32 8)
store i8* %5, i8** %4
store i32 0, i32* %3
br label %6
6: ; preds = %21, %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 8
br i1 %8, label %9, label %24
9: ; preds = %6
%10 = load i8, i8* %2
%11 = sext i8 %10 to i32
%12 = load i32, i32* %3
%13 = sub nsw i32 7, %12
%14 = ashr i32 %11, %13
%15 = and i32 %14, 1
%16 = trunc i32 %15 to i8
%17 = load i8*, i8** %4
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
store i8 %16, i8* %20
br label %21
21: ; preds = %9
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %6
24: ; preds = %6
%25 = load i8*, i8** %4
ret i8* %25
}

LLVM IR (-O2):
define noalias i8* @get_byte(i8 signext %0) {
%2 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%3 = lshr i8 %0, 7
store i8 %3, i8* %2
%4 = lshr i8 %0, 6
%5 = and i8 %4, 1
%6 = getelementptr inbounds i8, i8* %2, i64 1
store i8 %5, i8* %6
%7 = lshr i8 %0, 5
%8 = and i8 %7, 1
%9 = getelementptr inbounds i8, i8* %2, i64 2
store i8 %8, i8* %9
%10 = lshr i8 %0, 4
%11 = and i8 %10, 1
%12 = getelementptr inbounds i8, i8* %2, i64 3
store i8 %11, i8* %12
%13 = lshr i8 %0, 3
%14 = and i8 %13, 1
%15 = getelementptr inbounds i8, i8* %2, i64 4
store i8 %14, i8* %15
%16 = lshr i8 %0, 2
%17 = and i8 %16, 1
%18 = getelementptr inbounds i8, i8* %2, i64 5
store i8 %17, i8* %18
%19 = lshr i8 %0, 1
%20 = and i8 %19, 1
%21 = getelementptr inbounds i8, i8* %2, i64 6
store i8 %20, i8* %21
%22 = and i8 %0, 1
%23 = getelementptr inbounds i8, i8* %2, i64 7
store i8 %22, i8* %23
ret i8* %2
}