#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_fix_screeninfo {
  int /*<<< orphan*/ smem_len;
};

/* Variables and functions */
int /*<<< orphan*/ FBIOGET_FSCREENINFO;
char *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
scalar_t__ colortable(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct fb_fix_screeninfo *);
int /*<<< orphan*/ memset(char *, int, int /*<<< orphan*/);
char *mmap(int /*<<< orphan*/, int /*<<< orphan*/, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int main(void) {
  int fd;
  struct fb_fix_screeninfo fb_fix;
  char *mapped;
  if ((fd = open("/dev/fb/0", O_RDWR)) < 0) {
    perror("/dev/fb/0");
    return 1;
  }
  if (ioctl(fd, FBIOGET_FSCREENINFO, &fb_fix) < 0) {
    perror("FBIOGET_FSCREENINFO");
    return 1;
  }
  if (colortable(fd) < 0)
    return 1;
  mapped = mmap(0, fb_fix.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  if (mapped == MAP_FAILED) {
    perror("mmap");
    return 1;
  }
  memset(mapped, 1, fb_fix.smem_len);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11a8 <main+0x48>
lea    0xe69(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1272 <main+0x112>
mov    -0x8(%rbp),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    11df <main+0x7f>
lea    0xe3c(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1272 <main+0x112>
mov    -0x8(%rbp),%edi
call   1060 <colortable@plt>
cmp    $0x0,%rax
jge    11fd <main+0x9d>
movl   $0x1,-0x4(%rbp)
jmp    1272 <main+0x112>
mov    -0x10(%rbp),%esi
mov    0x2df1(%rip),%rax
mov    (%rax),%edx
mov    0x2db0(%rip),%rax
or     (%rax),%edx
mov    0x2dcf(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2d7f(%rip),%rcx
cmp    (%rcx),%rax
jne    125a <main+0xfa>
lea    0xdd5(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1272 <main+0x112>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%edx
mov    $0x1,%esi
call   1040 <memset@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
lea    0xe8d(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11f9 <main+0x99>
mov    %eax,%ebp
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebp,%edi
call   1050 <ioctl@plt>
test   %rax,%rax
js     1202 <main+0xa2>
mov    %ebp,%edi
call   1060 <colortable@plt>
mov    $0x1,%ebx
test   %rax,%rax
js     11f0 <main+0x90>
mov    (%rsp),%esi
mov    0x2e47(%rip),%rax
mov    0x2e08(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e25(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2ddf(%rip),%rcx
cmp    (%rcx),%rax
je     1215 <main+0xb5>
mov    (%rsp),%edx
mov    %rax,%rdi
mov    $0x1,%esi
call   1040 <memset@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe00(%rip),%rdi
jmp    1209 <main+0xa9>
lea    0xe01(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%ebx
jmp    11f0 <main+0x90>
lea    0xe02(%rip),%rdi
call   1080 <perror@plt>
jmp    11f0 <main+0x90>

LLVM IR (-O0):
%struct.fb_fix_screeninfo = type { i32 }
@.str = [10 x i8] c"/dev/fb/0\00"
@O_RDWR = global i32 0
@FBIOGET_FSCREENINFO = global i32 0
@.str.1 = [20 x i8] c"FBIOGET_FSCREENINFO\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [5 x i8] c"mmap\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.fb_fix_screeninfo
%4 = alloca i8*
store i32 0, i32* %1
%5 = load i32, i32* @O_RDWR
%6 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %41
10: ; preds = %0
%11 = load i32, i32* %2
%12 = load i32, i32* @FBIOGET_FSCREENINFO
%13 = call i64 @ioctl(i32 %11, i32 %12, %struct.fb_fix_screeninfo* %3)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %41
17: ; preds = %10
%18 = load i32, i32* %2
%19 = call i64 @colortable(i32 %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 1, i32* %1
br label %41
22: ; preds = %17
%23 = getelementptr inbounds %struct.fb_fix_screeninfo, %struct.fb_fix_screeninfo* %3, i32 0, i32 0
%24 = load i32, i32* %23
%25 = load i32, i32* @PROT_READ
%26 = load i32, i32* @PROT_WRITE
%27 = or i32 %25, %26
%28 = load i32, i32* @MAP_SHARED
%29 = load i32, i32* %2
%30 = call i8* @mmap(i32 0, i32 %24, i32 %27, i32 %28, i32 %29, i32 0)
store i8* %30, i8** %4
%31 = load i8*, i8** %4
%32 = load i8*, i8** @MAP_FAILED
%33 = icmp eq i8* %31, %32
br i1 %33, label %34, label %36
34: ; preds = %22
%35 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %41
36: ; preds = %22
%37 = load i8*, i8** %4
%38 = getelementptr inbounds %struct.fb_fix_screeninfo, %struct.fb_fix_screeninfo* %3, i32 0, i32 0
%39 = load i32, i32* %38
%40 = call i32 @memset(i8* %37, i32 1, i32 %39)
store i32 0, i32* %1
br label %41
41: ; preds = %36, %34, %21, %15, %8
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
%struct.fb_fix_screeninfo = type { i32 }
@.str = [10 x i8] c"/dev/fb/0\00"
@O_RDWR = global i32 0
@FBIOGET_FSCREENINFO = global i32 0
@.str.1 = [20 x i8] c"FBIOGET_FSCREENINFO\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [5 x i8] c"mmap\00"
define i32 @main() {
%1 = alloca %struct.fb_fix_screeninfo
%2 = bitcast %struct.fb_fix_screeninfo* %1 to i8*
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %32
8: ; preds = %0
%9 = load i32, i32* @FBIOGET_FSCREENINFO
%10 = call i64 @ioctl(i32 %4, i32 %9, %struct.fb_fix_screeninfo* %1)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %32
14: ; preds = %8
%15 = call i64 @colortable(i32 %4)
%16 = icmp slt i64 %15, 0
br i1 %16, label %32, label %17
17: ; preds = %14
%18 = getelementptr inbounds %struct.fb_fix_screeninfo, %struct.fb_fix_screeninfo* %1, i64 0, i32 0
%19 = load i32, i32* %18
%20 = load i32, i32* @PROT_READ
%21 = load i32, i32* @PROT_WRITE
%22 = or i32 %21, %20
%23 = load i32, i32* @MAP_SHARED
%24 = call i8* @mmap(i32 0, i32 %19, i32 %22, i32 %23, i32 %4, i32 0)
%25 = load i8*, i8** @MAP_FAILED
%26 = icmp eq i8* %24, %25
br i1 %26, label %27, label %29
27: ; preds = %17
%28 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %32
29: ; preds = %17
%30 = load i32, i32* %18
%31 = call i32 @memset(i8* %24, i32 1, i32 %30)
br label %32
32: ; preds = %14, %29, %27, %12, %6
%33 = phi i32 [ 1, %6 ], [ 1, %12 ], [ 1, %27 ], [ 0, %29 ], [ 1, %14 ]
ret i32 %33
}