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

/* 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;
unsigned char atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputs(int /*<<< orphan*/, char *);
int ioctl(int, int /*<<< orphan*/, struct fb_var_screeninfo *);
scalar_t__ mmap(int /*<<< orphan*/, unsigned long, int, int /*<<< orphan*/, int,
                int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, unsigned long);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc != 6) {
    fprintf(stderr, "usage: %s /dev/fbX <blue> <green> <red> <alpha>\n",
            argv[0]);
    return 1;
  }
  int fbfd = open(argv[1], O_RDWR);
  if (fbfd == -1) {
    perror("Error: cannot open framebuffer device");
    return 2;
  }
  puts("The framebuffer device was opened successfully");
  struct fb_fix_screeninfo finfo;
  if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) {
    perror("Error reading fixed information");
    return 3;
  }
  struct fb_var_screeninfo vinfo;
  if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
    perror("Error reading variable information");
    return 4;
  }
  printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
  if (vinfo.xres == 0 || vinfo.yres == 0 || vinfo.bits_per_pixel == 0) {
    fputs(stderr, "Invalid framebuffer info, exiting");
    return 5;
  }
  unsigned long int screensize =
      vinfo.xres * vinfo.yres * (vinfo.bits_per_pixel / 8);
  char *fbp =
      (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
  if ((int)fbp == -1) {
    perror("Error: failed to map framebuffer device to memory");
    return 6;
  }
  puts("The framebuffer device was mapped to memory successfully");
  size_t x, y;
  unsigned int value;
  unsigned char blue = atoi(argv[2]), green = atoi(argv[3]),
                red = atoi(argv[4]), alpha = atoi(argv[5]);
  if (vinfo.bits_per_pixel == 32) {
    value = alpha << 24 | red << 16 | green << 8 | blue;
  }
  if (vinfo.bits_per_pixel == 16) {
    value = ((red >> 3) << 11) | ((green >> 2) << 5) | (blue >> 3);
  }
  for (y = 0; y < vinfo.yres; ++y) {
    for (x = 0; x < vinfo.xres; ++x) {
      long int location = (x + vinfo.xoffset) * (vinfo.bits_per_pixel / 8) +
                          (y + vinfo.yoffset) * finfo.line_length;
      if (vinfo.bits_per_pixel == 32) {
        *((unsigned int *)(fbp + location)) = value;
      }
      if (vinfo.bits_per_pixel == 16) {
        *((unsigned short *)(fbp + location)) = value;
      }
    }
  }
  munmap(fbp, screensize);
  close(fbfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x6,-0x8(%rbp)
je     11fb <main+0x4b>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe16(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1557 <main+0x3a7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1236 <main+0x86>
lea    0xe0c(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1557 <main+0x3a7>
lea    0xe1a(%rip),%rdi
call   1030 <puts@plt>
mov    -0x14(%rbp),%edi
mov    0x2d7c(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1278 <main+0xc8>
lea    0xe1f(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x3,-0x4(%rbp)
jmp    1557 <main+0x3a7>
mov    -0x14(%rbp),%edi
mov    0x2d2e(%rip),%rax
mov    (%rax),%esi
lea    -0x68(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    12ae <main+0xfe>
lea    0xe09(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x4,-0x4(%rbp)
jmp    1557 <main+0x3a7>
mov    -0x68(%rbp),%esi
mov    -0x64(%rbp),%edx
mov    -0x60(%rbp),%ecx
lea    0xe0b(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0x0,-0x68(%rbp)
je     12e1 <main+0x131>
cmpl   $0x0,-0x64(%rbp)
je     12e1 <main+0x131>
cmpl   $0x0,-0x60(%rbp)
jne    1302 <main+0x152>
mov    0x2cd8(%rip),%rax
mov    (%rax),%edi
lea    0xde6(%rip),%rsi
call   1060 <fputs@plt>
movl   $0x5,-0x4(%rbp)
jmp    1557 <main+0x3a7>
mov    -0x68(%rbp),%eax
imul   -0x64(%rbp),%eax
mov    %eax,-0x9c(%rbp)
mov    -0x60(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x9c(%rbp),%eax
imul   %ecx,%eax
cltq
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rsi
mov    0x2cc2(%rip),%rax
mov    (%rax),%edx
mov    0x2c79(%rip),%rax
or     (%rax),%edx
mov    0x2ca0(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
cmp    $0xffffffff,%eax
jne    1382 <main+0x1d2>
lea    0xd88(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x6,-0x4(%rbp)
jmp    1557 <main+0x3a7>
lea    0xda2(%rip),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <atoi@plt>
mov    %al,-0x8d(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10d0 <atoi@plt>
mov    %al,-0x8e(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10d0 <atoi@plt>
mov    %al,-0x8f(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   10d0 <atoi@plt>
mov    %al,-0x90(%rbp)
cmpl   $0x20,-0x60(%rbp)
jne    1415 <main+0x265>
movzbl -0x90(%rbp),%eax
shl    $0x18,%eax
movzbl -0x8f(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
movzbl -0x8e(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
movzbl -0x8d(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x8c(%rbp)
cmpl   $0x10,-0x60(%rbp)
jne    144d <main+0x29d>
movzbl -0x8f(%rbp),%eax
sar    $0x3,%eax
shl    $0xb,%eax
movzbl -0x8e(%rbp),%ecx
sar    $0x2,%ecx
shl    $0x5,%ecx
or     %ecx,%eax
movzbl -0x8d(%rbp),%ecx
sar    $0x3,%ecx
or     %ecx,%eax
mov    %eax,-0x8c(%rbp)
movq   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%rax
movslq -0x64(%rbp),%rcx
cmp    %rcx,%rax
jae    153b <main+0x38b>
movq   $0x0,-0x80(%rbp)
mov    -0x80(%rbp),%rax
movslq -0x68(%rbp),%rcx
cmp    %rcx,%rax
jae    151f <main+0x36f>
mov    -0x80(%rbp),%rax
add    -0x58(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x60(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0xa8(%rbp),%rax
movslq %ecx,%rcx
imul   %rcx,%rax
mov    -0x88(%rbp),%rcx
add    -0x50(%rbp),%rcx
imul   -0x20(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x98(%rbp)
cmpl   $0x20,-0x60(%rbp)
jne    14e7 <main+0x337>
mov    -0x8c(%rbp),%edx
mov    -0x78(%rbp),%rax
mov    -0x98(%rbp),%rcx
mov    %edx,(%rax,%rcx,1)
cmpl   $0x10,-0x60(%rbp)
jne    1509 <main+0x359>
mov    -0x8c(%rbp),%eax
mov    %ax,%dx
mov    -0x78(%rbp),%rax
mov    -0x98(%rbp),%rcx
mov    %dx,(%rax,%rcx,1)
jmp    150e <main+0x35e>
mov    -0x80(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x80(%rbp)
jmp    1474 <main+0x2c4>
jmp    1524 <main+0x374>
mov    -0x88(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x88(%rbp)
jmp    1458 <main+0x2a8>
mov    -0x78(%rbp),%rdi
mov    -0x70(%rbp),%rsi
call   10a0 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%rbp
cmp    $0x6,%edi
jne    132d <main+0x17d>
mov    0x8(%rbp),%rdi
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     1455 <main+0x2a5>
mov    %eax,%r15d
lea    0xe68(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
lea    0x40(%rsp),%rdx
mov    %r15d,%edi
call   1070 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1468 <main+0x2b8>
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %r15d,%edi
call   1070 <ioctl@plt>
cmp    $0xffffffff,%eax
je     147b <main+0x2cb>
mov    0x10(%rsp),%esi
mov    0x14(%rsp),%edx
mov    0x18(%rsp),%ecx
lea    0xe84(%rip),%rdi
call   1050 <printf@plt>
mov    0x10(%rsp),%ecx
test   %ecx,%ecx
je     1350 <main+0x1a0>
mov    0x14(%rsp),%eax
test   %eax,%eax
je     1350 <main+0x1a0>
mov    0x18(%rsp),%edx
test   %edx,%edx
je     1350 <main+0x1a0>
imul   %ecx,%eax
lea    0x7(%rdx),%ecx
test   %edx,%edx
cmovns %edx,%ecx
sar    $0x3,%ecx
imul   %eax,%ecx
movslq %ecx,%r14
mov    0x2d6f(%rip),%rax
mov    0x2d28(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d4d(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r14,%rsi
mov    %r15d,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%r13
cmp    $0xffffffff,%r13d
je     148e <main+0x2de>
mov    %r14,0x38(%rsp)
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %al,0xf(%rsp)
mov    0x18(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %eax,%ebx
mov    0x20(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %eax,%r14d
mov    0x18(%rsp),%r12d
cmp    $0x10,%r12d
je     136f <main+0x1bf>
cmp    $0x20,%r12d
jne    1391 <main+0x1e1>
mov    0x28(%rbp),%rdi
call   10d0 <atoi@plt>
movzbl %al,%eax
shl    $0x18,%eax
movzbl %r14b,%ecx
shl    $0x10,%ecx
or     %eax,%ecx
movzbl %bl,%edx
shl    $0x8,%edx
or     %ecx,%edx
movzbl 0xf(%rsp),%eax
or     %edx,%eax
jmp    1391 <main+0x1e1>
mov    0x2c8c(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xcbf(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%eax
jmp    1446 <main+0x296>
mov    0x2c69(%rip),%rax
mov    (%rax),%edi
lea    0xd77(%rip),%rsi
call   1060 <fputs@plt>
mov    $0x5,%eax
jmp    1446 <main+0x296>
shr    $0x3,%r14b
movzbl %r14b,%eax
shl    $0xb,%eax
shr    $0x2,%bl
movzbl %bl,%ecx
shl    $0x5,%ecx
or     %eax,%ecx
mov    0xf(%rsp),%al
shr    $0x3,%al
movzbl %al,%eax
or     %ecx,%eax
mov    0x14(%rsp),%ebp
test   %ebp,%ebp
mov    0x38(%rsp),%rsi
je     1434 <main+0x284>
mov    0x20(%rsp),%rcx
mov    0x28(%rsp),%r8
mov    0x60(%rsp),%r9
mov    0x10(%rsp),%edx
xor    %r10d,%r10d
jmp    13d0 <main+0x220>
nopw   0x0(%rax,%rax,1)
mov    0x14(%rsp),%ebp
add    $0x1,%r10
movslq %ebp,%rdi
cmp    %rdi,%r10
jae    1434 <main+0x284>
test   %edx,%edx
je     1430 <main+0x280>
lea    (%r8,%r10,1),%rbp
imul   %r9,%rbp
xor    %ebx,%ebx
jmp    13ee <main+0x23e>
add    $0x1,%rbx
movslq 0x10(%rsp),%rdx
cmp    %rdx,%rbx
jae    13c0 <main+0x210>
lea    (%rcx,%rbx,1),%rdi
lea    0x7(%r12),%edx
test   %r12d,%r12d
cmovns %r12d,%edx
sar    $0x3,%edx
movslq %edx,%rdx
imul   %rdi,%rdx
add    %rbp,%rdx
cmp    $0x20,%r12d
jne    141b <main+0x26b>
mov    %eax,0x0(%r13,%rdx,1)
mov    0x18(%rsp),%r12d
cmp    $0x10,%r12d
jne    13e0 <main+0x230>
mov    %ax,0x0(%r13,%rdx,1)
jmp    13e0 <main+0x230>
nopl   0x0(%rax)
xor    %edx,%edx
jmp    13c4 <main+0x214>
mov    %r13,%rdi
call   10a0 <munmap@plt>
mov    %r15d,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbd5(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x2,%eax
jmp    1446 <main+0x296>
lea    0xc17(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x3,%eax
jmp    1446 <main+0x296>
lea    0xc24(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x4,%eax
jmp    1446 <main+0x296>
lea    0xc64(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x6,%eax
jmp    1446 <main+0x296>

LLVM IR (-O0):
%struct.fb_fix_screeninfo = type { i32, i32, i32, i64, i64, i64 }
%struct.fb_var_screeninfo = type { i32, i32, i32, i64, i64, i64 }
@stderr = global i32 0
@.str = [49 x i8] c"usage: %s /dev/fbX <blue> <green> <red> <alpha>\0A\00"
@O_RDWR = global i32 0
@.str.1 = [38 x i8] c"Error: cannot open framebuffer device\00"
@.str.2 = [47 x i8] c"The framebuffer device was opened successfully\00"
@FBIOGET_FSCREENINFO = global i32 0
@.str.3 = [32 x i8] c"Error reading fixed information\00"
@FBIOGET_VSCREENINFO = global i32 0
@.str.4 = [35 x i8] c"Error reading variable information\00"
@.str.5 = [14 x i8] c"%dx%d, %dbpp\0A\00"
@.str.6 = [34 x i8] c"Invalid framebuffer info, exiting\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.7 = [50 x i8] c"Error: failed to map framebuffer device to memory\00"
@.str.8 = [57 x i8] c"The framebuffer device was mapped to memory successfully\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.fb_fix_screeninfo
%8 = alloca %struct.fb_var_screeninfo
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
%14 = alloca i8
%15 = alloca i8
%16 = alloca i8
%17 = alloca i8
%18 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 6
br i1 %20, label %21, label %27
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %25)
store i32 1, i32* %3
br label %219
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = load i32, i32* @O_RDWR
%32 = call i32 @open(i8* %30, i32 %31)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %27
%36 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %219
37: ; preds = %27
%38 = call i32 @puts(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* %6
%40 = load i32, i32* @FBIOGET_FSCREENINFO
%41 = bitcast %struct.fb_fix_screeninfo* %7 to %struct.fb_var_screeninfo*
%42 = call i32 @ioctl(i32 %39, i32 %40, %struct.fb_var_screeninfo* %41)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %37
%45 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
store i32 3, i32* %3
br label %219
46: ; preds = %37
%47 = load i32, i32* %6
%48 = load i32, i32* @FBIOGET_VSCREENINFO
%49 = call i32 @ioctl(i32 %47, i32 %48, %struct.fb_var_screeninfo* %8)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %46
%52 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
store i32 4, i32* %3
br label %219
53: ; preds = %46
%54 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %8, i32 0, i32 0
%55 = load i32, i32* %54
%56 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %8, i32 0, i32 1
%57 = load i32, i32* %56
%58 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %8, i32 0, i32 2
%59 = load i32, i32* %58
%60 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %55, i32 %57, i32 %59)
%61 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %8, i32 0, i32 0
%62 = load i32, i32* %61
%63 = icmp eq i32 %62, 0
br i1 %63, label %72, label %64
64: ; preds = %53
%65 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %8, i32 0, i32 1
%66 = load i32, i32* %65
%67 = icmp eq i32 %66, 0
br i1 %67, label %72, label %68
68: ; preds = %64
%69 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %8, i32 0, i32 2
%70 = load i32, i32* %69
%71 = icmp eq i32 %70, 0
br i1 %71, label %72, label %75
72: ; preds = %68, %64, %53
%73 = load i32, i32* @stderr
%74 = call i32 @fputs(i32 %73, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
store i32 5, i32* %3
br label %219
75: ; preds = %68
%76 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %8, i32 0, i32 0
%77 = load i32, i32* %76
%78 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %8, i32 0, i32 1
%79 = load i32, i32* %78
%80 = mul nsw i32 %77, %79
%81 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %8, i32 0, i32 2
%82 = load i32, i32* %81
%83 = sdiv i32 %82, 8
%84 = mul nsw i32 %80, %83
%85 = sext i32 %84 to i64
store i64 %85, i64* %9
%86 = load i64, i64* %9
%87 = load i32, i32* @PROT_READ
%88 = load i32, i32* @PROT_WRITE
%89 = or i32 %87, %88
%90 = load i32, i32* @MAP_SHARED
%91 = load i32, i32* %6
%92 = call i64 @mmap(i32 0, i64 %86, i32 %89, i32 %90, i32 %91, i32 0)
%93 = inttoptr i64 %92 to i8*
store i8* %93, i8** %10
%94 = load i8*, i8** %10
%95 = ptrtoint i8* %94 to i32
%96 = icmp eq i32 %95, -1
br i1 %96, label %97, label %99
97: ; preds = %75
%98 = call i32 @perror(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.7, i64 0, i64 0))
store i32 6, i32* %3
br label %219
99: ; preds = %75
%100 = call i32 @puts(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.8, i64 0, i64 0))
%101 = load i8**, i8*** %5
%102 = getelementptr inbounds i8*, i8** %101, i64 2
%103 = load i8*, i8** %102
%104 = call zeroext i8 @atoi(i8* %103)
store i8 %104, i8* %14
%105 = load i8**, i8*** %5
%106 = getelementptr inbounds i8*, i8** %105, i64 3
%107 = load i8*, i8** %106
%108 = call zeroext i8 @atoi(i8* %107)
store i8 %108, i8* %15
%109 = load i8**, i8*** %5
%110 = getelementptr inbounds i8*, i8** %109, i64 4
%111 = load i8*, i8** %110
%112 = call zeroext i8 @atoi(i8* %111)
store i8 %112, i8* %16
%113 = load i8**, i8*** %5
%114 = getelementptr inbounds i8*, i8** %113, i64 5
%115 = load i8*, i8** %114
%116 = call zeroext i8 @atoi(i8* %115)
store i8 %116, i8* %17
%117 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %8, i32 0, i32 2
%118 = load i32, i32* %117
%119 = icmp eq i32 %118, 32
br i1 %119, label %120, label %135
120: ; preds = %99
%121 = load i8, i8* %17
%122 = zext i8 %121 to i32
%123 = shl i32 %122, 24
%124 = load i8, i8* %16
%125 = zext i8 %124 to i32
%126 = shl i32 %125, 16
%127 = or i32 %123, %126
%128 = load i8, i8* %15
%129 = zext i8 %128 to i32
%130 = shl i32 %129, 8
%131 = or i32 %127, %130
%132 = load i8, i8* %14
%133 = zext i8 %132 to i32
%134 = or i32 %131, %133
store i32 %134, i32* %13
br label %135
135: ; preds = %120, %99
%136 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %8, i32 0, i32 2
%137 = load i32, i32* %136
%138 = icmp eq i32 %137, 16
br i1 %138, label %139, label %153
139: ; preds = %135
%140 = load i8, i8* %16
%141 = zext i8 %140 to i32
%142 = ashr i32 %141, 3
%143 = shl i32 %142, 11
%144 = load i8, i8* %15
%145 = zext i8 %144 to i32
%146 = ashr i32 %145, 2
%147 = shl i32 %146, 5
%148 = or i32 %143, %147
%149 = load i8, i8* %14
%150 = zext i8 %149 to i32
%151 = ashr i32 %150, 3
%152 = or i32 %148, %151
store i32 %152, i32* %13
br label %153
153: ; preds = %139, %135
store i64 0, i64* %12
br label %154
154: ; preds = %210, %153
%155 = load i64, i64* %12
%156 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %8, i32 0, i32 1
%157 = load i32, i32* %156
%158 = sext i32 %157 to i64
%159 = icmp ult i64 %155, %158
br i1 %159, label %160, label %213
160: ; preds = %154
store i64 0, i64* %11
br label %161
161: ; preds = %206, %160
%162 = load i64, i64* %11
%163 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %8, i32 0, i32 0
%164 = load i32, i32* %163
%165 = sext i32 %164 to i64
%166 = icmp ult i64 %162, %165
br i1 %166, label %167, label %209
167: ; preds = %161
%168 = load i64, i64* %11
%169 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %8, i32 0, i32 3
%170 = load i64, i64* %169
%171 = add i64 %168, %170
%172 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %8, i32 0, i32 2
%173 = load i32, i32* %172
%174 = sdiv i32 %173, 8
%175 = sext i32 %174 to i64
%176 = mul i64 %171, %175
%177 = load i64, i64* %12
%178 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %8, i32 0, i32 4
%179 = load i64, i64* %178
%180 = add i64 %177, %179
%181 = getelementptr inbounds %struct.fb_fix_screeninfo, %struct.fb_fix_screeninfo* %7, i32 0, i32 5
%182 = load i64, i64* %181
%183 = mul i64 %180, %182
%184 = add i64 %176, %183
store i64 %184, i64* %18
%185 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %8, i32 0, i32 2
%186 = load i32, i32* %185
%187 = icmp eq i32 %186, 32
br i1 %187, label %188, label %194
188: ; preds = %167
%189 = load i32, i32* %13
%190 = load i8*, i8** %10
%191 = load i64, i64* %18
%192 = getelementptr inbounds i8, i8* %190, i64 %191
%193 = bitcast i8* %192 to i32*
store i32 %189, i32* %193
br label %194
194: ; preds = %188, %167
%195 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %8, i32 0, i32 2
%196 = load i32, i32* %195
%197 = icmp eq i32 %196, 16
br i1 %197, label %198, label %205
198: ; preds = %194
%199 = load i32, i32* %13
%200 = trunc i32 %199 to i16
%201 = load i8*, i8** %10
%202 = load i64, i64* %18
%203 = getelementptr inbounds i8, i8* %201, i64 %202
%204 = bitcast i8* %203 to i16*
store i16 %200, i16* %204
br label %205
205: ; preds = %198, %194
br label %206
206: ; preds = %205
%207 = load i64, i64* %11
%208 = add i64 %207, 1
store i64 %208, i64* %11
br label %161
209: ; preds = %161
br label %210
210: ; preds = %209
%211 = load i64, i64* %12
%212 = add i64 %211, 1
store i64 %212, i64* %12
br label %154
213: ; preds = %154
%214 = load i8*, i8** %10
%215 = load i64, i64* %9
%216 = call i32 @munmap(i8* %214, i64 %215)
%217 = load i32, i32* %6
%218 = call i32 @close(i32 %217)
store i32 0, i32* %3
br label %219
219: ; preds = %213, %97, %72, %51, %44, %35, %21
%220 = load i32, i32* %3
ret i32 %220
}

LLVM IR (-O2):
%struct.fb_fix_screeninfo = type { i32, i32, i32, i64, i64, i64 }
%struct.fb_var_screeninfo = type { i32, i32, i32, i64, i64, i64 }
@stderr = global i32 0
@.str = [49 x i8] c"usage: %s /dev/fbX <blue> <green> <red> <alpha>\0A\00"
@O_RDWR = global i32 0
@.str.1 = [38 x i8] c"Error: cannot open framebuffer device\00"
@.str.2 = [47 x i8] c"The framebuffer device was opened successfully\00"
@FBIOGET_FSCREENINFO = global i32 0
@.str.3 = [32 x i8] c"Error reading fixed information\00"
@FBIOGET_VSCREENINFO = global i32 0
@.str.4 = [35 x i8] c"Error reading variable information\00"
@.str.5 = [14 x i8] c"%dx%d, %dbpp\0A\00"
@.str.6 = [34 x i8] c"Invalid framebuffer info, exiting\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.7 = [50 x i8] c"Error: failed to map framebuffer device to memory\00"
@.str.8 = [57 x i8] c"The framebuffer device was mapped to memory successfully\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.fb_fix_screeninfo
%4 = alloca %struct.fb_var_screeninfo
%5 = icmp eq i32 %0, 6
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %170
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDWR
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = tail call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %170
18: ; preds = %10
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
%20 = bitcast %struct.fb_fix_screeninfo* %3 to i8*
%21 = load i32, i32* @FBIOGET_FSCREENINFO
%22 = bitcast %struct.fb_fix_screeninfo* %3 to %struct.fb_var_screeninfo*
%23 = call i32 @ioctl(i32 %14, i32 %21, %struct.fb_var_screeninfo* %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %168
27: ; preds = %18
%28 = bitcast %struct.fb_var_screeninfo* %4 to i8*
%29 = load i32, i32* @FBIOGET_VSCREENINFO
%30 = call i32 @ioctl(i32 %14, i32 %29, %struct.fb_var_screeninfo* %4)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %166
34: ; preds = %27
%35 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %4, i64 0, i32 0
%36 = load i32, i32* %35
%37 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %4, i64 0, i32 1
%38 = load i32, i32* %37
%39 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %4, i64 0, i32 2
%40 = load i32, i32* %39
%41 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %36, i32 %38, i32 %40)
%42 = load i32, i32* %35
%43 = icmp eq i32 %42, 0
%44 = load i32, i32* %37
%45 = icmp eq i32 %44, 0
%46 = select i1 %43, i1 true, i1 %45
%47 = load i32, i32* %39
%48 = icmp eq i32 %47, 0
%49 = select i1 %46, i1 true, i1 %48
br i1 %49, label %50, label %53
50: ; preds = %34
%51 = load i32, i32* @stderr
%52 = call i32 @fputs(i32 %51, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
br label %166
53: ; preds = %34
%54 = mul nsw i32 %44, %42
%55 = sdiv i32 %47, 8
%56 = mul nsw i32 %54, %55
%57 = sext i32 %56 to i64
%58 = load i32, i32* @PROT_READ
%59 = load i32, i32* @PROT_WRITE
%60 = or i32 %59, %58
%61 = load i32, i32* @MAP_SHARED
%62 = call i64 @mmap(i32 0, i64 %57, i32 %60, i32 %61, i32 %14, i32 0)
%63 = inttoptr i64 %62 to i8*
%64 = trunc i64 %62 to i32
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %68
66: ; preds = %53
%67 = call i32 @perror(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.7, i64 0, i64 0))
br label %166
68: ; preds = %53
%69 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.8, i64 0, i64 0))
%70 = getelementptr inbounds i8*, i8** %1, i64 2
%71 = load i8*, i8** %70
%72 = call zeroext i8 @atoi(i8* %71)
%73 = getelementptr inbounds i8*, i8** %1, i64 3
%74 = load i8*, i8** %73
%75 = call zeroext i8 @atoi(i8* %74)
%76 = getelementptr inbounds i8*, i8** %1, i64 4
%77 = load i8*, i8** %76
%78 = call zeroext i8 @atoi(i8* %77)
%79 = load i32, i32* %39
switch i32 %79, label %105 [
i32 32, label %80
i32 16, label %94
]
80: ; preds = %68
%81 = getelementptr inbounds i8*, i8** %1, i64 5
%82 = load i8*, i8** %81
%83 = call zeroext i8 @atoi(i8* %82)
%84 = zext i8 %83 to i32
%85 = shl nuw i32 %84, 24
%86 = zext i8 %78 to i32
%87 = shl nuw nsw i32 %86, 16
%88 = or i32 %85, %87
%89 = zext i8 %75 to i32
%90 = shl nuw nsw i32 %89, 8
%91 = or i32 %88, %90
%92 = zext i8 %72 to i32
%93 = or i32 %91, %92
br label %105
94: ; preds = %68
%95 = lshr i8 %78, 3
%96 = zext i8 %95 to i32
%97 = shl nuw nsw i32 %96, 11
%98 = lshr i8 %75, 2
%99 = zext i8 %98 to i32
%100 = shl nuw nsw i32 %99, 5
%101 = or i32 %97, %100
%102 = lshr i8 %72, 3
%103 = zext i8 %102 to i32
%104 = or i32 %101, %103
br label %105
105: ; preds = %68, %80, %94
%106 = phi i32 [ %104, %94 ], [ %93, %80 ], [ undef, %68 ]
%107 = load i32, i32* %37
%108 = icmp eq i32 %107, 0
br i1 %108, label %163, label %109
109: ; preds = %105
%110 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %4, i64 0, i32 3
%111 = load i64, i64* %110
%112 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %4, i64 0, i32 4
%113 = load i64, i64* %112
%114 = getelementptr inbounds %struct.fb_fix_screeninfo, %struct.fb_fix_screeninfo* %3, i64 0, i32 5
%115 = load i64, i64* %114
%116 = trunc i32 %106 to i16
%117 = load i32, i32* %35
br label %118
118: ; preds = %109, %155
%119 = phi i32 [ %107, %109 ], [ %156, %155 ]
%120 = phi i32 [ %79, %109 ], [ %157, %155 ]
%121 = phi i32 [ %79, %109 ], [ %158, %155 ]
%122 = phi i32 [ %117, %109 ], [ %159, %155 ]
%123 = phi i64 [ 0, %109 ], [ %160, %155 ]
%124 = icmp eq i32 %122, 0
br i1 %124, label %155, label %125
125: ; preds = %118
%126 = add i64 %113, %123
%127 = mul i64 %126, %115
br label %128
128: ; preds = %125, %148
%129 = phi i32 [ %120, %125 ], [ %143, %148 ]
%130 = phi i32 [ %121, %125 ], [ %143, %148 ]
%131 = phi i64 [ 0, %125 ], [ %149, %148 ]
%132 = add i64 %111, %131
%133 = sdiv i32 %130, 8
%134 = sext i32 %133 to i64
%135 = mul i64 %132, %134
%136 = add i64 %135, %127
%137 = icmp eq i32 %130, 32
br i1 %137, label %138, label %142
138: ; preds = %128
%139 = getelementptr inbounds i8, i8* %63, i64 %136
%140 = bitcast i8* %139 to i32*
store i32 %106, i32* %140
%141 = load i32, i32* %39
br label %142
142: ; preds = %138, %128
%143 = phi i32 [ %141, %138 ], [ %129, %128 ]
%144 = icmp eq i32 %143, 16
br i1 %144, label %145, label %148
145: ; preds = %142
%146 = getelementptr inbounds i8, i8* %63, i64 %136
%147 = bitcast i8* %146 to i16*
store i16 %116, i16* %147
br label %148
148: ; preds = %145, %142
%149 = add nuw i64 %131, 1
%150 = load i32, i32* %35
%151 = sext i32 %150 to i64
%152 = icmp ult i64 %149, %151
br i1 %152, label %128, label %153
153: ; preds = %148
%154 = load i32, i32* %37
br label %155
155: ; preds = %153, %118
%156 = phi i32 [ %154, %153 ], [ %119, %118 ]
%157 = phi i32 [ %143, %153 ], [ %120, %118 ]
%158 = phi i32 [ %143, %153 ], [ %121, %118 ]
%159 = phi i32 [ %150, %153 ], [ 0, %118 ]
%160 = add nuw i64 %123, 1
%161 = sext i32 %156 to i64
%162 = icmp ult i64 %160, %161
br i1 %162, label %118, label %163
163: ; preds = %155, %105
%164 = call i32 @munmap(i8* %63, i64 %57)
%165 = call i32 @close(i32 %14)
br label %166
166: ; preds = %66, %163, %50, %32
%167 = phi i32 [ 4, %32 ], [ 5, %50 ], [ 6, %66 ], [ 0, %163 ]
br label %168
168: ; preds = %166, %25
%169 = phi i32 [ 3, %25 ], [ %167, %166 ]
br label %170
170: ; preds = %16, %168, %6
%171 = phi i32 [ 1, %6 ], [ 2, %16 ], [ %169, %168 ]
ret i32 %171
}