#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 */
typedef int /*<<< orphan*/ XImage;
struct TYPE_4__ {
  int /*<<< orphan*/ y;
  int /*<<< orphan*/ x;
};
struct TYPE_5__ {
  TYPE_1__ xbutton;
};
typedef TYPE_2__ XEvent;
typedef int /*<<< orphan*/ Display;
typedef int /*<<< orphan*/ Cursor;

/* Variables and functions */
int /*<<< orphan*/ AllPlanes;
int /*<<< orphan*/ ButtonReleaseMask;
int /*<<< orphan*/ CurrentTime;
int /*<<< orphan*/ DefaultRootWindow(int /*<<< orphan*/ *);
int /*<<< orphan*/ False;
int /*<<< orphan*/ GrabModeAsync;
int /*<<< orphan*/ XC_crosshair;
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XCreateFontCursor(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XDestroyImage(int /*<<< orphan*/ *);
int /*<<< orphan*/ XFreeCursor(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *XGetImage(int /*<<< orphan*/ *, int /*<<< orphan*/,
                              int /*<<< orphan*/, int /*<<< orphan*/, int, int,
                              int /*<<< orphan*/, int /*<<< orphan*/);
unsigned long XGetPixel(int /*<<< orphan*/ *, int /*<<< orphan*/,
                        int /*<<< orphan*/);
int /*<<< orphan*/ XGrabPointer(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/);
int /*<<< orphan*/ XNextEvent(int /*<<< orphan*/ *, TYPE_2__ *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XUngrabPointer(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ ZPixmap;
int /*<<< orphan*/ printf(char *, unsigned long);
int main(int argc, char **argv) {
  Display *display;
  Cursor cursor;
  XImage *image;
  unsigned long color;
  display = XOpenDisplay(NULL);
  cursor = XCreateFontCursor(display, XC_crosshair);
  XGrabPointer(display, DefaultRootWindow(display), False, ButtonReleaseMask,
               GrabModeAsync, GrabModeAsync, DefaultRootWindow(display), cursor,
               CurrentTime);
  XEvent e;
  XNextEvent(display, &e);
  image = XGetImage(display, DefaultRootWindow(display), e.xbutton.x,
                    e.xbutton.y, 1, 1, AllPlanes, ZPixmap);
  color = XGetPixel(image, 0, 0);
  XDestroyImage(image);
  printf("#%06X\n", color);
  XUngrabPointer(display, CurrentTime);
  XFreeCursor(display, cursor);
  XCloseDisplay(display);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <XOpenDisplay@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
call   1040 <XCreateFontCursor@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <DefaultRootWindow@plt>
mov    %eax,-0x54(%rbp)
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <DefaultRootWindow@plt>
mov    -0x60(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    -0x50(%rbp),%edx
mov    -0x4c(%rbp),%ecx
mov    -0x48(%rbp),%r8d
mov    -0x44(%rbp),%r9d
mov    %eax,%r11d
mov    -0x1c(%rbp),%r10d
mov    0x2d84(%rip),%rax
mov    (%rax),%eax
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1080 <XGrabPointer@plt>
mov    -0x18(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10b0 <XNextEvent@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <DefaultRootWindow@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
mov    -0x34(%rbp),%edx
mov    -0x38(%rbp),%ecx
mov    0x2d07(%rip),%rax
mov    (%rax),%r10d
mov    0x2d1d(%rip),%rax
mov    (%rax),%eax
mov    $0x1,%r9d
mov    %r9d,%r8d
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   10e0 <XGetImage@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1030 <XGetPixel@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <XDestroyImage@plt>
mov    -0x30(%rbp),%rsi
lea    0xd0c(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2ce4(%rip),%rax
mov    (%rax),%esi
call   10a0 <XUngrabPointer@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10c0 <XFreeCursor@plt>
mov    -0x18(%rbp),%rdi
call   10d0 <XCloseDisplay@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %edi,%edi
call   1090 <XOpenDisplay@plt>
mov    %rax,%rbx
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <XCreateFontCursor@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1050 <DefaultRootWindow@plt>
mov    %eax,%r15d
mov    0x2de5(%rip),%rax
mov    (%rax),%r12d
mov    0x2db3(%rip),%rax
mov    (%rax),%r13d
mov    0x2db1(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1050 <DefaultRootWindow@plt>
mov    0x2dc8(%rip),%rcx
mov    (%rcx),%r10d
sub    $0x8,%rsp
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %r13d,%ecx
mov    %ebp,%r8d
mov    %ebp,%r9d
push   %r10
push   %r14
push   %rax
call   1080 <XGrabPointer@plt>
add    $0x20,%rsp
mov    %rsp,%rsi
mov    %rbx,%rdi
call   10b0 <XNextEvent@plt>
mov    %rbx,%rdi
call   1050 <DefaultRootWindow@plt>
mov    (%rsp),%ecx
mov    0x4(%rsp),%edx
mov    0x2d48(%rip),%rsi
mov    (%rsi),%r10d
mov    0x2d5e(%rip),%rsi
mov    (%rsi),%ebp
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%r8d
mov    $0x1,%r9d
push   %rbp
push   %r10
call   10e0 <XGetImage@plt>
add    $0x10,%rsp
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <XGetPixel@plt>
mov    %rax,%r15
mov    %rbp,%rdi
call   1070 <XDestroyImage@plt>
lea    0xd4e(%rip),%rdi
mov    %r15,%rsi
call   1060 <printf@plt>
mov    0x2d27(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10a0 <XUngrabPointer@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   10c0 <XFreeCursor@plt>
mov    %rbx,%rdi
call   10d0 <XCloseDisplay@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i32, i32 }
@XC_crosshair = global i32 0
@False = global i32 0
@ButtonReleaseMask = global i32 0
@GrabModeAsync = global i32 0
@CurrentTime = global i32 0
@AllPlanes = global i32 0
@ZPixmap = global i32 0
@.str = [7 x i8] c"#%06X\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i64
%9 = alloca %struct.TYPE_5__
store i32 %0, i32* %3
store i8** %1, i8*** %4
%10 = call i32* @XOpenDisplay(i32* null)
store i32* %10, i32** %5
%11 = load i32*, i32** %5
%12 = load i32, i32* @XC_crosshair
%13 = call i32 @XCreateFontCursor(i32* %11, i32 %12)
store i32 %13, i32* %6
%14 = load i32*, i32** %5
%15 = load i32*, i32** %5
%16 = call i32 @DefaultRootWindow(i32* %15)
%17 = load i32, i32* @False
%18 = load i32, i32* @ButtonReleaseMask
%19 = load i32, i32* @GrabModeAsync
%20 = load i32, i32* @GrabModeAsync
%21 = load i32*, i32** %5
%22 = call i32 @DefaultRootWindow(i32* %21)
%23 = load i32, i32* %6
%24 = load i32, i32* @CurrentTime
%25 = call i32 @XGrabPointer(i32* %14, i32 %16, i32 %17, i32 %18, i32 %19, i32 %20, i32 %22, i32 %23, i32 %24)
%26 = load i32*, i32** %5
%27 = call i32 @XNextEvent(i32* %26, %struct.TYPE_5__* %9)
%28 = load i32*, i32** %5
%29 = load i32*, i32** %5
%30 = call i32 @DefaultRootWindow(i32* %29)
%31 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 0
%32 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %31, i32 0, i32 1
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 0
%35 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = load i32, i32* @AllPlanes
%38 = load i32, i32* @ZPixmap
%39 = call i32* @XGetImage(i32* %28, i32 %30, i32 %33, i32 %36, i32 1, i32 1, i32 %37, i32 %38)
store i32* %39, i32** %7
%40 = load i32*, i32** %7
%41 = call i64 @XGetPixel(i32* %40, i32 0, i32 0)
store i64 %41, i64* %8
%42 = load i32*, i32** %7
%43 = call i32 @XDestroyImage(i32* %42)
%44 = load i64, i64* %8
%45 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %44)
%46 = load i32*, i32** %5
%47 = load i32, i32* @CurrentTime
%48 = call i32 @XUngrabPointer(i32* %46, i32 %47)
%49 = load i32*, i32** %5
%50 = load i32, i32* %6
%51 = call i32 @XFreeCursor(i32* %49, i32 %50)
%52 = load i32*, i32** %5
%53 = call i32 @XCloseDisplay(i32* %52)
ret i32 0
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i32, i32 }
@XC_crosshair = global i32 0
@False = global i32 0
@ButtonReleaseMask = global i32 0
@GrabModeAsync = global i32 0
@CurrentTime = global i32 0
@AllPlanes = global i32 0
@ZPixmap = global i32 0
@.str = [7 x i8] c"#%06X\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.TYPE_5__
%4 = tail call i32* @XOpenDisplay(i32* null)
%5 = load i32, i32* @XC_crosshair
%6 = tail call i32 @XCreateFontCursor(i32* %4, i32 %5)
%7 = tail call i32 @DefaultRootWindow(i32* %4)
%8 = load i32, i32* @False
%9 = load i32, i32* @ButtonReleaseMask
%10 = load i32, i32* @GrabModeAsync
%11 = tail call i32 @DefaultRootWindow(i32* %4)
%12 = load i32, i32* @CurrentTime
%13 = tail call i32 @XGrabPointer(i32* %4, i32 %7, i32 %8, i32 %9, i32 %10, i32 %10, i32 %11, i32 %6, i32 %12)
%14 = bitcast %struct.TYPE_5__* %3 to i8*
%15 = call i32 @XNextEvent(i32* %4, %struct.TYPE_5__* %3)
%16 = call i32 @DefaultRootWindow(i32* %4)
%17 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 0, i32 1
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 0, i32 0
%20 = load i32, i32* %19
%21 = load i32, i32* @AllPlanes
%22 = load i32, i32* @ZPixmap
%23 = call i32* @XGetImage(i32* %4, i32 %16, i32 %18, i32 %20, i32 1, i32 1, i32 %21, i32 %22)
%24 = call i64 @XGetPixel(i32* %23, i32 0, i32 0)
%25 = call i32 @XDestroyImage(i32* %23)
%26 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %24)
%27 = load i32, i32* @CurrentTime
%28 = call i32 @XUngrabPointer(i32* %4, i32 %27)
%29 = call i32 @XFreeCursor(i32* %4, i32 %6)
%30 = call i32 @XCloseDisplay(i32* %4)
ret i32 0
}