void _UnpackFont8_1bpp(unsigned int *fontDst, const unsigned char *fontSrc,
                       unsigned int foreColor, unsigned int backColor) {
  int i, j;
  for (j = 0; j < 8 * 16 * 16; j++) {
    unsigned int data = *fontSrc++;
    for (i = 0; i < 8; i++)
      *fontDst++ = data & 1 << (7 - i) ? foreColor : backColor;
  }
}


x86 assembly (clang, -O0):
<_UnpackFont8_1bpp>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x800,-0x20(%rbp)
jge    11b1 <_UnpackFont8_1bpp+0xb1>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    119e <_UnpackFont8_1bpp+0x9e>
mov    -0x24(%rbp),%eax
mov    $0x7,%ecx
sub    -0x1c(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1176 <_UnpackFont8_1bpp+0x76>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    117c <_UnpackFont8_1bpp+0x7c>
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x8(%rbp)
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1142 <_UnpackFont8_1bpp+0x42>
jmp    11a3 <_UnpackFont8_1bpp+0xa3>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1119 <_UnpackFont8_1bpp+0x19>
pop    %rbp
ret

x86 assembly (clang, -O2):
<_UnpackFont8_1bpp>:
movd   %ecx,%xmm0
pshufd $0x0,%xmm0,%xmm0
movd   %edx,%xmm1
pshufd $0x0,%xmm1,%xmm1
xor    %eax,%eax
movdqa 0xee4(%rip),%xmm2
pxor   %xmm3,%xmm3
movdqa 0xee8(%rip),%xmm4
nopl   0x0(%rax,%rax,1)
movzbl (%rsi,%rax,1),%ecx
movd   %ecx,%xmm5
pshufd $0x0,%xmm5,%xmm5
movdqa %xmm5,%xmm6
pand   %xmm2,%xmm6
pcmpeqd %xmm3,%xmm6
movdqa %xmm0,%xmm7
pand   %xmm6,%xmm7
pandn  %xmm1,%xmm6
por    %xmm7,%xmm6
movdqu %xmm6,(%rdi)
pand   %xmm4,%xmm5
pcmpeqd %xmm3,%xmm5
movdqa %xmm0,%xmm6
pand   %xmm5,%xmm6
pandn  %xmm1,%xmm5
por    %xmm6,%xmm5
movdqu %xmm5,0x10(%rdi)
add    $0x1,%rax
add    $0x20,%rdi
cmp    $0x800,%eax
jne    1130 <_UnpackFont8_1bpp+0x30>
ret

LLVM IR (-O0):
define void @_UnpackFont8_1bpp(i32* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %10
br label %12
12: ; preds = %42, %4
%13 = load i32, i32* %10
%14 = icmp slt i32 %13, 2048
br i1 %14, label %15, label %45
15: ; preds = %12
%16 = load i8*, i8** %6
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %6
%18 = load i8, i8* %16
%19 = zext i8 %18 to i32
store i32 %19, i32* %11
store i32 0, i32* %9
br label %20
20: ; preds = %38, %15
%21 = load i32, i32* %9
%22 = icmp slt i32 %21, 8
br i1 %22, label %23, label %41
23: ; preds = %20
%24 = load i32, i32* %11
%25 = load i32, i32* %9
%26 = sub nsw i32 7, %25
%27 = shl i32 1, %26
%28 = and i32 %24, %27
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %23
%31 = load i32, i32* %7
br label %34
32: ; preds = %23
%33 = load i32, i32* %8
br label %34
34: ; preds = %32, %30
%35 = phi i32 [ %31, %30 ], [ %33, %32 ]
%36 = load i32*, i32** %5
%37 = getelementptr inbounds i32, i32* %36, i32 1
store i32* %37, i32** %5
store i32 %35, i32* %36
br label %38
38: ; preds = %34
%39 = load i32, i32* %9
%40 = add nsw i32 %39, 1
store i32 %40, i32* %9
br label %20
41: ; preds = %20
br label %42
42: ; preds = %41
%43 = load i32, i32* %10
%44 = add nsw i32 %43, 1
store i32 %44, i32* %10
br label %12
45: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @_UnpackFont8_1bpp(i32* nocapture writeonly %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = insertelement <4 x i32> poison, i32 %3, i64 0
%6 = shufflevector <4 x i32> %5, <4 x i32> poison, <4 x i32> zeroinitializer
%7 = insertelement <4 x i32> poison, i32 %2, i64 0
%8 = shufflevector <4 x i32> %7, <4 x i32> poison, <4 x i32> zeroinitializer
%9 = insertelement <4 x i32> poison, i32 %3, i64 0
%10 = shufflevector <4 x i32> %9, <4 x i32> poison, <4 x i32> zeroinitializer
%11 = insertelement <4 x i32> poison, i32 %2, i64 0
%12 = shufflevector <4 x i32> %11, <4 x i32> poison, <4 x i32> zeroinitializer
br label %13
13: ; preds = %4, %13
%14 = phi i32* [ %0, %4 ], [ %29, %13 ]
%15 = phi i32 [ 0, %4 ], [ %32, %13 ]
%16 = phi i8* [ %1, %4 ], [ %31, %13 ]
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = insertelement <4 x i32> poison, i32 %18, i64 0
%20 = shufflevector <4 x i32> %19, <4 x i32> poison, <4 x i32> zeroinitializer
%21 = and <4 x i32> %20, <i32 128, i32 64, i32 32, i32 16>
%22 = icmp eq <4 x i32> %21, zeroinitializer
%23 = select <4 x i1> %22, <4 x i32> %6, <4 x i32> %8
%24 = getelementptr inbounds i32, i32* %14, i64 4
%25 = bitcast i32* %14 to <4 x i32>*
store <4 x i32> %23, <4 x i32>* %25
%26 = and <4 x i32> %20, <i32 8, i32 4, i32 2, i32 1>
%27 = icmp eq <4 x i32> %26, zeroinitializer
%28 = select <4 x i1> %27, <4 x i32> %10, <4 x i32> %12
%29 = getelementptr inbounds i32, i32* %14, i64 8
%30 = bitcast i32* %24 to <4 x i32>*
store <4 x i32> %28, <4 x i32>* %30
%31 = getelementptr inbounds i8, i8* %16, i64 1
%32 = add nuw nsw i32 %15, 1
%33 = icmp eq i32 %32, 2048
br i1 %33, label %34, label %13
34: ; preds = %13
ret void
}