#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int x;
  int y;
  int /*<<< orphan*/ state;
  int /*<<< orphan*/ y_root;
  int /*<<< orphan*/ x_root;
  int /*<<< orphan*/ window;
  int /*<<< orphan*/ root;
};
struct TYPE_4__ {
  TYPE_1__ xbutton;
};
typedef TYPE_2__ XEvent;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int DefaultScreen(int /*<<< orphan*/ *);
int /*<<< orphan*/ RootWindow(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XQueryPointer(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                 int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                 int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                 int *, int *, int /*<<< orphan*/ *);
int get_pointer_coords(int *x, int *y) {
  Display *display;
  XEvent event;
  int screen;
  if (!(display = XOpenDisplay(NULL)))
    return 0;
  screen = DefaultScreen(display);
  XQueryPointer(display, RootWindow(display, screen), &event.xbutton.root,
                &event.xbutton.window, &event.xbutton.x_root,
                &event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y,
                &event.xbutton.state);
  *x = event.xbutton.x;
  *y = event.xbutton.y;
  XCloseDisplay(display);
  return 1;
}


x86 assembly (clang, -O0):
<get_pointer_coords>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1030 <XOpenDisplay@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1183 <get_pointer_coords+0x33>
movl   $0x0,-0x4(%rbp)
jmp    1212 <get_pointer_coords+0xc2>
mov    -0x20(%rbp),%rdi
call   1060 <DefaultScreen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1050 <RootWindow@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
lea    -0x40(%rbp),%rdx
add    $0x18,%rdx
lea    -0x40(%rbp),%rcx
add    $0x14,%rcx
lea    -0x40(%rbp),%r8
add    $0x10,%r8
lea    -0x40(%rbp),%r9
add    $0xc,%r9
lea    -0x40(%rbp),%r11
lea    -0x40(%rbp),%r10
add    $0x4,%r10
lea    -0x40(%rbp),%rax
add    $0x8,%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1040 <XQueryPointer@plt>
mov    -0x40(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x3c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
call   1070 <XCloseDisplay@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_pointer_coords>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
xor    %edi,%edi
call   1030 <XOpenDisplay@plt>
test   %rax,%rax
je     11d9 <get_pointer_coords+0x89>
mov    %rax,%r12
mov    %rax,%rdi
call   1060 <DefaultScreen@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   1050 <RootWindow@plt>
lea    0x20(%rsp),%rdx
lea    0x1c(%rsp),%rcx
lea    0x18(%rsp),%r8
lea    0x14(%rsp),%r9
lea    0xc(%rsp),%r10
lea    0x10(%rsp),%rbx
sub    $0x8,%rsp
lea    0x10(%rsp),%r11
mov    %r12,%rdi
mov    %eax,%esi
push   %rbx
push   %r10
push   %r11
call   1040 <XQueryPointer@plt>
add    $0x20,%rsp
mov    0x8(%rsp),%eax
mov    %eax,(%r15)
mov    0xc(%rsp),%eax
mov    %eax,(%r14)
mov    %r12,%rdi
call   1070 <XCloseDisplay@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32, i32, i32, i32, i32, i32, i32 }
define i32 @get_pointer_coords(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca %struct.TYPE_4__
%8 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%9 = call i32* @XOpenDisplay(i32* null)
store i32* %9, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
store i32 0, i32* %3
br label %44
12: ; preds = %2
%13 = load i32*, i32** %6
%14 = call i32 @DefaultScreen(i32* %13)
store i32 %14, i32* %8
%15 = load i32*, i32** %6
%16 = load i32*, i32** %6
%17 = load i32, i32* %8
%18 = call i32 @RootWindow(i32* %16, i32 %17)
%19 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %19, i32 0, i32 6
%21 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 0
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %21, i32 0, i32 5
%23 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 0
%24 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %23, i32 0, i32 4
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %25, i32 0, i32 3
%27 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 0
%28 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %27, i32 0, i32 0
%29 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 0
%30 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %29, i32 0, i32 1
%31 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 0
%32 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %31, i32 0, i32 2
%33 = call i32 @XQueryPointer(i32* %15, i32 %18, i32* %20, i32* %22, i32* %24, i32* %26, i32* %28, i32* %30, i32* %32)
%34 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 0
%35 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = load i32*, i32** %4
store i32 %36, i32* %37
%38 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 0
%39 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %38, i32 0, i32 1
%40 = load i32, i32* %39
%41 = load i32*, i32** %5
store i32 %40, i32* %41
%42 = load i32*, i32** %6
%43 = call i32 @XCloseDisplay(i32* %42)
store i32 1, i32* %3
br label %44
44: ; preds = %12, %11
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32, i32, i32, i32, i32, i32, i32 }
define i32 @get_pointer_coords(i32* nocapture writeonly %0, i32* nocapture writeonly %1) {
%3 = alloca %struct.TYPE_4__
%4 = bitcast %struct.TYPE_4__* %3 to i8*
%5 = tail call i32* @XOpenDisplay(i32* null)
%6 = icmp eq i32* %5, null
br i1 %6, label %21, label %7
7: ; preds = %2
%8 = tail call i32 @DefaultScreen(i32* %5)
%9 = tail call i32 @RootWindow(i32* %5, i32 %8)
%10 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0, i32 6
%11 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0, i32 5
%12 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0, i32 4
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0, i32 3
%14 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0, i32 0
%15 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0, i32 1
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0, i32 2
%17 = call i32 @XQueryPointer(i32* %5, i32 %9, i32* %10, i32* %11, i32* %12, i32* %13, i32* %14, i32* %15, i32* %16)
%18 = load i32, i32* %14
store i32 %18, i32* %0
%19 = load i32, i32* %15
store i32 %19, i32* %1
%20 = call i32 @XCloseDisplay(i32* %5)
br label %21
21: ; preds = %2, %7
%22 = phi i32 [ 1, %7 ], [ 0, %2 ]
ret i32 %22
}