#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;
};

/* Variables and functions */
int /*<<< orphan*/ FBIOGET_VSCREENINFO;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct fb_var_screeninfo *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int fbfd = 0;
  struct fb_var_screeninfo var_info;
  fbfd = open("/dev/fb1", O_RDWR);
  if (fbfd == -1) {
    printf("Error: cannot open framebuffer device.\n");
    return (1);
  }
  printf("The framebuffer device opened.\n");
  if (ioctl(fbfd, FBIOGET_VSCREENINFO, &var_info)) {
    printf("Error reading variable screen info.\n");
  }
  printf("Display info %dx%d, %d bpp\n", var_info.xres, var_info.yres,
         var_info.bits_per_pixel);
  close(fbfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
lea    0xe93(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1199 <main+0x59>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fa <main+0xba>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
je     11d4 <main+0x94>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    0xe9a(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11c9 <main+0x79>
mov    %eax,%ebx
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1050 <ioctl@plt>
test   %rax,%rax
je     11a4 <main+0x54>
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
mov    0x10(%rsp),%ecx
lea    0xe52(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
jmp    11da <main+0x8a>
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.fb_var_screeninfo = type { i32, i32, i32 }
@.str = [9 x i8] c"/dev/fb1\00"
@O_RDWR = global i32 0
@.str.1 = [40 x i8] c"Error: cannot open framebuffer device.\0A\00"
@.str.2 = [32 x i8] c"The framebuffer device opened.\0A\00"
@FBIOGET_VSCREENINFO = global i32 0
@.str.3 = [37 x i8] c"Error reading variable screen info.\0A\00"
@.str.4 = [28 x i8] c"Display info %dx%d, %d bpp\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.fb_var_screeninfo
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %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* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %32
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32, i32* %6
%17 = load i32, i32* @FBIOGET_VSCREENINFO
%18 = call i64 @ioctl(i32 %16, i32 %17, %struct.fb_var_screeninfo* %7)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %14
%23 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %7, i32 0, i32 0
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %7, i32 0, i32 1
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %7, i32 0, i32 2
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %24, i32 %26, i32 %28)
%30 = load i32, i32* %6
%31 = call i32 @close(i32 %30)
store i32 0, i32* %3
br label %32
32: ; preds = %22, %12
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
%struct.fb_var_screeninfo = type { i32, i32, i32 }
@.str = [9 x i8] c"/dev/fb1\00"
@O_RDWR = global i32 0
@FBIOGET_VSCREENINFO = global i32 0
@.str.4 = [28 x i8] c"Display info %dx%d, %d bpp\0A\00"
@str = [31 x i8] c"The framebuffer device opened.\00"
@str.5 = [36 x i8] c"Error reading variable screen info.\00"
@str.6 = [39 x i8] c"Error: cannot open framebuffer device.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.fb_var_screeninfo
%4 = bitcast %struct.fb_var_screeninfo* %3 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, -1
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.6, i64 0, i64 0))
br label %26
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%12 = load i32, i32* @FBIOGET_VSCREENINFO
%13 = call i64 @ioctl(i32 %6, i32 %12, %struct.fb_var_screeninfo* %3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %10
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.5, i64 0, i64 0))
br label %17
17: ; preds = %15, %10
%18 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %3, i64 0, i32 0
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %3, i64 0, i32 1
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %3, i64 0, i32 2
%23 = load i32, i32* %22
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %19, i32 %21, i32 %23)
%25 = call i32 @close(i32 %6)
br label %26
26: ; preds = %17, %8
%27 = phi i32 [ 1, %8 ], [ 0, %17 ]
ret i32 %27
}