#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 */
struct fb_var_screeninfo {
  int xres;
  int yres;
  int bits_per_pixel;
  long smem_len;
};
struct fb_fix_screeninfo {
  int xres;
  int yres;
  int bits_per_pixel;
  long smem_len;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ FBIOGET_FSCREENINFO;
int /*<<< orphan*/ FBIOGET_VSCREENINFO;
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct fb_var_screeninfo *);
int /*<<< orphan*/ memset(char *, int, long);
scalar_t__ mmap(int /*<<< orphan*/, long, int, int /*<<< orphan*/, int,
                int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, long);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int fbfd = 0;
  struct fb_var_screeninfo vinfo;
  struct fb_fix_screeninfo finfo;
  long int screensize = 0;
  char *fbp = 0;
  fbfd = open("/dev/fb0", O_RDWR);
  if (!fbfd) {
    printf("Error: cannot open framebuffer device.\n");
    exit(EXIT_FAILURE);
  }
  printf("The framebuffer device was opened successfully.\n");
  if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
    printf("Error reading fixed information.\n");
  }
  if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
    printf("Error reading variable information.\n");
  }
  printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
  screensize = finfo.smem_len;
  fbp =
      (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
  if ((void *)fbp == MAP_FAILED) {
    printf("Failed to mmap.\n");
    exit(EXIT_FAILURE);
  } else {
    memset(fbp, 0xff, screensize / 2);
    memset(fbp + screensize / 2, 0xff, screensize / 2);
  }
  munmap(fbp, screensize);
  close(fbfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
lea    0xe4a(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11e4 <main+0x64>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0x0,%rax
je     121f <main+0x9f>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    0x2d87(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0x0,%rax
je     124c <main+0xcc>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rsi
mov    0x2d82(%rip),%rax
mov    (%rax),%edx
mov    0x2d39(%rip),%rax
or     (%rax),%edx
mov    0x2d60(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    0x2d00(%rip),%rcx
cmp    (%rcx),%rax
jne    12cd <main+0x14d>
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rdx
mov    $0xff,%esi
call   1050 <memset@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
add    %rax,%rdi
mov    -0x40(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rdx
mov    $0xff,%esi
call   1050 <memset@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1080 <munmap@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
lea    0xe56(%rip),%rdi
call   10a0 <open@plt>
test   %eax,%eax
je     12bd <main+0x12d>
mov    %eax,%r14d
lea    0xe7d(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
lea    0x20(%rsp),%rdx
mov    %r14d,%edi
call   1070 <ioctl@plt>
test   %rax,%rax
je     11ed <main+0x5d>
lea    0xeba(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %r14d,%edi
call   1070 <ioctl@plt>
test   %rax,%rax
je     1214 <main+0x84>
lea    0xe6f(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
mov    0x10(%rsp),%ecx
lea    0xde2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x30(%rsp),%r15
mov    0x2dbe(%rip),%rax
mov    0x2d77(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d9c(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r15,%rsi
mov    %r14d,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbp
mov    0x2d40(%rip),%rax
cmp    %rbp,(%rax)
je     12c6 <main+0x136>
mov    %r15,%rbx
shr    $0x3f,%rbx
add    %r15,%rbx
sar    %rbx
mov    %rbp,%rdi
mov    $0xff,%esi
mov    %rbx,%rdx
call   1060 <memset@plt>
mov    %rbp,%rdi
add    %rbx,%rdi
mov    $0xff,%esi
mov    %rbx,%rdx
call   1060 <memset@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1090 <munmap@plt>
mov    %r14d,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd53(%rip),%rdi
jmp    12cd <main+0x13d>
lea    0xda1(%rip),%rdi
call   1030 <puts@plt>
mov    0x2ce7(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.fb_var_screeninfo = type { i32, i32, i32, i64 }
%struct.fb_fix_screeninfo = type { i32, i32, i32, i64 }
@.str = [9 x i8] c"/dev/fb0\00"
@O_RDWR = global i32 0
@.str.1 = [40 x i8] c"Error: cannot open framebuffer device.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [49 x i8] c"The framebuffer device was opened successfully.\0A\00"
@FBIOGET_FSCREENINFO = global i32 0
@.str.3 = [34 x i8] c"Error reading fixed information.\0A\00"
@FBIOGET_VSCREENINFO = global i32 0
@.str.4 = [37 x i8] c"Error reading variable information.\0A\00"
@.str.5 = [14 x i8] c"%dx%d, %dbpp\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.6 = [17 x i8] c"Failed to mmap.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.fb_var_screeninfo
%4 = alloca %struct.fb_fix_screeninfo
%5 = alloca i64
%6 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %2
store i64 0, i64* %5
store i8* null, i8** %6
%7 = load i32, i32* @O_RDWR
%8 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp ne i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* %2
%18 = load i32, i32* @FBIOGET_FSCREENINFO
%19 = bitcast %struct.fb_fix_screeninfo* %4 to %struct.fb_var_screeninfo*
%20 = call i64 @ioctl(i32 %17, i32 %18, %struct.fb_var_screeninfo* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %15
%25 = load i32, i32* %2
%26 = load i32, i32* @FBIOGET_VSCREENINFO
%27 = call i64 @ioctl(i32 %25, i32 %26, %struct.fb_var_screeninfo* %3)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %29, %24
%32 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %3, i32 0, i32 0
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %3, i32 0, i32 1
%35 = load i32, i32* %34
%36 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %3, i32 0, i32 2
%37 = load i32, i32* %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %33, i32 %35, i32 %37)
%39 = getelementptr inbounds %struct.fb_fix_screeninfo, %struct.fb_fix_screeninfo* %4, i32 0, i32 3
%40 = load i64, i64* %39
store i64 %40, i64* %5
%41 = load i64, i64* %5
%42 = load i32, i32* @PROT_READ
%43 = load i32, i32* @PROT_WRITE
%44 = or i32 %42, %43
%45 = load i32, i32* @MAP_SHARED
%46 = load i32, i32* %2
%47 = call i64 @mmap(i32 0, i64 %41, i32 %44, i32 %45, i32 %46, i32 0)
%48 = inttoptr i64 %47 to i8*
store i8* %48, i8** %6
%49 = load i8*, i8** %6
%50 = load i8*, i8** @MAP_FAILED
%51 = icmp eq i8* %49, %50
br i1 %51, label %52, label %56
52: ; preds = %31
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %31
%57 = load i8*, i8** %6
%58 = load i64, i64* %5
%59 = sdiv i64 %58, 2
%60 = call i32 @memset(i8* %57, i32 255, i64 %59)
%61 = load i8*, i8** %6
%62 = load i64, i64* %5
%63 = sdiv i64 %62, 2
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = load i64, i64* %5
%66 = sdiv i64 %65, 2
%67 = call i32 @memset(i8* %64, i32 255, i64 %66)
br label %68
68: ; preds = %56
%69 = load i8*, i8** %6
%70 = load i64, i64* %5
%71 = call i32 @munmap(i8* %69, i64 %70)
%72 = load i32, i32* %2
%73 = call i32 @close(i32 %72)
ret i32 0
}

LLVM IR (-O2):
%struct.fb_var_screeninfo = type { i32, i32, i32, i64 }
%struct.fb_fix_screeninfo = type { i32, i32, i32, i64 }
@.str = [9 x i8] c"/dev/fb0\00"
@O_RDWR = global i32 0
@EXIT_FAILURE = global i32 0
@FBIOGET_FSCREENINFO = global i32 0
@FBIOGET_VSCREENINFO = global i32 0
@.str.5 = [14 x i8] c"%dx%d, %dbpp\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@str = [39 x i8] c"Error: cannot open framebuffer device.\00"
@str.7 = [48 x i8] c"The framebuffer device was opened successfully.\00"
@str.8 = [16 x i8] c"Failed to mmap.\00"
@str.9 = [36 x i8] c"Error reading variable information.\00"
@str.10 = [33 x i8] c"Error reading fixed information.\00"
define i32 @main() {
%1 = alloca %struct.fb_var_screeninfo
%2 = alloca %struct.fb_fix_screeninfo
%3 = bitcast %struct.fb_var_screeninfo* %1 to i8*
%4 = bitcast %struct.fb_fix_screeninfo* %2 to i8*
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.7, i64 0, i64 0))
%14 = load i32, i32* @FBIOGET_FSCREENINFO
%15 = bitcast %struct.fb_fix_screeninfo* %2 to %struct.fb_var_screeninfo*
%16 = call i64 @ioctl(i32 %6, i32 %14, %struct.fb_var_screeninfo* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %12
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.10, i64 0, i64 0))
br label %20
20: ; preds = %18, %12
%21 = load i32, i32* @FBIOGET_VSCREENINFO
%22 = call i64 @ioctl(i32 %6, i32 %21, %struct.fb_var_screeninfo* %1)
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %20
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.9, i64 0, i64 0))
br label %26
26: ; preds = %24, %20
%27 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %1, i64 0, i32 0
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %1, i64 0, i32 1
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %1, i64 0, i32 2
%32 = load i32, i32* %31
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %28, i32 %30, i32 %32)
%34 = getelementptr inbounds %struct.fb_fix_screeninfo, %struct.fb_fix_screeninfo* %2, i64 0, i32 3
%35 = load i64, i64* %34
%36 = load i32, i32* @PROT_READ
%37 = load i32, i32* @PROT_WRITE
%38 = or i32 %37, %36
%39 = load i32, i32* @MAP_SHARED
%40 = call i64 @mmap(i32 0, i64 %35, i32 %38, i32 %39, i32 %6, i32 0)
%41 = inttoptr i64 %40 to i8*
%42 = load i8*, i8** @MAP_FAILED
%43 = icmp eq i8* %42, %41
br i1 %43, label %44, label %48
44: ; preds = %26
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.8, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %26
%49 = sdiv i64 %35, 2
%50 = call i32 @memset(i8* %41, i32 255, i64 %49)
%51 = getelementptr inbounds i8, i8* %41, i64 %49
%52 = call i32 @memset(i8* %51, i32 255, i64 %49)
%53 = call i32 @munmap(i8* %41, i64 %35)
%54 = call i32 @close(i32 %6)
ret i32 0
}