#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 */
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int CurrentTime;
scalar_t__ False;
scalar_t__ True;
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XK_c;
int XKeysymToKeycode(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *XOpenDisplay(char *);
int /*<<< orphan*/ XTestFakeKeyEvent(int /*<<< orphan*/ *, int, scalar_t__,
                                     int);
scalar_t__ XTestQueryExtension(int /*<<< orphan*/ *, int *, int *, int *,
                               int *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  char *dpyid = NULL;
  Display *dpy;
  int dummy;
  int keycode;
  dpy = XOpenDisplay(dpyid);
  if (XTestQueryExtension(dpy, &dummy, &dummy, &dummy, &dummy) == False) {
    printf("This should not have failed.\n");
    return 1;
  }
  keycode = XKeysymToKeycode(dpy, XK_c);
  XTestFakeKeyEvent(dpy, keycode, True, CurrentTime);
  XTestFakeKeyEvent(dpy, keycode, False, 20);
  XCloseDisplay(dpy);
}


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)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <XOpenDisplay@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x24(%rbp),%r8
mov    %r8,%rsi
mov    %r8,%rdx
mov    %r8,%rcx
call   1040 <XTestQueryExtension@plt>
mov    0x2e38(%rip),%rcx
cmp    (%rcx),%rax
jne    11c9 <main+0x69>
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1221 <main+0xc1>
mov    -0x20(%rbp),%rdi
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
call   1060 <XKeysymToKeycode@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    0x2dec(%rip),%rax
mov    (%rax),%rdx
mov    0x2df2(%rip),%rax
mov    (%rax),%ecx
call   1070 <XTestFakeKeyEvent@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    0x2dd5(%rip),%rax
mov    (%rax),%rdx
mov    $0x14,%ecx
call   1070 <XTestFakeKeyEvent@plt>
mov    -0x20(%rbp),%rdi
call   1080 <XCloseDisplay@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
xor    %edi,%edi
call   1050 <XOpenDisplay@plt>
mov    %rax,%rbx
lea    0x4(%rsp),%rcx
mov    %rax,%rdi
mov    %rcx,%rsi
mov    %rcx,%rdx
mov    %rcx,%r8
call   1040 <XTestQueryExtension@plt>
mov    0x2e4f(%rip),%r15
cmp    (%r15),%rax
jne    11aa <main+0x4a>
lea    0xe63(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r14d
jmp    11f4 <main+0x94>
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <XKeysymToKeycode@plt>
mov    %eax,%ebp
mov    0x2e14(%rip),%rax
mov    (%rax),%rdx
mov    0x2e1a(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <XTestFakeKeyEvent@plt>
mov    (%r15),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x14,%ecx
call   1070 <XTestFakeKeyEvent@plt>
mov    %rbx,%rdi
call   1080 <XCloseDisplay@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@False = global i64 0
@.str = [30 x i8] c"This should not have failed.\0A\00"
@XK_c = global i32 0
@True = global i64 0
@CurrentTime = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
%10 = load i8*, i8** %6
%11 = call i32* @XOpenDisplay(i8* %10)
store i32* %11, i32** %7
%12 = load i32*, i32** %7
%13 = call i64 @XTestQueryExtension(i32* %12, i32* %8, i32* %8, i32* %8, i32* %8)
%14 = load i64, i64* @False
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %33
18: ; preds = %2
%19 = load i32*, i32** %7
%20 = load i32, i32* @XK_c
%21 = call i32 @XKeysymToKeycode(i32* %19, i32 %20)
store i32 %21, i32* %9
%22 = load i32*, i32** %7
%23 = load i32, i32* %9
%24 = load i64, i64* @True
%25 = load i32, i32* @CurrentTime
%26 = call i32 @XTestFakeKeyEvent(i32* %22, i32 %23, i64 %24, i32 %25)
%27 = load i32*, i32** %7
%28 = load i32, i32* %9
%29 = load i64, i64* @False
%30 = call i32 @XTestFakeKeyEvent(i32* %27, i32 %28, i64 %29, i32 20)
%31 = load i32*, i32** %7
%32 = call i32 @XCloseDisplay(i32* %31)
br label %33
33: ; preds = %18, %16
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@False = global i64 0
@XK_c = global i32 0
@True = global i64 0
@CurrentTime = global i32 0
@str = [29 x i8] c"This should not have failed.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32* @XOpenDisplay(i8* null)
%6 = call i64 @XTestQueryExtension(i32* %5, i32* %3, i32* %3, i32* %3, i32* %3)
%7 = load i64, i64* @False
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %20
11: ; preds = %2
%12 = load i32, i32* @XK_c
%13 = call i32 @XKeysymToKeycode(i32* %5, i32 %12)
%14 = load i64, i64* @True
%15 = load i32, i32* @CurrentTime
%16 = call i32 @XTestFakeKeyEvent(i32* %5, i32 %13, i64 %14, i32 %15)
%17 = load i64, i64* @False
%18 = call i32 @XTestFakeKeyEvent(i32* %5, i32 %13, i64 %17, i32 20)
%19 = call i32 @XCloseDisplay(i32* %5)
br label %20
20: ; preds = %11, %9
%21 = phi i32 [ 1, %9 ], [ 0, %11 ]
ret i32 %21
}