#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 uint16_t;
struct fb_fix_screeninfo {
  int /*<<< orphan*/ id;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ FBIOGET_FSCREENINFO;
int *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ delay(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int ioctl(int, int /*<<< orphan*/, struct fb_fix_screeninfo *);
int /*<<< orphan*/ memset(int *, int, int);
int *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
          int /*<<< orphan*/);
int munmap(int *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int main(void) {
  int i;
  int fbfd;
  uint16_t *map;
  uint16_t *p;
  struct fb_fix_screeninfo fix_info;
  fbfd = open("/dev/fb1", O_RDWR);
  if (fbfd == -1) {
    perror("Error (call to 'open')");
    exit(EXIT_FAILURE);
  }
  if (ioctl(fbfd, FBIOGET_FSCREENINFO, &fix_info) == -1) {
    perror("Error (call to 'ioctl')");
    close(fbfd);
    exit(EXIT_FAILURE);
  }
  if (strcmp(fix_info.id, "RPi-Sense FB") != 0) {
    printf("%s\n", "Error: RPi-Sense FB not found");
    close(fbfd);
    exit(EXIT_FAILURE);
  }
  map = mmap(NULL, (64 * sizeof(uint16_t)), PROT_READ | PROT_WRITE, MAP_SHARED,
             fbfd, 0);
  if (map == MAP_FAILED) {
    close(fbfd);
    perror("Error mmapping the file");
    exit(EXIT_FAILURE);
  }
  p = map;
  memset(map, 0, (64 * sizeof(uint16_t)));
  for (i = 0; i < 64; i++) {
    *(p + i) = 0xF800;
    delay(25);
  }
  for (i = 0; i < 3; i++) {
    delay(250);
    memset(map, 0xFF, (64 * sizeof(uint16_t)));
    delay(250);
    memset(map, 0, (64 * sizeof(uint16_t)));
  }
  delay(250);
  memset(map, 0, (64 * sizeof(uint16_t)));
  if (munmap(map, (64 * sizeof(uint16_t))) == -1) {
    perror("Error un-mmapping the file");
  }
  close(fbfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
lea    0xe31(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11fb <main+0x4b>
lea    0xe21(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0xc(%rbp),%edi
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    123b <main+0x8b>
lea    0xe00(%rip),%rdi
call   10c0 <perror@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x28(%rbp),%edi
lea    0xdf3(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     127d <main+0xcd>
lea    0xdea(%rip),%rdi
lea    0xde7(%rip),%rsi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%edx
mov    0x2d2b(%rip),%rax
or     (%rax),%edx
mov    0x2d52(%rip),%rax
mov    (%rax),%ecx
mov    -0xc(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x100,%esi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2cf4(%rip),%rcx
cmp    (%rcx),%rax
jne    12e7 <main+0x137>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
lea    0xd93(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x40,-0x8(%rbp)
jge    1337 <main+0x187>
mov    -0x20(%rbp),%rax
movslq -0x8(%rbp),%rcx
movl   $0xf800,(%rax,%rcx,4)
mov    $0x19,%edi
call   1080 <delay@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1306 <main+0x156>
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    138d <main+0x1dd>
mov    $0xfa,%edi
call   1080 <delay@plt>
mov    -0x18(%rbp),%rdi
mov    $0xff,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    $0xfa,%edi
call   1080 <delay@plt>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    133e <main+0x18e>
mov    $0xfa,%edi
call   1080 <delay@plt>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    $0x100,%esi
call   10a0 <munmap@plt>
cmp    $0xffffffff,%eax
jne    13ca <main+0x21a>
lea    0xcba(%rip),%rdi
call   10c0 <perror@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
lea    0xe38(%rip),%rdi
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     1376 <main+0x1c6>
mov    %eax,%r14d
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %r14d,%edi
call   1060 <ioctl@plt>
cmp    $0xffffffff,%eax
je     137f <main+0x1cf>
mov    0x8(%rsp),%edi
lea    0xe35(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    138d <main+0x1dd>
mov    0x2de0(%rip),%rax
mov    0x2d99(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2dbe(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x100,%esi
mov    %r14d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
mov    0x2d68(%rip),%rax
cmp    (%rax),%rbx
je     13aa <main+0x1fa>
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movl   $0xf800,(%rbx,%rbp,4)
mov    $0x19,%edi
call   1080 <delay@plt>
add    $0x1,%rbp
cmp    $0x40,%rbp
jne    1270 <main+0xc0>
mov    $0xfa,%edi
call   1080 <delay@plt>
mov    %rbx,%rdi
mov    $0xff,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    $0xfa,%edi
call   1080 <delay@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    $0xfa,%edi
call   1080 <delay@plt>
mov    %rbx,%rdi
mov    $0xff,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    $0xfa,%edi
call   1080 <delay@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    $0xfa,%edi
call   1080 <delay@plt>
mov    %rbx,%rdi
mov    $0xff,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    $0xfa,%edi
call   1080 <delay@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    $0xfa,%edi
call   1080 <delay@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
call   10a0 <munmap@plt>
cmp    $0xffffffff,%eax
je     1368 <main+0x1b8>
mov    %r14d,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd10(%rip),%rdi
call   10c0 <perror@plt>
jmp    1355 <main+0x1a5>
lea    0xc8c(%rip),%rdi
jmp    13b9 <main+0x209>
lea    0xc9a(%rip),%rdi
call   10c0 <perror@plt>
jmp    13a0 <main+0x1f0>
lea    0xcb1(%rip),%rdi
lea    0xcae(%rip),%rsi
call   1040 <printf@plt>
mov    %r14d,%edi
call   1070 <close@plt>
jmp    13be <main+0x20e>
mov    %r14d,%edi
call   1070 <close@plt>
lea    0xcae(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2bfb(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.fb_fix_screeninfo = type { i32 }
@.str = [9 x i8] c"/dev/fb1\00"
@O_RDWR = global i32 0
@.str.1 = [23 x i8] c"Error (call to 'open')\00"
@EXIT_FAILURE = global i32 0
@FBIOGET_FSCREENINFO = global i32 0
@.str.2 = [24 x i8] c"Error (call to 'ioctl')\00"
@.str.3 = [13 x i8] c"RPi-Sense FB\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [30 x i8] c"Error: RPi-Sense FB not found\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i32* null
@.str.6 = [24 x i8] c"Error mmapping the file\00"
@.str.7 = [27 x i8] c"Error un-mmapping the file\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca %struct.fb_fix_screeninfo
store i32 0, i32* %1
%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* %3
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 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 = load i32, i32* %3
%17 = load i32, i32* @FBIOGET_FSCREENINFO
%18 = call i32 @ioctl(i32 %16, i32 %17, %struct.fb_fix_screeninfo* %6)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %26
20: ; preds = %15
%21 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* %3
%23 = call i32 @close(i32 %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %15
%27 = getelementptr inbounds %struct.fb_fix_screeninfo, %struct.fb_fix_screeninfo* %6, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i64 @strcmp(i32 %28, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %26
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%33 = load i32, i32* %3
%34 = call i32 @close(i32 %33)
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %26
%38 = load i32, i32* @PROT_READ
%39 = load i32, i32* @PROT_WRITE
%40 = or i32 %38, %39
%41 = load i32, i32* @MAP_SHARED
%42 = load i32, i32* %3
%43 = call i32* @mmap(i32* null, i32 256, i32 %40, i32 %41, i32 %42, i32 0)
store i32* %43, i32** %4
%44 = load i32*, i32** %4
%45 = load i32*, i32** @MAP_FAILED
%46 = icmp eq i32* %44, %45
br i1 %46, label %47, label %53
47: ; preds = %37
%48 = load i32, i32* %3
%49 = call i32 @close(i32 %48)
%50 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %37
%54 = load i32*, i32** %4
store i32* %54, i32** %5
%55 = load i32*, i32** %4
%56 = call i32 @memset(i32* %55, i32 0, i32 256)
store i32 0, i32* %2
br label %57
57: ; preds = %66, %53
%58 = load i32, i32* %2
%59 = icmp slt i32 %58, 64
br i1 %59, label %60, label %69
60: ; preds = %57
%61 = load i32*, i32** %5
%62 = load i32, i32* %2
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %61, i64 %63
store i32 63488, i32* %64
%65 = call i32 @delay(i32 25)
br label %66
66: ; preds = %60
%67 = load i32, i32* %2
%68 = add nsw i32 %67, 1
store i32 %68, i32* %2
br label %57
69: ; preds = %57
store i32 0, i32* %2
br label %70
70: ; preds = %80, %69
%71 = load i32, i32* %2
%72 = icmp slt i32 %71, 3
br i1 %72, label %73, label %83
73: ; preds = %70
%74 = call i32 @delay(i32 250)
%75 = load i32*, i32** %4
%76 = call i32 @memset(i32* %75, i32 255, i32 256)
%77 = call i32 @delay(i32 250)
%78 = load i32*, i32** %4
%79 = call i32 @memset(i32* %78, i32 0, i32 256)
br label %80
80: ; preds = %73
%81 = load i32, i32* %2
%82 = add nsw i32 %81, 1
store i32 %82, i32* %2
br label %70
83: ; preds = %70
%84 = call i32 @delay(i32 250)
%85 = load i32*, i32** %4
%86 = call i32 @memset(i32* %85, i32 0, i32 256)
%87 = load i32*, i32** %4
%88 = call i32 @munmap(i32* %87, i32 256)
%89 = icmp eq i32 %88, -1
br i1 %89, label %90, label %92
90: ; preds = %83
%91 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
br label %92
92: ; preds = %90, %83
%93 = load i32, i32* %3
%94 = call i32 @close(i32 %93)
ret i32 0
}

LLVM IR (-O2):
%struct.fb_fix_screeninfo = type { i32 }
@.str = [9 x i8] c"/dev/fb1\00"
@O_RDWR = global i32 0
@.str.1 = [23 x i8] c"Error (call to 'open')\00"
@EXIT_FAILURE = global i32 0
@FBIOGET_FSCREENINFO = global i32 0
@.str.2 = [24 x i8] c"Error (call to 'ioctl')\00"
@.str.3 = [13 x i8] c"RPi-Sense FB\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [30 x i8] c"Error: RPi-Sense FB not found\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i32* null
@.str.6 = [24 x i8] c"Error mmapping the file\00"
@.str.7 = [27 x i8] c"Error un-mmapping the file\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 ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = load i32, i32* @FBIOGET_FSCREENINFO
%12 = call i32 @ioctl(i32 %4, i32 %11, %struct.fb_fix_screeninfo* %1)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @close(i32 %4)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %10
%20 = getelementptr inbounds %struct.fb_fix_screeninfo, %struct.fb_fix_screeninfo* %1, i64 0, i32 0
%21 = load i32, i32* %20
%22 = call i64 @strcmp(i32 %21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %19
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%26 = call i32 @close(i32 %4)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %19
%30 = load i32, i32* @PROT_READ
%31 = load i32, i32* @PROT_WRITE
%32 = or i32 %31, %30
%33 = load i32, i32* @MAP_SHARED
%34 = call i32* @mmap(i32* null, i32 256, i32 %32, i32 %33, i32 %4, i32 0)
%35 = load i32*, i32** @MAP_FAILED
%36 = icmp eq i32* %34, %35
br i1 %36, label %37, label %42
37: ; preds = %29
%38 = call i32 @close(i32 %4)
%39 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %29
%43 = call i32 @memset(i32* %34, i32 0, i32 256)
br label %44
44: ; preds = %42, %44
%45 = phi i64 [ 0, %42 ], [ %48, %44 ]
%46 = getelementptr inbounds i32, i32* %34, i64 %45
store i32 63488, i32* %46
%47 = call i32 @delay(i32 25)
%48 = add nuw nsw i64 %45, 1
%49 = icmp eq i64 %48, 64
br i1 %49, label %50, label %44
50: ; preds = %44
%51 = call i32 @delay(i32 250)
%52 = call i32 @memset(i32* %34, i32 255, i32 256)
%53 = call i32 @delay(i32 250)
%54 = call i32 @memset(i32* %34, i32 0, i32 256)
%55 = call i32 @delay(i32 250)
%56 = call i32 @memset(i32* %34, i32 255, i32 256)
%57 = call i32 @delay(i32 250)
%58 = call i32 @memset(i32* %34, i32 0, i32 256)
%59 = call i32 @delay(i32 250)
%60 = call i32 @memset(i32* %34, i32 255, i32 256)
%61 = call i32 @delay(i32 250)
%62 = call i32 @memset(i32* %34, i32 0, i32 256)
%63 = call i32 @delay(i32 250)
%64 = call i32 @memset(i32* %34, i32 0, i32 256)
%65 = call i32 @munmap(i32* %34, i32 256)
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %69
67: ; preds = %50
%68 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
br label %69
69: ; preds = %67, %50
%70 = call i32 @close(i32 %4)
ret i32 0
}