#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 uint32_t;
typedef scalar_t__ int32_t;
typedef int /*<<< orphan*/ XEvent;
typedef int /*<<< orphan*/ XColor;
typedef int /*<<< orphan*/ Window;
typedef int /*<<< orphan*/ Pixmap;
typedef int /*<<< orphan*/ Display;
typedef int /*<<< orphan*/ Cursor;

/* Variables and functions */
scalar_t__ AlreadyGrabbed;
int ButtonPressMask;
int ButtonReleaseMask;
int /*<<< orphan*/ CurrentTime;
int /*<<< orphan*/ DefaultRootWindow(int /*<<< orphan*/ *);
int /*<<< orphan*/ GrabModeAsync;
scalar_t__ GrabSuccess;
int /*<<< orphan*/ LeaveWindowMask;
int PointerMotionMask;
int /*<<< orphan*/ True;
int /*<<< orphan*/ XCreateBitmapFromData(int /*<<< orphan*/ *,
                                         int /*<<< orphan*/, char *, int, int);
int /*<<< orphan*/ XCreatePixmapCursor(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                       int /*<<< orphan*/, int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ *, int, int);
scalar_t__ XGrabPointer(int /*<<< orphan*/ *, int /*<<< orphan*/,
                        int /*<<< orphan*/, int, int /*<<< orphan*/,
                        int /*<<< orphan*/, int /*<<< orphan*/,
                        int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ XMaskEvent(int /*<<< orphan*/ *, int /*<<< orphan*/,
                              int /*<<< orphan*/ *);
int /*<<< orphan*/ XSelectInput(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                int /*<<< orphan*/);
int32_t grab_and_hide_root_window_pointer(Display *display) {
  Window root_window = DefaultRootWindow(display);
  static char cursor_pixmap_bits[] = {0};
  Pixmap cursor_pixmap =
      XCreateBitmapFromData(display, root_window, cursor_pixmap_bits, 1, 1);
  XColor xcolor;
  Cursor cursor = XCreatePixmapCursor(display, cursor_pixmap, cursor_pixmap,
                                      &xcolor, &xcolor, 1, 1);
  uint32_t pointer_event_mask =
      PointerMotionMask | ButtonPressMask | ButtonReleaseMask;
  int32_t grab_result = XGrabPointer(
      display, root_window, True, pointer_event_mask, GrabModeAsync,
      GrabModeAsync, root_window, cursor, CurrentTime);
  if (grab_result != GrabSuccess) {
    if (grab_result == AlreadyGrabbed) {
      XSelectInput(display, DefaultRootWindow(display), LeaveWindowMask);
      XEvent leave_event;
      XMaskEvent(display, LeaveWindowMask, &leave_event);
      grab_result = XGrabPointer(display, root_window, True, pointer_event_mask,
                                 GrabModeAsync, GrabModeAsync, root_window,
                                 cursor, CurrentTime);
    }
  }
  return grab_result;
}


x86 assembly (clang, -O0):
<grab_and_hide_root_window_pointer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <DefaultRootWindow@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    0x2ed2(%rip),%rdx
mov    $0x1,%r8d
mov    %r8d,%ecx
call   1050 <XCreateBitmapFromData@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    -0x14(%rbp),%r8
mov    $0x1,%r9d
mov    %r8,%rcx
movl   $0x1,(%rsp)
call   1060 <XCreatePixmapCursor@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e2c(%rip),%rax
mov    (%rax),%eax
mov    0x2e0b(%rip),%rcx
or     (%rcx),%eax
mov    0x2de2(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2de7(%rip),%rax
mov    (%rax),%edx
mov    -0x1c(%rbp),%ecx
mov    0x2dcb(%rip),%rax
mov    (%rax),%r8d
mov    0x2dc1(%rip),%rax
mov    (%rax),%r9d
mov    -0xc(%rbp),%r11d
mov    -0x18(%rbp),%r10d
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1040 <XGrabPointer@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2d6c(%rip),%rcx
cmp    (%rcx),%rax
je     12df <grab_and_hide_root_window_pointer+0x17f>
mov    -0x28(%rbp),%rax
mov    0x2d68(%rip),%rcx
cmp    (%rcx),%rax
jne    12da <grab_and_hide_root_window_pointer+0x17a>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <DefaultRootWindow@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
mov    0x2d39(%rip),%rax
mov    (%rax),%edx
call   1070 <XSelectInput@plt>
mov    -0x8(%rbp),%rdi
mov    0x2d27(%rip),%rax
mov    (%rax),%esi
lea    -0x2c(%rbp),%rdx
call   1080 <XMaskEvent@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2d36(%rip),%rax
mov    (%rax),%edx
mov    -0x1c(%rbp),%ecx
mov    0x2d1a(%rip),%rax
mov    (%rax),%r8d
mov    0x2d10(%rip),%rax
mov    (%rax),%r9d
mov    -0xc(%rbp),%r11d
mov    -0x18(%rbp),%r10d
mov    0x2d1e(%rip),%rax
mov    (%rax),%eax
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1040 <XGrabPointer@plt>
mov    %rax,-0x28(%rbp)
jmp    12df <grab_and_hide_root_window_pointer+0x17f>
mov    -0x28(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grab_and_hide_root_window_pointer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <DefaultRootWindow@plt>
mov    %eax,%r14d
lea    0x2edb(%rip),%rdx
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%ecx
mov    $0x1,%r8d
call   1050 <XCreateBitmapFromData@plt>
sub    $0x8,%rsp
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
mov    %eax,%esi
mov    %eax,%edx
mov    %rcx,%r8
mov    $0x1,%r9d
push   $0x1
call   1060 <XCreatePixmapCursor@plt>
add    $0x10,%rsp
mov    %eax,%r15d
mov    0x2e30(%rip),%rax
mov    0x2e11(%rip),%rcx
mov    (%rcx),%ebp
or     (%rax),%ebp
mov    0x2de6(%rip),%rax
or     (%rax),%ebp
mov    0x2df5(%rip),%rax
mov    (%rax),%edx
mov    0x2ddc(%rip),%rax
mov    (%rax),%r8d
mov    0x2df2(%rip),%r12
mov    (%r12),%eax
sub    $0x8,%rsp
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %ebp,%ecx
mov    %r8d,%r9d
push   %rax
push   %r15
push   %r14
call   1040 <XGrabPointer@plt>
add    $0x20,%rsp
mov    0x2d8a(%rip),%rcx
cmp    (%rcx),%rax
je     1287 <grab_and_hide_root_window_pointer+0x127>
mov    0x2d8e(%rip),%rcx
cmp    (%rcx),%rax
jne    1287 <grab_and_hide_root_window_pointer+0x127>
mov    %rbx,%rdi
call   1030 <DefaultRootWindow@plt>
mov    0x2d72(%rip),%r13
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <XSelectInput@plt>
mov    0x0(%r13),%esi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1080 <XMaskEvent@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edx
mov    0x2d5d(%rip),%rax
mov    (%rax),%r8d
mov    (%r12),%eax
sub    $0x8,%rsp
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %ebp,%ecx
mov    %r8d,%r9d
push   %rax
push   %r15
push   %r14
call   1040 <XGrabPointer@plt>
add    $0x20,%rsp
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@grab_and_hide_root_window_pointer.cursor_pixmap_bits = internal global [1 x i8] zeroinitializer
@PointerMotionMask = global i32 0
@ButtonPressMask = global i32 0
@ButtonReleaseMask = global i32 0
@True = global i32 0
@GrabModeAsync = global i32 0
@CurrentTime = global i32 0
@GrabSuccess = global i64 0
@AlreadyGrabbed = global i64 0
@LeaveWindowMask = global i32 0
define i64 @grab_and_hide_root_window_pointer(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
store i32* %0, i32** %2
%10 = load i32*, i32** %2
%11 = call i32 @DefaultRootWindow(i32* %10)
store i32 %11, i32* %3
%12 = load i32*, i32** %2
%13 = load i32, i32* %3
%14 = call i32 @XCreateBitmapFromData(i32* %12, i32 %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @grab_and_hide_root_window_pointer.cursor_pixmap_bits, i64 0, i64 0), i32 1, i32 1)
store i32 %14, i32* %4
%15 = load i32*, i32** %2
%16 = load i32, i32* %4
%17 = load i32, i32* %4
%18 = call i32 @XCreatePixmapCursor(i32* %15, i32 %16, i32 %17, i32* %5, i32* %5, i32 1, i32 1)
store i32 %18, i32* %6
%19 = load i32, i32* @PointerMotionMask
%20 = load i32, i32* @ButtonPressMask
%21 = or i32 %19, %20
%22 = load i32, i32* @ButtonReleaseMask
%23 = or i32 %21, %22
store i32 %23, i32* %7
%24 = load i32*, i32** %2
%25 = load i32, i32* %3
%26 = load i32, i32* @True
%27 = load i32, i32* %7
%28 = load i32, i32* @GrabModeAsync
%29 = load i32, i32* @GrabModeAsync
%30 = load i32, i32* %3
%31 = load i32, i32* %6
%32 = load i32, i32* @CurrentTime
%33 = call i64 @XGrabPointer(i32* %24, i32 %25, i32 %26, i32 %27, i32 %28, i32 %29, i32 %30, i32 %31, i32 %32)
store i64 %33, i64* %8
%34 = load i64, i64* %8
%35 = load i64, i64* @GrabSuccess
%36 = icmp ne i64 %34, %35
br i1 %36, label %37, label %61
37: ; preds = %1
%38 = load i64, i64* %8
%39 = load i64, i64* @AlreadyGrabbed
%40 = icmp eq i64 %38, %39
br i1 %40, label %41, label %60
41: ; preds = %37
%42 = load i32*, i32** %2
%43 = load i32*, i32** %2
%44 = call i32 @DefaultRootWindow(i32* %43)
%45 = load i32, i32* @LeaveWindowMask
%46 = call i32 @XSelectInput(i32* %42, i32 %44, i32 %45)
%47 = load i32*, i32** %2
%48 = load i32, i32* @LeaveWindowMask
%49 = call i32 @XMaskEvent(i32* %47, i32 %48, i32* %9)
%50 = load i32*, i32** %2
%51 = load i32, i32* %3
%52 = load i32, i32* @True
%53 = load i32, i32* %7
%54 = load i32, i32* @GrabModeAsync
%55 = load i32, i32* @GrabModeAsync
%56 = load i32, i32* %3
%57 = load i32, i32* %6
%58 = load i32, i32* @CurrentTime
%59 = call i64 @XGrabPointer(i32* %50, i32 %51, i32 %52, i32 %53, i32 %54, i32 %55, i32 %56, i32 %57, i32 %58)
store i64 %59, i64* %8
br label %60
60: ; preds = %41, %37
br label %61
61: ; preds = %60, %1
%62 = load i64, i64* %8
ret i64 %62
}

LLVM IR (-O2):
@grab_and_hide_root_window_pointer.cursor_pixmap_bits = internal global [1 x i8] zeroinitializer
@PointerMotionMask = global i32 0
@ButtonPressMask = global i32 0
@ButtonReleaseMask = global i32 0
@True = global i32 0
@GrabModeAsync = global i32 0
@CurrentTime = global i32 0
@GrabSuccess = global i64 0
@AlreadyGrabbed = global i64 0
@LeaveWindowMask = global i32 0
define i64 @grab_and_hide_root_window_pointer(i32* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = tail call i32 @DefaultRootWindow(i32* %0)
%5 = tail call i32 @XCreateBitmapFromData(i32* %0, i32 %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @grab_and_hide_root_window_pointer.cursor_pixmap_bits, i64 0, i64 0), i32 1, i32 1)
%6 = bitcast i32* %2 to i8*
%7 = call i32 @XCreatePixmapCursor(i32* %0, i32 %5, i32 %5, i32* %2, i32* %2, i32 1, i32 1)
%8 = load i32, i32* @PointerMotionMask
%9 = load i32, i32* @ButtonPressMask
%10 = or i32 %9, %8
%11 = load i32, i32* @ButtonReleaseMask
%12 = or i32 %10, %11
%13 = load i32, i32* @True
%14 = load i32, i32* @GrabModeAsync
%15 = load i32, i32* @CurrentTime
%16 = call i64 @XGrabPointer(i32* %0, i32 %4, i32 %13, i32 %12, i32 %14, i32 %14, i32 %4, i32 %7, i32 %15)
%17 = load i64, i64* @GrabSuccess
%18 = icmp ne i64 %16, %17
%19 = load i64, i64* @AlreadyGrabbed
%20 = icmp eq i64 %16, %19
%21 = select i1 %18, i1 %20, i1 false
br i1 %21, label %22, label %33
22: ; preds = %1
%23 = call i32 @DefaultRootWindow(i32* %0)
%24 = load i32, i32* @LeaveWindowMask
%25 = call i32 @XSelectInput(i32* %0, i32 %23, i32 %24)
%26 = bitcast i32* %3 to i8*
%27 = load i32, i32* @LeaveWindowMask
%28 = call i32 @XMaskEvent(i32* %0, i32 %27, i32* %3)
%29 = load i32, i32* @True
%30 = load i32, i32* @GrabModeAsync
%31 = load i32, i32* @CurrentTime
%32 = call i64 @XGrabPointer(i32* %0, i32 %4, i32 %29, i32 %12, i32 %30, i32 %30, i32 %4, i32 %7, i32 %31)
br label %33
33: ; preds = %22, %1
%34 = phi i64 [ %32, %22 ], [ %16, %1 ]
ret i64 %34
}