#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 */

/* Variables and functions */
int O_NONBLOCK;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int ioctl(int, int, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int main(int argc, char **argv) {
  int fd = open("/dev/fb0", O_WRONLY | O_NONBLOCK);
  int on;
  int res = 0;
  if (argc != 2) {
    printf("You must specify on or off\n");
    return 0;
  }
  on = !strncmp(argv[1], "on", (strlen(argv[1]) > 1 ? 2 : 1));
  printf((on ? "on\n" : "off\n"));
  if (fd) {
    int ioctlnum = 0x4611;
    int vesaMode = on ? 0 : 3;
    res = ioctl(fd, ioctlnum, vesaMode);
    printf("%i\n", res);
    close(fd);
  } else {
    printf("failed\n");
  }
  return res;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
mov    0x2e62(%rip),%rax
or     (%rax),%esi
lea    0xe71(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c2 <main+0x62>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1293 <main+0x133>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%ecx
mov    $0x1,%edx
mov    $0x2,%eax
cmp    $0x1,%ecx
cmovg  %eax,%edx
lea    0xe2d(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
lea    0xe09(%rip),%rdi
lea    0xe0a(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
je     127f <main+0x11f>
movl   $0x4611,-0x20(%rbp)
mov    -0x18(%rbp),%edx
mov    $0x3,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1060 <ioctl@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
jmp    128d <main+0x12d>
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e50(%rip),%rax
mov    0x2e61(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe6e(%rip),%rdi
call   1090 <open@plt>
cmp    $0x2,%ebp
jne    1220 <main+0xb0>
mov    %eax,%r14d
mov    0x8(%rbx),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
xor    %edx,%edx
cmp    $0x2,%eax
setge  %dl
add    $0x1,%edx
lea    0xe48(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strncmp@plt>
mov    %eax,%ebx
test   %eax,%eax
lea    0xe38(%rip),%rax
lea    0xe35(%rip),%rdi
cmove  %rax,%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <printf@plt>
test   %r14d,%r14d
je     1230 <main+0xc0>
xor    %eax,%eax
test   %ebx,%ebx
setne  %al
lea    (%rax,%rax,2),%edx
mov    %r14d,%edi
mov    $0x4611,%esi
call   1070 <ioctl@plt>
mov    %eax,%ebp
lea    0xe08(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14d,%edi
call   1080 <close@plt>
jmp    123c <main+0xcc>
lea    0xdf9(%rip),%rdi
call   1040 <puts@plt>
xor    %ebp,%ebp
jmp    123c <main+0xcc>
lea    0xde2(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/fb0\00"
@O_WRONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [28 x i8] c"You must specify on or off\0A\00"
@.str.2 = [3 x i8] c"on\00"
@.str.3 = [4 x i8] c"on\0A\00"
@.str.4 = [5 x i8] c"off\0A\00"
@.str.5 = [4 x i8] c"%i\0A\00"
@.str.6 = [8 x i8] c"failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @O_WRONLY
%12 = load i32, i32* @O_NONBLOCK
%13 = or i32 %11, %12
%14 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %6
store i32 0, i32* %8
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %58
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @strlen(i8* %25)
%27 = icmp sgt i32 %26, 1
%28 = zext i1 %27 to i64
%29 = select i1 %27, i32 2, i32 1
%30 = call i32 @strncmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = icmp ne i32 %30, 0
%32 = xor i1 %31, true
%33 = zext i1 %32 to i32
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = icmp ne i32 %34, 0
%36 = zext i1 %35 to i64
%37 = select i1 %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
%38 = call i32 (i8*, ...) @printf(i8* %37)
%39 = load i32, i32* %6
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %54
41: ; preds = %19
store i32 17937, i32* %9
%42 = load i32, i32* %7
%43 = icmp ne i32 %42, 0
%44 = zext i1 %43 to i64
%45 = select i1 %43, i32 0, i32 3
store i32 %45, i32* %10
%46 = load i32, i32* %6
%47 = load i32, i32* %9
%48 = load i32, i32* %10
%49 = call i32 @ioctl(i32 %46, i32 %47, i32 %48)
store i32 %49, i32* %8
%50 = load i32, i32* %8
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %50)
%52 = load i32, i32* %6
%53 = call i32 @close(i32 %52)
br label %56
54: ; preds = %19
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %56
56: ; preds = %54, %41
%57 = load i32, i32* %8
store i32 %57, i32* %3
br label %58
58: ; preds = %56, %17
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/fb0\00"
@O_WRONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.2 = [3 x i8] c"on\00"
@.str.3 = [4 x i8] c"on\0A\00"
@.str.4 = [5 x i8] c"off\0A\00"
@.str.5 = [4 x i8] c"%i\0A\00"
@str = [7 x i8] c"failed\00"
@str.7 = [27 x i8] c"You must specify on or off\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @O_WRONLY
%4 = load i32, i32* @O_NONBLOCK
%5 = or i32 %4, %3
%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 %0, 2
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.7, i64 0, i64 0))
br label %28
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @strlen(i8* %12)
%14 = icmp sgt i32 %13, 1
%15 = select i1 %14, i32 2, i32 1
%16 = tail call i32 @strncmp(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = icmp eq i32 %16, 0
%18 = select i1 %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %18)
%20 = icmp eq i32 %6, 0
br i1 %20, label %26, label %21
21: ; preds = %10
%22 = select i1 %17, i32 0, i32 3
%23 = tail call i32 @ioctl(i32 %6, i32 17937, i32 %22)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %23)
%25 = tail call i32 @close(i32 %6)
br label %28
26: ; preds = %10
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %28
28: ; preds = %21, %26, %8
%29 = phi i32 [ 0, %8 ], [ %23, %21 ], [ 0, %26 ]
ret i32 %29
}