void k_clear_screen() {
  char *vidmem = (char *)0xB8000;
  unsigned int i = 0;
  while (i < (80 * 25 * 2)) {
    vidmem[i] = ' ';
    i++;
    vidmem[i] = 0x07;
    i++;
  }
}


x86 assembly (clang, -O0):
<k_clear_screen>:
push   %rbp
mov    %rsp,%rbp
mov    $0xb8000,%eax
mov    %rax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xfa0,-0xc(%rbp)
jae    114e <k_clear_screen+0x4e>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
movb   $0x20,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
movb   $0x7,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1114 <k_clear_screen+0x14>
pop    %rbp
ret

x86 assembly (clang, -O2):
<k_clear_screen>:
mov    $0xb8070,%eax
xor    %ecx,%ecx
movaps 0xef2(%rip),%xmm0
xchg   %ax,%ax
movaps %xmm0,-0x70(%rax,%rcx,2)
movaps %xmm0,-0x60(%rax,%rcx,2)
cmp    $0x7c0,%rcx
je     1146 <k_clear_screen+0x46>
movaps %xmm0,-0x50(%rax,%rcx,2)
movaps %xmm0,-0x40(%rax,%rcx,2)
movaps %xmm0,-0x30(%rax,%rcx,2)
movaps %xmm0,-0x20(%rax,%rcx,2)
movaps %xmm0,-0x10(%rax,%rcx,2)
movaps %xmm0,(%rax,%rcx,2)
add    $0x40,%rcx
jmp    1110 <k_clear_screen+0x10>
ret

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

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