void clear(unsigned int bcolor, unsigned int fcolor) {
  char *vidmem = (char *)0xb8000;
  unsigned int i = 0;
  while (i < (80 * 25 * 2)) {
    vidmem[i] = ' ';
    i++;
    vidmem[i] = fcolor + (bcolor * 16);
    i++;
  }
}


x86 assembly (clang, -O0):
<clear>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0xb8000,%eax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xfa0,-0x14(%rbp)
jae    1160 <clear+0x60>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movb   $0x20,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
shl    $0x4,%ecx
add    %ecx,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    111a <clear+0x1a>
pop    %rbp
ret

x86 assembly (clang, -O2):
<clear>:
mov    $0xb8030,%eax
shl    $0x4,%edi
add    %esi,%edi
movd   %edi,%xmm0
punpcklbw %xmm0,%xmm0
pshuflw $0x0,%xmm0,%xmm0
pxor   %xmm1,%xmm1
punpcklbw %xmm1,%xmm0
pshuflw $0xe7,%xmm0,%xmm0
pshufhw $0x27,%xmm0,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pshuflw $0xb1,%xmm0,%xmm0
pshufhw $0x27,%xmm0,%xmm1
packuswb %xmm1,%xmm1
movdqa 0xebc(%rip),%xmm0
punpcklbw %xmm1,%xmm0
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
movdqa %xmm0,-0x30(%rax,%rcx,2)
movdqa %xmm0,-0x20(%rax,%rcx,2)
cmp    $0x7c0,%rcx
je     1176 <clear+0x76>
movdqa %xmm0,-0x10(%rax,%rcx,2)
movdqa %xmm0,(%rax,%rcx,2)
add    $0x20,%rcx
jmp    1150 <clear+0x50>
ret

LLVM IR (-O0):
define void @clear(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i8* inttoptr (i64 753664 to i8*), i8** %5
store i32 0, i32* %6
br label %7
7: ; preds = %10, %2
%8 = load i32, i32* %6
%9 = icmp ult i32 %8, 4000
br i1 %9, label %10, label %28
10: ; preds = %7
%11 = load i8*, i8** %5
%12 = load i32, i32* %6
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
store i8 32, i8* %14
%15 = load i32, i32* %6
%16 = add i32 %15, 1
store i32 %16, i32* %6
%17 = load i32, i32* %4
%18 = load i32, i32* %3
%19 = mul i32 %18, 16
%20 = add i32 %17, %19
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %5
%23 = load i32, i32* %6
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 %21, i8* %25
%26 = load i32, i32* %6
%27 = add i32 %26, 1
store i32 %27, i32* %6
br label %7
28: ; preds = %7
ret void
}

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