#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ get_screen_offset(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ set_cursor(int /*<<< orphan*/);
void clearscreen() {
  char *video_memory = (char *)0xb8000;
  int max = 0xb8000 + 2 * (80 * 25);
  for (int i = 0; i < max; i++) {
    *video_memory = 0x00;
    video_memory = video_memory + 2;
  }
  set_cursor(get_screen_offset(0, 0));
}


x86 assembly (clang, -O0):
<clearscreen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0xb8000,%eax
mov    %rax,-0x8(%rbp)
movl   $0xb8fa0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    116c <clearscreen+0x4c>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113f <clearscreen+0x1f>
xor    %esi,%esi
mov    %esi,%edi
call   1030 <get_screen_offset@plt>
mov    %eax,%edi
call   1040 <set_cursor@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clearscreen>:
push   %rax
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x0,0xb8000(%rax,%rax,1)
movb   $0x0,0xb8002(%rax,%rax,1)
movb   $0x0,0xb8004(%rax,%rax,1)
movb   $0x0,0xb8006(%rax,%rax,1)
movb   $0x0,0xb8008(%rax,%rax,1)
movb   $0x0,0xb800a(%rax,%rax,1)
movb   $0x0,0xb800c(%rax,%rax,1)
movb   $0x0,0xb800e(%rax,%rax,1)
add    $0x8,%rax
cmp    $0xb8fa0,%eax
jne    1130 <clearscreen+0x10>
xor    %edi,%edi
xor    %esi,%esi
call   1030 <get_screen_offset@plt>
mov    %eax,%edi
pop    %rax
jmp    1040 <set_cursor@plt>

LLVM IR (-O0):
define void @clearscreen() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
store i8* inttoptr (i64 753664 to i8*), i8** %1
store i32 757664, i32* %2
store i32 0, i32* %3
br label %4
4: ; preds = %12, %0
%5 = load i32, i32* %3
%6 = load i32, i32* %2
%7 = icmp slt i32 %5, %6
br i1 %7, label %8, label %15
8: ; preds = %4
%9 = load i8*, i8** %1
store i8 0, i8* %9
%10 = load i8*, i8** %1
%11 = getelementptr inbounds i8, i8* %10, i64 2
store i8* %11, i8** %1
br label %12
12: ; preds = %8
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
br label %4
15: ; preds = %4
%16 = call i32 @get_screen_offset(i32 0, i32 0)
%17 = call i32 @set_cursor(i32 %16)
ret void
}

LLVM IR (-O2):
define void @clearscreen() {
br label %4
1: ; preds = %4
%2 = tail call i32 @get_screen_offset(i32 0, i32 0)
%3 = tail call i32 @set_cursor(i32 %2)
ret void
4: ; preds = %4, %0
%5 = phi i32 [ 0, %0 ], [ %15, %4 ]
%6 = phi i8* [ inttoptr (i64 753664 to i8*), %0 ], [ %14, %4 ]
store i8 0, i8* %6
%7 = getelementptr inbounds i8, i8* %6, i64 2
store i8 0, i8* %7
%8 = getelementptr inbounds i8, i8* %6, i64 4
store i8 0, i8* %8
%9 = getelementptr inbounds i8, i8* %6, i64 6
store i8 0, i8* %9
%10 = getelementptr inbounds i8, i8* %6, i64 8
store i8 0, i8* %10
%11 = getelementptr inbounds i8, i8* %6, i64 10
store i8 0, i8* %11
%12 = getelementptr inbounds i8, i8* %6, i64 12
store i8 0, i8* %12
%13 = getelementptr inbounds i8, i8* %6, i64 14
store i8 0, i8* %13
%14 = getelementptr inbounds i8, i8* %6, i64 16
%15 = add nuw nsw i32 %5, 8
%16 = icmp eq i32 %15, 757664
br i1 %16, label %1, label %4
}