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

/* Variables and functions */
int /*<<< orphan*/ FBIOGET_VSCREENINFO;
int /*<<< orphan*/ FBIOPAN_DISPLAY;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ PRIO_PROCESS;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct fb_var_screeninfo *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ setpriority(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  int ret = 0;
  struct fb_var_screeninfo var;
  int fd = open("/dev/fb0", O_RDWR);
  setpriority(PRIO_PROCESS, 0, -20);
  assert(fd >= 0);
  assert(ioctl(fd, FBIOGET_VSCREENINFO, &var) >= 0);
  if (argc > 1 && !strcmp(argv[1], "--loop")) {
    while (1) {
      ioctl(fd, FBIOPAN_DISPLAY, &var);
      usleep(16666);
    }
    perror("Failed FBIOPAN_DISPLAY");
    ret = 1;
  } else if (ioctl(fd, FBIOPAN_DISPLAY, &var) < 0) {
    perror("Failed FBIOPAN_DISPLAY");
    ret = 1;
  }
  close(fd);
  return ret;
}


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    0x2e44(%rip),%rax
mov    (%rax),%esi
lea    0xe53(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
mov    $0xffffffec,%edx
call   1030 <setpriority@plt>
cmpl   $0x0,-0x1c(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x1c(%rbp),%edi
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
cmpl   $0x1,-0x8(%rbp)
jle    1251 <main+0xd1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdef(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1251 <main+0xd1>
jmp    122d <main+0xad>
mov    -0x1c(%rbp),%edi
mov    0x2da1(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
mov    $0x411a,%edi
call   10a0 <usleep@plt>
jmp    122d <main+0xad>
mov    -0x1c(%rbp),%edi
mov    0x2d7d(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1283 <main+0x103>
lea    0xd99(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x14(%rbp)
jmp    1288 <main+0x108>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
lea    0xe5f(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%r12d
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
xor    %r15d,%r15d
xor    %esi,%esi
mov    $0xffffffec,%edx
call   1030 <setpriority@plt>
mov    %r12d,%edi
not    %edi
shr    $0x1f,%edi
call   1070 <assert@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %r12d,%edi
call   1040 <ioctl@plt>
shr    $0x3f,%rax
xor    $0x1,%eax
mov    %eax,%edi
call   1070 <assert@plt>
cmp    $0x2,%ebp
jl     120b <main+0x8b>
mov    0x8(%r14),%rdi
lea    0xe07(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     123e <main+0xbe>
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %r12d,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
js     1269 <main+0xe9>
mov    %r12d,%edi
call   1050 <close@plt>
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d93(%rip),%rbx
lea    0x8(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    (%rbx),%esi
mov    %r12d,%edi
mov    %rbp,%rdx
call   1040 <ioctl@plt>
mov    $0x411a,%edi
call   10a0 <usleep@plt>
jmp    1250 <main+0xd0>
lea    0xda0(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%r15d
jmp    1226 <main+0xa6>

LLVM IR (-O0):
%struct.fb_var_screeninfo = type { i32 }
@.str = [9 x i8] c"/dev/fb0\00"
@O_RDWR = global i32 0
@PRIO_PROCESS = global i32 0
@FBIOGET_VSCREENINFO = global i32 0
@.str.1 = [7 x i8] c"--loop\00"
@FBIOPAN_DISPLAY = global i32 0
@.str.2 = [23 x i8] c"Failed FBIOPAN_DISPLAY\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
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%9 = load i32, i32* @O_RDWR
%10 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %8
%11 = load i32, i32* @PRIO_PROCESS
%12 = call i32 @setpriority(i32 %11, i32 0, i32 -20)
%13 = load i32, i32* %8
%14 = icmp sge i32 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i32, i32* %8
%18 = load i32, i32* @FBIOGET_VSCREENINFO
%19 = call i64 @ioctl(i32 %17, i32 %18, %struct.fb_var_screeninfo* %7)
%20 = icmp sge i64 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i32, i32* %4
%24 = icmp sgt i32 %23, 1
br i1 %24, label %25, label %37
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @strcmp(i8* %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp ne i32 %29, 0
br i1 %30, label %37, label %31
31: ; preds = %25
br label %32
32: ; preds = %31, %32
%33 = load i32, i32* %8
%34 = load i32, i32* @FBIOPAN_DISPLAY
%35 = call i64 @ioctl(i32 %33, i32 %34, %struct.fb_var_screeninfo* %7)
%36 = call i32 @usleep(i32 16666)
br label %32
37: ; preds = %25, %2
%38 = load i32, i32* %8
%39 = load i32, i32* @FBIOPAN_DISPLAY
%40 = call i64 @ioctl(i32 %38, i32 %39, %struct.fb_var_screeninfo* %7)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %6
br label %44
44: ; preds = %42, %37
br label %45
45: ; preds = %44
%46 = load i32, i32* %8
%47 = call i32 @close(i32 %46)
%48 = load i32, i32* %6
ret i32 %48
}

LLVM IR (-O2):
%struct.fb_var_screeninfo = type { i32 }
@.str = [9 x i8] c"/dev/fb0\00"
@O_RDWR = global i32 0
@PRIO_PROCESS = global i32 0
@FBIOGET_VSCREENINFO = global i32 0
@.str.1 = [7 x i8] c"--loop\00"
@FBIOPAN_DISPLAY = global i32 0
@.str.2 = [23 x i8] c"Failed FBIOPAN_DISPLAY\00"
define i32 @main(i32 %0, i8** nocapture %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 = load i32, i32* @PRIO_PROCESS
%8 = tail call i32 @setpriority(i32 %7, i32 0, i32 -20)
%9 = xor i32 %6, -1
%10 = lshr i32 %9, 31
%11 = tail call i32 @assert(i32 %10)
%12 = load i32, i32* @FBIOGET_VSCREENINFO
%13 = call i64 @ioctl(i32 %6, i32 %12, %struct.fb_var_screeninfo* %3)
%14 = lshr i64 %13, 63
%15 = trunc i64 %14 to i32
%16 = xor i32 %15, 1
%17 = call i32 @assert(i32 %16)
%18 = icmp sgt i32 %0, 1
br i1 %18, label %19, label %28
19: ; preds = %2
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @strcmp(i8* dereferenceable(1) %21, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %19, %24
%25 = load i32, i32* @FBIOPAN_DISPLAY
%26 = call i64 @ioctl(i32 %6, i32 %25, %struct.fb_var_screeninfo* %3)
%27 = call i32 @usleep(i32 16666)
br label %24
28: ; preds = %19, %2
%29 = load i32, i32* @FBIOPAN_DISPLAY
%30 = call i64 @ioctl(i32 %6, i32 %29, %struct.fb_var_screeninfo* %3)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %28, %32
%35 = phi i32 [ 1, %32 ], [ 0, %28 ]
%36 = call i32 @close(i32 %6)
ret i32 %35
}