void expand0(unsigned char *in, unsigned char *out) {
  int divide;
  int i, j;
  for (i = 0; i < 8; i++) {
    divide = 0x80;
    for (j = 0; j < 8; j++) {
      *out++ = (in[i] / divide) & 1;
      divide /= 2;
    }
  }
}


x86 assembly (clang, -O0):
<expand0>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x8,-0x18(%rbp)
jge    118a <expand0+0x8a>
movl   $0x80,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    1177 <expand0+0x77>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cltd
idivl  -0x14(%rbp)
and    $0x1,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112b <expand0+0x2b>
jmp    117c <expand0+0x7c>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1113 <expand0+0x13>
pop    %rbp
ret

x86 assembly (clang, -O2):
<expand0>:
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rdi,%rax,1),%ecx
shr    $0x7,%cl
mov    %cl,(%rsi,%rax,8)
movzbl (%rdi,%rax,1),%ecx
shr    $0x6,%cl
and    $0x1,%cl
mov    %cl,0x1(%rsi,%rax,8)
movzbl (%rdi,%rax,1),%ecx
shr    $0x5,%cl
and    $0x1,%cl
mov    %cl,0x2(%rsi,%rax,8)
movzbl (%rdi,%rax,1),%ecx
shr    $0x4,%cl
and    $0x1,%cl
mov    %cl,0x3(%rsi,%rax,8)
movzbl (%rdi,%rax,1),%ecx
shr    $0x3,%cl
and    $0x1,%cl
mov    %cl,0x4(%rsi,%rax,8)
movzbl (%rdi,%rax,1),%ecx
shr    $0x2,%cl
and    $0x1,%cl
mov    %cl,0x5(%rsi,%rax,8)
movzbl (%rdi,%rax,1),%ecx
shr    %cl
and    $0x1,%cl
mov    %cl,0x6(%rsi,%rax,8)
movzbl (%rdi,%rax,1),%ecx
and    $0x1,%cl
mov    %cl,0x7(%rsi,%rax,8)
add    $0x1,%rax
cmp    $0x8,%rax
jne    1110 <expand0+0x10>
ret

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

LLVM IR (-O2):
define void @expand0(i8* nocapture %0, i8* nocapture writeonly %1) {
br label %3
3: ; preds = %2, %3
%4 = phi i64 [ 0, %2 ], [ %37, %3 ]
%5 = phi i8* [ %1, %2 ], [ %36, %3 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %4
%7 = load i8, i8* %6
%8 = lshr i8 %7, 7
%9 = getelementptr inbounds i8, i8* %5, i64 1
store i8 %8, i8* %5
%10 = load i8, i8* %6
%11 = lshr i8 %10, 6
%12 = and i8 %11, 1
%13 = getelementptr inbounds i8, i8* %5, i64 2
store i8 %12, i8* %9
%14 = load i8, i8* %6
%15 = lshr i8 %14, 5
%16 = and i8 %15, 1
%17 = getelementptr inbounds i8, i8* %5, i64 3
store i8 %16, i8* %13
%18 = load i8, i8* %6
%19 = lshr i8 %18, 4
%20 = and i8 %19, 1
%21 = getelementptr inbounds i8, i8* %5, i64 4
store i8 %20, i8* %17
%22 = load i8, i8* %6
%23 = lshr i8 %22, 3
%24 = and i8 %23, 1
%25 = getelementptr inbounds i8, i8* %5, i64 5
store i8 %24, i8* %21
%26 = load i8, i8* %6
%27 = lshr i8 %26, 2
%28 = and i8 %27, 1
%29 = getelementptr inbounds i8, i8* %5, i64 6
store i8 %28, i8* %25
%30 = load i8, i8* %6
%31 = lshr i8 %30, 1
%32 = and i8 %31, 1
%33 = getelementptr inbounds i8, i8* %5, i64 7
store i8 %32, i8* %29
%34 = load i8, i8* %6
%35 = and i8 %34, 1
%36 = getelementptr inbounds i8, i8* %5, i64 8
store i8 %35, i8* %33
%37 = add nuw nsw i64 %4, 1
%38 = icmp eq i64 %37, 8
br i1 %38, label %39, label %3
39: ; preds = %3
ret void
}