#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 */
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
char *calloc(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int write(int, char *, int);
void clear_display(void) {
  int fb = open("/dev/graphics/fb0", O_WRONLY);
  if (fb < 0) {
    printf("Error opening framebuffer on device.\n");
    exit(0);
  }
  char *zeros = calloc(1, 512);
  ssize_t written, total = 0;
  do {
    total += written = write(fb, zeros, 512);
  } while (written == 512);
  close(fb);
  free(zeros);
}


x86 assembly (clang, -O0):
<clear_display>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11ad <clear_display+0x3d>
lea    0xe71(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    $0x1,%edi
mov    $0x200,%esi
call   1070 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x200,%edx
call   1040 <write@plt>
mov    %eax,-0x14(%rbp)
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x200,-0x14(%rbp)
je     11c7 <clear_display+0x57>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clear_display>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
lea    0xe7d(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     11cb <clear_display+0x5b>
mov    %eax,%ebp
mov    $0x1,%edi
mov    $0x200,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1050 <write@plt>
cmp    $0x200,%eax
je     11a0 <clear_display+0x30>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <free@plt>
lea    0xe40(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"/dev/graphics/fb0\00"
@O_WRONLY = global i32 0
@.str.1 = [38 x i8] c"Error opening framebuffer on device.\0A\00"
define void @clear_display() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = load i32, i32* @O_WRONLY
%6 = call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %1
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %0
%13 = call i8* @calloc(i32 1, i32 512)
store i8* %13, i8** %2
store i32 0, i32* %4
br label %14
14: ; preds = %20, %12
%15 = load i32, i32* %1
%16 = load i8*, i8** %2
%17 = call i32 @write(i32 %15, i8* %16, i32 512)
store i32 %17, i32* %3
%18 = load i32, i32* %4
%19 = add nsw i32 %18, %17
store i32 %19, i32* %4
br label %20
20: ; preds = %14
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, 512
br i1 %22, label %14, label %23
23: ; preds = %20
%24 = load i32, i32* %1
%25 = call i32 @close(i32 %24)
%26 = load i8*, i8** %2
%27 = call i32 @free(i8* %26)
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"/dev/graphics/fb0\00"
@O_WRONLY = global i32 0
@str = [37 x i8] c"Error opening framebuffer on device.\00"
define void @clear_display() {
%1 = load i32, i32* @O_WRONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 0)
unreachable
7: ; preds = %0
%8 = tail call dereferenceable_or_null(512) i8* @calloc(i32 1, i32 512)
br label %9
9: ; preds = %9, %7
%10 = tail call i32 @write(i32 %2, i8* %8, i32 512)
%11 = icmp eq i32 %10, 512
br i1 %11, label %9, label %12
12: ; preds = %9
%13 = tail call i32 @close(i32 %2)
%14 = tail call i32 @free(i8* %8)
ret void
}