#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 */
typedef struct TYPE_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int keycode;
  int /*<<< orphan*/ state;
};
struct TYPE_5__ {
  int type;
  TYPE_1__ xkey;
};
typedef TYPE_2__ XEvent;
typedef int /*<<< orphan*/ Window;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ CurrentTime;
int /*<<< orphan*/ False;
int /*<<< orphan*/ GrabModeAsync;
#define KeyPress 128
int /*<<< orphan*/ KeyPressMask;
int /*<<< orphan*/ Mod4Mask;
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XDefaultRootWindow(int /*<<< orphan*/ *);
int /*<<< orphan*/ XFlush(int /*<<< orphan*/ *);
int /*<<< orphan*/ XGrabKeyboard(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                 int /*<<< orphan*/, int /*<<< orphan*/,
                                 int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ XGrabServer(int /*<<< orphan*/ *);
int /*<<< orphan*/ XK_Super_R;
int XKeysymToKeycode(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XNextEvent(int /*<<< orphan*/ *, TYPE_2__ *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XSelectInput(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                int /*<<< orphan*/);
int /*<<< orphan*/ XUngrabKey(int /*<<< orphan*/ *, int, int /*<<< orphan*/,
                              int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ system(char *);
int main() {
  system("vbetool dpms off");
  Display *display;
  display = XOpenDisplay(NULL);
  if (display == NULL) {
    printf("Cant open display\n");
    return 2;
  }
  XGrabServer(display);
  XFlush(display);
  int keyCode = XKeysymToKeycode(display, XK_Super_R);
  Window root = XDefaultRootWindow(display);
  XGrabKeyboard(display, root, False, GrabModeAsync, GrabModeAsync,
                CurrentTime);
  XSelectInput(display, root, KeyPressMask);
  int shouldQuit = 0;
  XEvent event;
  while (!shouldQuit) {
    XNextEvent(display, &event);
    switch (event.type) {
    case KeyPress:
      if (event.xkey.state == Mod4Mask && event.xkey.keycode == keyCode) {
        XUngrabKey(display, keyCode, 0, root);
        shouldQuit = 1;
        system("vbetool dpms on");
        break;
      }
    }
  }
  XCloseDisplay(display);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe2a(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <XOpenDisplay@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    120b <main+0x4b>
lea    0xe17(%rip),%rdi
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1323 <main+0x163>
mov    -0x10(%rbp),%rdi
call   1090 <XGrabServer@plt>
mov    -0x10(%rbp),%rdi
call   10b0 <XFlush@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
call   1060 <XKeysymToKeycode@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <XDefaultRootWindow@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    0x2d84(%rip),%rax
mov    (%rax),%edx
mov    0x2d63(%rip),%rax
mov    (%rax),%ecx
mov    0x2d5a(%rip),%rax
mov    (%rax),%r8d
mov    0x2d70(%rip),%rax
mov    (%rax),%r9d
call   10e0 <XGrabKeyboard@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    0x2d4a(%rip),%rax
mov    (%rax),%edx
call   1080 <XSelectInput@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12a2 <main+0xe2>
jmp    1313 <main+0x153>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <XNextEvent@plt>
mov    -0x28(%rbp),%eax
sub    $0x80,%eax
jne    130e <main+0x14e>
jmp    12c2 <main+0x102>
mov    -0x20(%rbp),%eax
mov    0x2d24(%rip),%rcx
cmp    (%rcx),%eax
jne    1309 <main+0x149>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1309 <main+0x149>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%ecx
xor    %edx,%edx
call   10c0 <XUngrabKey@plt>
movl   $0x1,-0x1c(%rbp)
lea    0xd25(%rip),%rdi
call   1030 <system@plt>
jmp    130e <main+0x14e>
jmp    130e <main+0x14e>
jmp    128c <main+0xcc>
mov    -0x10(%rbp),%rdi
call   10d0 <XCloseDisplay@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe2d(%rip),%rdi
call   1040 <system@plt>
xor    %edi,%edi
call   1050 <XOpenDisplay@plt>
test   %rax,%rax
je     12bd <main+0xfd>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <XGrabServer@plt>
mov    %rbx,%rdi
call   10b0 <XFlush@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <XKeysymToKeycode@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   10a0 <XDefaultRootWindow@plt>
mov    %eax,%r14d
mov    0x2daf(%rip),%rax
mov    (%rax),%edx
mov    0x2d8e(%rip),%rax
mov    (%rax),%ecx
mov    0x2da5(%rip),%rax
mov    (%rax),%r9d
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %ecx,%r8d
call   10e0 <XGrabKeyboard@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1080 <XSelectInput@plt>
mov    %rsp,%rbp
mov    0x2d8e(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <XNextEvent@plt>
cmpl   $0x80,(%rsp)
jne    1270 <main+0xb0>
mov    0x8(%rsp),%eax
cmp    (%r15),%eax
jne    1270 <main+0xb0>
cmp    %r12d,0x4(%rsp)
jne    1270 <main+0xb0>
xor    %r15d,%r15d
mov    %rbx,%rdi
mov    %r12d,%esi
xor    %edx,%edx
mov    %r14d,%ecx
call   10c0 <XUngrabKey@plt>
lea    0xd63(%rip),%rdi
call   1040 <system@plt>
mov    %rbx,%rdi
call   10d0 <XCloseDisplay@plt>
jmp    12cf <main+0x10f>
lea    0xd5d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%r15d
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32, %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i32, i32 }
@.str = [17 x i8] c"vbetool dpms off\00"
@.str.1 = [19 x i8] c"Cant open display\0A\00"
@XK_Super_R = global i32 0
@False = global i32 0
@GrabModeAsync = global i32 0
@CurrentTime = global i32 0
@KeyPressMask = global i32 0
@Mod4Mask = global i32 0
@.str.2 = [16 x i8] c"vbetool dpms on\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.TYPE_5__
store i32 0, i32* %1
%7 = call i32 @system(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%8 = call i32* @XOpenDisplay(i32* null)
store i32* %8, i32** %2
%9 = load i32*, i32** %2
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %1
br label %66
13: ; preds = %0
%14 = load i32*, i32** %2
%15 = call i32 @XGrabServer(i32* %14)
%16 = load i32*, i32** %2
%17 = call i32 @XFlush(i32* %16)
%18 = load i32*, i32** %2
%19 = load i32, i32* @XK_Super_R
%20 = call i32 @XKeysymToKeycode(i32* %18, i32 %19)
store i32 %20, i32* %3
%21 = load i32*, i32** %2
%22 = call i32 @XDefaultRootWindow(i32* %21)
store i32 %22, i32* %4
%23 = load i32*, i32** %2
%24 = load i32, i32* %4
%25 = load i32, i32* @False
%26 = load i32, i32* @GrabModeAsync
%27 = load i32, i32* @GrabModeAsync
%28 = load i32, i32* @CurrentTime
%29 = call i32 @XGrabKeyboard(i32* %23, i32 %24, i32 %25, i32 %26, i32 %27, i32 %28)
%30 = load i32*, i32** %2
%31 = load i32, i32* %4
%32 = load i32, i32* @KeyPressMask
%33 = call i32 @XSelectInput(i32* %30, i32 %31, i32 %32)
store i32 0, i32* %5
br label %34
34: ; preds = %62, %13
%35 = load i32, i32* %5
%36 = icmp ne i32 %35, 0
%37 = xor i1 %36, true
br i1 %37, label %38, label %63
38: ; preds = %34
%39 = load i32*, i32** %2
%40 = call i32 @XNextEvent(i32* %39, %struct.TYPE_5__* %6)
%41 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 0
%42 = load i32, i32* %41
switch i32 %42, label %62 [
i32 128, label %43
]
43: ; preds = %38
%44 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 1
%45 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %44, i32 0, i32 1
%46 = load i32, i32* %45
%47 = load i32, i32* @Mod4Mask
%48 = icmp eq i32 %46, %47
br i1 %48, label %49, label %61
49: ; preds = %43
%50 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 1
%51 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %50, i32 0, i32 0
%52 = load i32, i32* %51
%53 = load i32, i32* %3
%54 = icmp eq i32 %52, %53
br i1 %54, label %55, label %61
55: ; preds = %49
%56 = load i32*, i32** %2
%57 = load i32, i32* %3
%58 = load i32, i32* %4
%59 = call i32 @XUngrabKey(i32* %56, i32 %57, i32 0, i32 %58)
store i32 1, i32* %5
%60 = call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %62
61: ; preds = %49, %43
br label %62
62: ; preds = %61, %38, %55
br label %34
63: ; preds = %34
%64 = load i32*, i32** %2
%65 = call i32 @XCloseDisplay(i32* %64)
store i32 0, i32* %1
br label %66
66: ; preds = %63, %11
%67 = load i32, i32* %1
ret i32 %67
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i32, i32 }
@.str = [17 x i8] c"vbetool dpms off\00"
@XK_Super_R = global i32 0
@False = global i32 0
@GrabModeAsync = global i32 0
@CurrentTime = global i32 0
@KeyPressMask = global i32 0
@Mod4Mask = global i32 0
@.str.2 = [16 x i8] c"vbetool dpms on\00"
@str = [18 x i8] c"Cant open display\00"
define i32 @main() {
%1 = alloca %struct.TYPE_5__
%2 = tail call i32 @system(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32* @XOpenDisplay(i32* null)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %39
7: ; preds = %0
%8 = tail call i32 @XGrabServer(i32* %3)
%9 = tail call i32 @XFlush(i32* %3)
%10 = load i32, i32* @XK_Super_R
%11 = tail call i32 @XKeysymToKeycode(i32* %3, i32 %10)
%12 = tail call i32 @XDefaultRootWindow(i32* %3)
%13 = load i32, i32* @False
%14 = load i32, i32* @GrabModeAsync
%15 = load i32, i32* @CurrentTime
%16 = tail call i32 @XGrabKeyboard(i32* %3, i32 %12, i32 %13, i32 %14, i32 %14, i32 %15)
%17 = load i32, i32* @KeyPressMask
%18 = tail call i32 @XSelectInput(i32* %3, i32 %12, i32 %17)
%19 = bitcast %struct.TYPE_5__* %1 to i8*
%20 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %1, i64 0, i32 0
%21 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %1, i64 0, i32 1, i32 1
%22 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %1, i64 0, i32 1, i32 0
br label %23
23: ; preds = %34, %7
%24 = call i32 @XNextEvent(i32* %3, %struct.TYPE_5__* %1)
%25 = load i32, i32* %20
%26 = icmp eq i32 %25, 128
br i1 %26, label %27, label %34
27: ; preds = %23
%28 = load i32, i32* %21
%29 = load i32, i32* @Mod4Mask
%30 = icmp eq i32 %28, %29
%31 = load i32, i32* %22
%32 = icmp eq i32 %31, %11
%33 = select i1 %30, i1 %32, i1 false
br i1 %33, label %35, label %34
34: ; preds = %27, %23
br label %23
35: ; preds = %27
%36 = call i32 @XUngrabKey(i32* %3, i32 %11, i32 0, i32 %12)
%37 = call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @XCloseDisplay(i32* %3)
br label %39
39: ; preds = %35, %5
%40 = phi i32 [ 2, %5 ], [ 0, %35 ]
ret i32 %40
}