#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;
};
struct fb_fix_screeninfo {
  int xres;
  int yres;
  int bits_per_pixel;
};

/* Variables and functions */
int /*<<< orphan*/ FBIOGET_FSCREENINFO;
int /*<<< orphan*/ FBIOGET_VSCREENINFO;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct fb_var_screeninfo *);
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() {
  int fbfd = 0;
  struct fb_var_screeninfo vinfo;
  struct fb_fix_screeninfo finfo;
  long int screensize = 0;
  char *fbp = 0;
  int i;
  fbfd = open("/dev/fb0", O_RDWR);
  if (!fbfd) {
    printf("Error: cannot open framebuffer device.\n");
    exit(1);
  }
  printf("The framebuffer device was opened successfully.\n");
  if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
    printf("Error reading fixed information.\n");
    exit(2);
  }
  if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
    printf("Error reading variable information.\n");
    exit(3);
  }
  screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
  fbp =
      (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
  if ((int)fbp == -1) {
    printf("Error: failed to map framebuffer device to memory.\n");
    exit(4);
  }
  printf("vinfo.xres : %d\n", vinfo.xres);
  printf("vinfo.yres : %d\n", vinfo.yres);
  printf("vinfo.bits_per_pixel : %d\n", vinfo.bits_per_pixel);
  for (i = 0; i < screensize; i++) {
    fbp[i] = 0x11;
  }
  printf("The framebuffer device was mapped to memory successfully.\n");
  munmap(fbp, screensize);
  close(fbfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
lea    0xe5a(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11d0 <main+0x60>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
je     1215 <main+0xa5>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
je     124c <main+0xdc>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x3,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%eax
imul   -0x14(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
mov    0x2d88(%rip),%rax
mov    (%rax),%edx
mov    0x2d47(%rip),%rax
or     (%rax),%edx
mov    0x2d66(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    $0xffffffff,%eax
jne    12bc <main+0x14c>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x4,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%esi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
cmp    -0x30(%rbp),%rax
jge    131e <main+0x1ae>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movb   $0x11,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12f6 <main+0x186>
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <munmap@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
lea    0xe56(%rip),%rdi
call   10a0 <open@plt>
test   %eax,%eax
je     12ce <main+0x13e>
mov    %eax,%r15d
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
lea    0x18(%rsp),%rdx
mov    %r15d,%edi
call   1070 <ioctl@plt>
test   %rax,%rax
jne    12e4 <main+0x154>
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %r15d,%edi
call   1070 <ioctl@plt>
test   %rax,%rax
jne    12fa <main+0x16a>
mov    0xc(%rsp),%ebp
imul   0x8(%rsp),%ebp
imul   0x10(%rsp),%ebp
lea    0x7(%rbp),%eax
test   %ebp,%ebp
cmovns %ebp,%eax
sar    $0x3,%eax
movslq %eax,%r14
mov    0x2dd1(%rip),%rax
mov    0x2d92(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2daf(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r14,%rsi
mov    %r15d,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
cmp    $0xffffffff,%ebx
je     1310 <main+0x180>
mov    0x8(%rsp),%esi
lea    0xda7(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
lea    0xda6(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%esi
lea    0xda5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x8,%ebp
jl     12a2 <main+0x112>
mov    %rbx,%rdi
mov    $0x11,%esi
mov    %r14,%rdx
call   1060 <memset@plt>
lea    0xdf4(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <munmap@plt>
mov    %r15d,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd71(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xe43(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
lea    0xe09(%rip),%rdi
call   1030 <puts@plt>
mov    $0x3,%edi
call   10b0 <exit@plt>
lea    0xdc0(%rip),%rdi
call   1030 <puts@plt>
mov    $0x4,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.fb_var_screeninfo = type { i32, i32, i32 }
%struct.fb_fix_screeninfo = type { i32, i32, i32 }
@.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"
@.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"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.5 = [52 x i8] c"Error: failed to map framebuffer device to memory.\0A\00"
@.str.6 = [17 x i8] c"vinfo.xres : %d\0A\00"
@.str.7 = [17 x i8] c"vinfo.yres : %d\0A\00"
@.str.8 = [27 x i8] c"vinfo.bits_per_pixel : %d\0A\00"
@.str.9 = [59 x i8] c"The framebuffer device was mapped to memory successfully.\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*
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i64 0, i64* %5
store i8* null, i8** %6
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
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 %25
22: ; preds = %15
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 @exit(i32 2)
unreachable
25: ; preds = %15
%26 = load i32, i32* %2
%27 = load i32, i32* @FBIOGET_VSCREENINFO
%28 = call i64 @ioctl(i32 %26, i32 %27, %struct.fb_var_screeninfo* %3)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 @exit(i32 3)
unreachable
33: ; preds = %25
%34 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %3, i32 0, i32 0
%35 = load i32, i32* %34
%36 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %3, i32 0, i32 1
%37 = load i32, i32* %36
%38 = mul nsw i32 %35, %37
%39 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %3, i32 0, i32 2
%40 = load i32, i32* %39
%41 = mul nsw i32 %38, %40
%42 = sdiv i32 %41, 8
%43 = sext i32 %42 to i64
store i64 %43, i64* %5
%44 = load i64, i64* %5
%45 = load i32, i32* @PROT_READ
%46 = load i32, i32* @PROT_WRITE
%47 = or i32 %45, %46
%48 = load i32, i32* @MAP_SHARED
%49 = load i32, i32* %2
%50 = call i64 @mmap(i32 0, i64 %44, i32 %47, i32 %48, i32 %49, i32 0)
%51 = inttoptr i64 %50 to i8*
store i8* %51, i8** %6
%52 = load i8*, i8** %6
%53 = ptrtoint i8* %52 to i32
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %58
55: ; preds = %33
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0))
%57 = call i32 @exit(i32 4)
unreachable
58: ; preds = %33
%59 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %3, i32 0, i32 0
%60 = load i32, i32* %59
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %60)
%62 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %3, i32 0, i32 1
%63 = load i32, i32* %62
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i32 %63)
%65 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %3, i32 0, i32 2
%66 = load i32, i32* %65
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i32 %66)
store i32 0, i32* %7
br label %68
68: ; preds = %78, %58
%69 = load i32, i32* %7
%70 = sext i32 %69 to i64
%71 = load i64, i64* %5
%72 = icmp slt i64 %70, %71
br i1 %72, label %73, label %81
73: ; preds = %68
%74 = load i8*, i8** %6
%75 = load i32, i32* %7
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %74, i64 %76
store i8 17, i8* %77
br label %78
78: ; preds = %73
%79 = load i32, i32* %7
%80 = add nsw i32 %79, 1
store i32 %80, i32* %7
br label %68
81: ; preds = %68
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.9, i64 0, i64 0))
%83 = load i8*, i8** %6
%84 = load i64, i64* %5
%85 = call i32 @munmap(i8* %83, i64 %84)
%86 = load i32, i32* %2
%87 = call i32 @close(i32 %86)
ret i32 0
}

LLVM IR (-O2):
%struct.fb_var_screeninfo = type { i32, i32, i32 }
%struct.fb_fix_screeninfo = type { i32, i32, i32 }
@.str = [9 x i8] c"/dev/fb0\00"
@O_RDWR = global i32 0
@FBIOGET_FSCREENINFO = global i32 0
@FBIOGET_VSCREENINFO = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.6 = [17 x i8] c"vinfo.xres : %d\0A\00"
@.str.7 = [17 x i8] c"vinfo.yres : %d\0A\00"
@.str.8 = [27 x i8] c"vinfo.bits_per_pixel : %d\0A\00"
@str = [39 x i8] c"Error: cannot open framebuffer device.\00"
@str.10 = [48 x i8] c"The framebuffer device was opened successfully.\00"
@str.11 = [58 x i8] c"The framebuffer device was mapped to memory successfully.\00"
@str.12 = [51 x i8] c"Error: failed to map framebuffer device to memory.\00"
@str.13 = [36 x i8] c"Error reading variable information.\00"
@str.14 = [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 %11
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 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.10, i64 0, i64 0))
%13 = load i32, i32* @FBIOGET_FSCREENINFO
%14 = bitcast %struct.fb_fix_screeninfo* %2 to %struct.fb_var_screeninfo*
%15 = call i64 @ioctl(i32 %6, i32 %13, %struct.fb_var_screeninfo* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %11
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.14, i64 0, i64 0))
%19 = call i32 @exit(i32 2)
unreachable
20: ; preds = %11
%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 %27, label %24
24: ; preds = %20
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.13, i64 0, i64 0))
%26 = call i32 @exit(i32 3)
unreachable
27: ; preds = %20
%28 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %1, i64 0, i32 0
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %1, i64 0, i32 1
%31 = load i32, i32* %30
%32 = mul nsw i32 %31, %29
%33 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %1, i64 0, i32 2
%34 = load i32, i32* %33
%35 = mul nsw i32 %32, %34
%36 = sdiv i32 %35, 8
%37 = sext i32 %36 to i64
%38 = load i32, i32* @PROT_READ
%39 = load i32, i32* @PROT_WRITE
%40 = or i32 %39, %38
%41 = load i32, i32* @MAP_SHARED
%42 = call i64 @mmap(i32 0, i64 %37, i32 %40, i32 %41, i32 %6, i32 0)
%43 = inttoptr i64 %42 to i8*
%44 = trunc i64 %42 to i32
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %49
46: ; preds = %27
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.12, i64 0, i64 0))
%48 = call i32 @exit(i32 4)
unreachable
49: ; preds = %27
%50 = load i32, i32* %28
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %50)
%52 = load i32, i32* %30
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i32 %52)
%54 = load i32, i32* %33
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i32 %54)
%56 = icmp sgt i32 %35, 7
br i1 %56, label %57, label %58
57: ; preds = %49
br label %58
58: ; preds = %57, %49
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str.11, i64 0, i64 0))
%60 = call i32 @munmap(i8* %43, i64 %37)
%61 = call i32 @close(i32 %6)
ret i32 0
}