#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_6__ TYPE_2__;
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ event;
struct TYPE_5__ {
  int button;
  int /*<<< orphan*/ state;
  int /*<<< orphan*/ y;
  int /*<<< orphan*/ x;
  int /*<<< orphan*/ y_root;
  int /*<<< orphan*/ x_root;
  scalar_t__ subwindow;
  int /*<<< orphan*/ root;
  scalar_t__ window;
  int /*<<< orphan*/ same_screen;
};
struct TYPE_6__ {
  int /*<<< orphan*/ type;
  TYPE_1__ xbutton;
};
typedef TYPE_2__ XEvent;
typedef scalar_t__ Window;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ ButtonPress;
int /*<<< orphan*/ ButtonRelease;
int /*<<< orphan*/ PointerWindow;
int /*<<< orphan*/ True;
int /*<<< orphan*/ XFlush(int /*<<< orphan*/ *);
int /*<<< orphan*/ XQueryPointer(int /*<<< orphan*/ *, scalar_t__,
                                 int /*<<< orphan*/ *, scalar_t__ *,
                                 int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                 int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                 int /*<<< orphan*/ *);
scalar_t__ XSendEvent(int /*<<< orphan*/ *, int /*<<< orphan*/,
                      int /*<<< orphan*/, int, TYPE_2__ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(TYPE_2__ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
void click(Display *dpy, Window w, int button) {
  XEvent event;
  memset(&event, 0, sizeof(event));
  event.type = ButtonPress;
  event.xbutton.button = button;
  event.xbutton.same_screen = True;
  event.xbutton.subwindow = w;
  while (event.xbutton.subwindow) {
    event.xbutton.window = event.xbutton.subwindow;
    XQueryPointer(dpy, event.xbutton.window, &event.xbutton.root,
                  &event.xbutton.subwindow, &event.xbutton.x_root,
                  &event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y,
                  &event.xbutton.state);
  }
  if (XSendEvent(dpy, PointerWindow, True, 0xfff, &event) == 0)
    fprintf(stderr, "Couldn't send ButtonPress event?\n");
  XFlush(dpy);
  event.type = ButtonRelease;
  if (XSendEvent(dpy, PointerWindow, True, 0xfff, &event) == 0)
    fprintf(stderr, "Couldn't send ButtonRelease event?\n");
  XFlush(dpy);
}


x86 assembly (clang, -O0):
<click>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1220 <click+0xd0>
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x58(%rbp),%rdx
add    $0x8,%rdx
add    $0x20,%rdx
lea    -0x58(%rbp),%rcx
add    $0x8,%rcx
add    $0x18,%rcx
lea    -0x58(%rbp),%r8
add    $0x8,%r8
add    $0x14,%r8
lea    -0x58(%rbp),%r9
add    $0x8,%r9
add    $0x10,%r9
lea    -0x58(%rbp),%r11
add    $0x8,%r11
add    $0xc,%r11
lea    -0x58(%rbp),%r10
add    $0x8,%r10
add    $0x8,%r10
lea    -0x58(%rbp),%rax
add    $0x8,%rax
add    $0x4,%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1060 <XQueryPointer@plt>
jmp    1199 <click+0x49>
mov    -0x8(%rbp),%rdi
mov    0x2da5(%rip),%rax
mov    (%rax),%esi
mov    0x2db4(%rip),%rax
mov    (%rax),%edx
mov    $0xfff,%ecx
lea    -0x58(%rbp),%r8
call   1030 <XSendEvent@plt>
cmp    $0x0,%rax
jne    1263 <click+0x113>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1070 <XFlush@plt>
mov    0x2d45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2d4d(%rip),%rax
mov    (%rax),%esi
mov    0x2d5c(%rip),%rax
mov    (%rax),%edx
mov    $0xfff,%ecx
lea    -0x58(%rbp),%r8
call   1030 <XSendEvent@plt>
cmp    $0x0,%rax
jne    12bb <click+0x16b>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
lea    0xd6c(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1070 <XFlush@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<click>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %ebp,0x10(%rsp)
mov    0x2e59(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %edx,0x40(%rsp)
mov    %rbx,0x28(%rsp)
test   %rbx,%rbx
je     1204 <click+0xb4>
lea    0x20(%rsp),%rbp
lea    0x1c(%rsp),%r13
lea    0x18(%rsp),%r15
lea    0x14(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,0x38(%rsp)
sub    $0x8,%rsp
mov    %r14,%rdi
mov    %rbx,%rsi
lea    0x38(%rsp),%rdx
lea    0x30(%rsp),%rcx
lea    0x2c(%rsp),%r8
mov    %rbp,%r9
push   %r12
push   %r15
push   %r13
call   1060 <XQueryPointer@plt>
add    $0x20,%rsp
mov    0x28(%rsp),%rbx
test   %rbx,%rbx
jne    11c0 <click+0x70>
mov    0x2de7(%rip),%rbp
mov    0x0(%rbp),%edx
mov    0x2dc5(%rip),%rbx
mov    (%rbx),%esi
lea    0x8(%rsp),%r8
mov    %r14,%rdi
mov    $0xfff,%ecx
call   1030 <XSendEvent@plt>
test   %rax,%rax
jne    1239 <click+0xe9>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
call   1050 <fprintf@plt>
mov    %r14,%rdi
call   1070 <XFlush@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    (%rbx),%esi
mov    0x0(%rbp),%edx
lea    0x8(%rsp),%r8
mov    %r14,%rdi
mov    $0xfff,%ecx
call   1030 <XSendEvent@plt>
test   %rax,%rax
jne    127f <click+0x12f>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
lea    0xda8(%rip),%rsi
call   1050 <fprintf@plt>
mov    %r14,%rdi
call   1070 <XFlush@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_6__ = type { i32, %struct.TYPE_5__ }
%struct.TYPE_5__ = type { i32, i32, i32, i32, i32, i32, i64, i32, i64, i32 }
@ButtonPress = global i32 0
@True = global i32 0
@PointerWindow = global i32 0
@stderr = global i32 0
@.str = [34 x i8] c"Couldn't send ButtonPress event?\0A\00"
@ButtonRelease = global i32 0
@.str.1 = [36 x i8] c"Couldn't send ButtonRelease event?\0A\00"
define void @click(i32* %0, i64 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i32
%7 = alloca %struct.TYPE_6__
store i32* %0, i32** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%8 = call i32 @memset(%struct.TYPE_6__* %7, i32 0, i32 64)
%9 = load i32, i32* @ButtonPress
%10 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 0
store i32 %9, i32* %10
%11 = load i32, i32* %6
%12 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 1
%13 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 0
store i32 %11, i32* %13
%14 = load i32, i32* @True
%15 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 1
%16 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %15, i32 0, i32 9
store i32 %14, i32* %16
%17 = load i64, i64* %5
%18 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 1
%19 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %18, i32 0, i32 6
store i64 %17, i64* %19
br label %20
20: ; preds = %25, %3
%21 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %21, i32 0, i32 6
%23 = load i64, i64* %22
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %50
25: ; preds = %20
%26 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 1
%27 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %26, i32 0, i32 6
%28 = load i64, i64* %27
%29 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 1
%30 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %29, i32 0, i32 8
store i64 %28, i64* %30
%31 = load i32*, i32** %4
%32 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 1
%33 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %32, i32 0, i32 8
%34 = load i64, i64* %33
%35 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 1
%36 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %35, i32 0, i32 7
%37 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 1
%38 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %37, i32 0, i32 6
%39 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 1
%40 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %39, i32 0, i32 5
%41 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 1
%42 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %41, i32 0, i32 4
%43 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 1
%44 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %43, i32 0, i32 3
%45 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 1
%46 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %45, i32 0, i32 2
%47 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 1
%48 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %47, i32 0, i32 1
%49 = call i32 @XQueryPointer(i32* %31, i64 %34, i32* %36, i64* %38, i32* %40, i32* %42, i32* %44, i32* %46, i32* %48)
br label %20
50: ; preds = %20
%51 = load i32*, i32** %4
%52 = load i32, i32* @PointerWindow
%53 = load i32, i32* @True
%54 = call i64 @XSendEvent(i32* %51, i32 %52, i32 %53, i32 4095, %struct.TYPE_6__* %7)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %50
%57 = load i32, i32* @stderr
%58 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %59
59: ; preds = %56, %50
%60 = load i32*, i32** %4
%61 = call i32 @XFlush(i32* %60)
%62 = load i32, i32* @ButtonRelease
%63 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 0
store i32 %62, i32* %63
%64 = load i32*, i32** %4
%65 = load i32, i32* @PointerWindow
%66 = load i32, i32* @True
%67 = call i64 @XSendEvent(i32* %64, i32 %65, i32 %66, i32 4095, %struct.TYPE_6__* %7)
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %59
%70 = load i32, i32* @stderr
%71 = call i32 @fprintf(i32 %70, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %72
72: ; preds = %69, %59
%73 = load i32*, i32** %4
%74 = call i32 @XFlush(i32* %73)
ret void
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i32, %struct.TYPE_5__ }
%struct.TYPE_5__ = type { i32, i32, i32, i32, i32, i32, i64, i32, i64, i32 }
@ButtonPress = global i32 0
@True = global i32 0
@PointerWindow = global i32 0
@stderr = global i32 0
@.str = [34 x i8] c"Couldn't send ButtonPress event?\0A\00"
@ButtonRelease = global i32 0
@.str.1 = [36 x i8] c"Couldn't send ButtonRelease event?\0A\00"
define void @click(i32* %0, i64 %1, i32 %2) {
%4 = alloca %struct.TYPE_6__
%5 = bitcast %struct.TYPE_6__* %4 to i8*
%6 = call i32 @memset(%struct.TYPE_6__* %4, i32 0, i32 64)
%7 = load i32, i32* @ButtonPress
%8 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 0
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 1, i32 0
store i32 %2, i32* %9
%10 = load i32, i32* @True
%11 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 1, i32 9
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 1, i32 6
store i64 %1, i64* %12
%13 = icmp eq i64 %1, 0
br i1 %13, label %29, label %14
14: ; preds = %3
%15 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 1, i32 8
%16 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 1, i32 7
%17 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 1, i32 5
%18 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 1, i32 4
%19 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 1, i32 3
%20 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 1, i32 2
%21 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 1, i32 1
br label %22
22: ; preds = %14, %22
%23 = phi i64 [ %1, %14 ], [ %25, %22 ]
store i64 %23, i64* %15
%24 = call i32 @XQueryPointer(i32* %0, i64 %23, i32* %16, i64* %12, i32* %17, i32* %18, i32* %19, i32* %20, i32* %21)
%25 = load i64, i64* %12
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %22
27: ; preds = %22
%28 = load i32, i32* @True
br label %29
29: ; preds = %27, %3
%30 = phi i32 [ %28, %27 ], [ %10, %3 ]
%31 = load i32, i32* @PointerWindow
%32 = call i64 @XSendEvent(i32* %0, i32 %31, i32 %30, i32 4095, %struct.TYPE_6__* %4)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %37
37: ; preds = %34, %29
%38 = call i32 @XFlush(i32* %0)
%39 = load i32, i32* @ButtonRelease
store i32 %39, i32* %8
%40 = load i32, i32* @PointerWindow
%41 = load i32, i32* @True
%42 = call i64 @XSendEvent(i32* %0, i32 %40, i32 %41, i32 4095, %struct.TYPE_6__* %4)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %37
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %47
47: ; preds = %44, %37
%48 = call i32 @XFlush(i32* %0)
ret void
}