void clear_screen() {
  unsigned char *vidmem = (unsigned char *)0xB8000;
  int loop;
  for (loop = 0; loop < (80 * 25); loop++) {
    *vidmem++ = 0x20;
    *vidmem++ = 0x0F;
  }
}


x86 assembly (clang, -O0):
<clear_screen>:
push   %rbp
mov    %rsp,%rbp
mov    $0xb8000,%eax
mov    %rax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x7d0,-0xc(%rbp)
jge    1153 <clear_screen+0x53>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x20,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0xf,(%rax)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1114 <clear_screen+0x14>
pop    %rbp
ret

x86 assembly (clang, -O2):
<clear_screen>:
mov    $0x38,%eax
mov    $0xb8000,%ecx
movaps 0xeef(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movaps %xmm0,-0x70(%rcx,%rax,2)
movaps %xmm0,-0x60(%rcx,%rax,2)
cmp    $0x7f8,%rax
je     1155 <clear_screen+0x55>
movaps %xmm0,-0x50(%rcx,%rax,2)
movaps %xmm0,-0x40(%rcx,%rax,2)
movaps %xmm0,-0x30(%rcx,%rax,2)
movaps %xmm0,-0x20(%rcx,%rax,2)
movaps %xmm0,-0x10(%rcx,%rax,2)
movaps %xmm0,(%rcx,%rax,2)
add    $0x40,%rax
jmp    1120 <clear_screen+0x20>
ret

LLVM IR (-O0):
define void @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 = %11, %0
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 2000
br i1 %5, label %6, label %14
6: ; preds = %3
%7 = load i8*, i8** %1
%8 = getelementptr inbounds i8, i8* %7, i32 1
store i8* %8, i8** %1
store i8 32, i8* %7
%9 = load i8*, i8** %1
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %1
store i8 15, i8* %9
br label %11
11: ; preds = %6
%12 = load i32, i32* %2
%13 = add nsw i32 %12, 1
store i32 %13, i32* %2
br label %3
14: ; preds = %3
ret void
}

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