#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 /*<<< orphan*/ O_RDWR;
int VT_LOCKSWITCH;
int VT_UNLOCKSWITCH;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int ioctl(int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int consfd = -1;
  int op;
  consfd = open("/dev/console", O_RDWR);
  if (consfd == -1) {
    fprintf(stderr, "Oops, cannot open /dev/console");
    return 1;
  }
  if (argc <= 1) {
    op = VT_UNLOCKSWITCH;
  } else {
    switch (argv[1][0]) {
    case '\0':
      op = VT_UNLOCKSWITCH;
      break;
    case 'u':
      op = VT_UNLOCKSWITCH;
      break;
    case 'l':
      op = VT_LOCKSWITCH;
      break;
    case '-':
      op = VT_UNLOCKSWITCH;
      break;
    case '+':
      op = VT_LOCKSWITCH;
      break;
    case '0':
      op = VT_UNLOCKSWITCH;
      break;
    case '1':
      op = VT_LOCKSWITCH;
      break;
    case 'n':
      op = VT_UNLOCKSWITCH;
      break;
    case 'y':
      op = VT_LOCKSWITCH;
      break;
    case 'o':
      if (argv[1][1] == 'n') {
        op = VT_LOCKSWITCH;
      } else {
        op = VT_UNLOCKSWITCH;
      }
      break;
    default:
      op = VT_UNLOCKSWITCH;
      break;
    }
  }
  if (ioctl(consfd, op) == -1) {
    fprintf(stderr, "Oops, ioctl failed\n");
    return 2;
  }
  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   $0xffffffff,-0x14(%rbp)
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
lea    0xeb5(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1190 <main+0x60>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    137c <main+0x24c>
cmpl   $0x1,-0x8(%rbp)
jg     11ab <main+0x7b>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1340 <main+0x210>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     125f <main+0x12f>
jmp    11c6 <main+0x96>
mov    -0x1c(%rbp),%eax
sub    $0x2b,%eax
je     12a3 <main+0x173>
jmp    11d7 <main+0xa7>
mov    -0x1c(%rbp),%eax
sub    $0x2d,%eax
je     1292 <main+0x162>
jmp    11e8 <main+0xb8>
mov    -0x1c(%rbp),%eax
sub    $0x30,%eax
je     12b4 <main+0x184>
jmp    11f9 <main+0xc9>
mov    -0x1c(%rbp),%eax
sub    $0x31,%eax
je     12c5 <main+0x195>
jmp    120a <main+0xda>
mov    -0x1c(%rbp),%eax
sub    $0x6c,%eax
je     1281 <main+0x151>
jmp    121b <main+0xeb>
mov    -0x1c(%rbp),%eax
sub    $0x6e,%eax
je     12d6 <main+0x1a6>
jmp    122c <main+0xfc>
mov    -0x1c(%rbp),%eax
sub    $0x6f,%eax
je     12f8 <main+0x1c8>
jmp    123d <main+0x10d>
mov    -0x1c(%rbp),%eax
sub    $0x75,%eax
je     1270 <main+0x140>
jmp    124e <main+0x11e>
mov    -0x1c(%rbp),%eax
sub    $0x79,%eax
je     12e7 <main+0x1b7>
jmp    132f <main+0x1ff>
mov    0x2d72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    133b <main+0x20b>
mov    0x2d61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    133b <main+0x20b>
mov    0x2d58(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    133b <main+0x20b>
mov    0x2d3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    133b <main+0x20b>
mov    0x2d36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    133b <main+0x20b>
mov    0x2d1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    133b <main+0x20b>
mov    0x2d14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    133b <main+0x20b>
mov    0x2cfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    133b <main+0x20b>
mov    0x2cf2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    133b <main+0x20b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x6e,%eax
jne    131e <main+0x1ee>
mov    0x2ccc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    132a <main+0x1fa>
mov    0x2cb3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    133b <main+0x20b>
mov    0x2ca2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1340 <main+0x210>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1375 <main+0x245>
mov    0x2c6d(%rip),%rax
mov    (%rax),%edi
lea    0xcbb(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    137c <main+0x24c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
lea    0xeca(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     117b <main+0x4b>
mov    0x2e7f(%rip),%rcx
cmp    $0x2,%ebp
jl     11a2 <main+0x72>
mov    0x8(%rbx),%rsi
movsbl (%rsi),%edx
cmp    $0x6b,%edx
jle    1189 <main+0x59>
cmp    $0x79,%edx
je     119b <main+0x6b>
cmp    $0x6f,%edx
je     1195 <main+0x65>
cmp    $0x6c,%edx
je     119b <main+0x6b>
jmp    11a2 <main+0x72>
mov    $0x1,%ebx
lea    0xe79(%rip),%rsi
jmp    11be <main+0x8e>
cmp    $0x2b,%edx
je     119b <main+0x6b>
cmp    $0x31,%edx
je     119b <main+0x6b>
jmp    11a2 <main+0x72>
cmpb   $0x6e,0x1(%rsi)
jne    11d5 <main+0xa5>
mov    0x2e3e(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1030 <ioctl@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
jne    11cc <main+0x9c>
mov    $0x2,%ebx
lea    0xe61(%rip),%rsi
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2dfc(%rip),%rcx
jmp    11a2 <main+0x72>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/console\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [31 x i8] c"Oops, cannot open /dev/console\00"
@VT_UNLOCKSWITCH = global i32 0
@VT_LOCKSWITCH = global i32 0
@.str.2 = [20 x i8] c"Oops, ioctl 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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 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 %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %70
15: ; preds = %2
%16 = load i32, i32* %4
%17 = icmp sle i32 %16, 1
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = load i32, i32* @VT_UNLOCKSWITCH
store i32 %19, i32* %7
br label %61
20: ; preds = %15
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
switch i32 %26, label %58 [
i32 0, label %27
i32 117, label %29
i32 108, label %31
i32 45, label %33
i32 43, label %35
i32 48, label %37
i32 49, label %39
i32 110, label %41
i32 121, label %43
i32 111, label %45
]
27: ; preds = %20
%28 = load i32, i32* @VT_UNLOCKSWITCH
store i32 %28, i32* %7
br label %60
29: ; preds = %20
%30 = load i32, i32* @VT_UNLOCKSWITCH
store i32 %30, i32* %7
br label %60
31: ; preds = %20
%32 = load i32, i32* @VT_LOCKSWITCH
store i32 %32, i32* %7
br label %60
33: ; preds = %20
%34 = load i32, i32* @VT_UNLOCKSWITCH
store i32 %34, i32* %7
br label %60
35: ; preds = %20
%36 = load i32, i32* @VT_LOCKSWITCH
store i32 %36, i32* %7
br label %60
37: ; preds = %20
%38 = load i32, i32* @VT_UNLOCKSWITCH
store i32 %38, i32* %7
br label %60
39: ; preds = %20
%40 = load i32, i32* @VT_LOCKSWITCH
store i32 %40, i32* %7
br label %60
41: ; preds = %20
%42 = load i32, i32* @VT_UNLOCKSWITCH
store i32 %42, i32* %7
br label %60
43: ; preds = %20
%44 = load i32, i32* @VT_LOCKSWITCH
store i32 %44, i32* %7
br label %60
45: ; preds = %20
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = getelementptr inbounds i8, i8* %48, i64 1
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 110
br i1 %52, label %53, label %55
53: ; preds = %45
%54 = load i32, i32* @VT_LOCKSWITCH
store i32 %54, i32* %7
br label %57
55: ; preds = %45
%56 = load i32, i32* @VT_UNLOCKSWITCH
store i32 %56, i32* %7
br label %57
57: ; preds = %55, %53
br label %60
58: ; preds = %20
%59 = load i32, i32* @VT_UNLOCKSWITCH
store i32 %59, i32* %7
br label %60
60: ; preds = %58, %57, %43, %41, %39, %37, %35, %33, %31, %29, %27
br label %61
61: ; preds = %60, %18
%62 = load i32, i32* %6
%63 = load i32, i32* %7
%64 = call i32 @ioctl(i32 %62, i32 %63)
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %69
66: ; preds = %61
%67 = load i32, i32* @stderr
%68 = call i32 @fprintf(i32 %67, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %70
69: ; preds = %61
store i32 0, i32* %3
br label %70
70: ; preds = %69, %66, %12
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/console\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [31 x i8] c"Oops, cannot open /dev/console\00"
@VT_UNLOCKSWITCH = global i32 0
@VT_LOCKSWITCH = global i32 0
@.str.2 = [20 x i8] c"Oops, ioctl failed\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %27, label %6
6: ; preds = %2
%7 = icmp slt i32 %0, 2
br i1 %7, label %22, label %8
8: ; preds = %6
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
switch i32 %12, label %22 [
i32 111, label %17
i32 121, label %16
i32 108, label %13
i32 49, label %15
i32 43, label %14
]
13: ; preds = %8
br label %22
14: ; preds = %8
br label %22
15: ; preds = %8
br label %22
16: ; preds = %8
br label %22
17: ; preds = %8
%18 = getelementptr inbounds i8, i8* %10, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 110
%21 = select i1 %20, i32* @VT_LOCKSWITCH, i32* @VT_UNLOCKSWITCH
br label %22
22: ; preds = %8, %17, %6, %13, %14, %15, %16
%23 = phi i32* [ @VT_LOCKSWITCH, %16 ], [ @VT_LOCKSWITCH, %15 ], [ @VT_LOCKSWITCH, %14 ], [ @VT_LOCKSWITCH, %13 ], [ @VT_UNLOCKSWITCH, %6 ], [ %21, %17 ], [ @VT_UNLOCKSWITCH, %8 ]
%24 = load i32, i32* %23
%25 = tail call i32 @ioctl(i32 %4, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %32
27: ; preds = %22, %2
%28 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), %22 ]
%29 = phi i32 [ 1, %2 ], [ 2, %22 ]
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* %28)
br label %32
32: ; preds = %27, %22
%33 = phi i32 [ 0, %22 ], [ %29, %27 ]
ret i32 %33
}