#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_8__ TYPE_3__;
typedef struct TYPE_7__ TYPE_2__;
typedef struct TYPE_6__ TYPE_1__;

/* Type definitions */
struct TYPE_7__ {
  int line_width;
  int /*<<< orphan*/ subwindow_mode;
  int /*<<< orphan*/ function;
};
typedef TYPE_2__ XGCValues;
struct TYPE_6__ {
  int x_root;
  int y_root;
};
struct TYPE_8__ {
  scalar_t__ type;
  TYPE_1__ xbutton;
};
typedef TYPE_3__ XEvent;
typedef int /*<<< orphan*/ Window;
typedef int /*<<< orphan*/ GC;
typedef int /*<<< orphan*/ Display;
typedef int /*<<< orphan*/ Cursor;

/* Variables and functions */
scalar_t__ ButtonPress;
int ButtonPressMask;
scalar_t__ ButtonRelease;
int ButtonReleaseMask;
int /*<<< orphan*/ CurrentTime;
int /*<<< orphan*/ DefaultRootWindow(int /*<<< orphan*/ *);
int GCFunction;
int GCLineWidth;
int GCSubwindowMode;
int /*<<< orphan*/ GXinvert;
int /*<<< orphan*/ GrabModeAsync;
int /*<<< orphan*/ IncludeInferiors;
scalar_t__ MotionNotify;
int /*<<< orphan*/ None;
int PointerMotionMask;
int /*<<< orphan*/ True;
int /*<<< orphan*/ XC_crosshair;
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XCreateFontCursor(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XCreateGC(int /*<<< orphan*/ *, int /*<<< orphan*/, int,
                             TYPE_2__ *);
int /*<<< orphan*/ XDrawRectangle(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                  int /*<<< orphan*/, int, int, unsigned int,
                                  unsigned int);
int /*<<< orphan*/ XFlush(int /*<<< orphan*/ *);
int /*<<< orphan*/ XFreeCursor(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XFreeGC(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XGrabPointer(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                int /*<<< orphan*/, int, int /*<<< orphan*/,
                                int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ XNextEvent(int /*<<< orphan*/ *, TYPE_3__ *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XSync(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ XUngrabPointer(int /*<<< orphan*/ *, int /*<<< orphan*/);
void xrectsel(unsigned *x_sel, unsigned *y_sel, unsigned *w_sel,
              unsigned *h_sel) {
  Display *dpy = XOpenDisplay(NULL);
  if (!dpy)
    return;
  Window root = DefaultRootWindow(dpy);
  XEvent ev;
  GC sel_gc;
  XGCValues sel_gv;
  int btn_pressed = 0;
  int x = 0, y = 0;
  unsigned int width = 0, height = 0;
  int start_x = 0, start_y = 0;
  Cursor cursor;
  cursor = XCreateFontCursor(dpy, XC_crosshair);
  XGrabPointer(dpy, root, True,
               PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
               GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime);
  sel_gv.function = GXinvert;
  sel_gv.subwindow_mode = IncludeInferiors;
  sel_gv.line_width = 1;
  sel_gc =
      XCreateGC(dpy, root, GCFunction | GCSubwindowMode | GCLineWidth, &sel_gv);
  for (;;) {
    XNextEvent(dpy, &ev);
    if (ev.type == ButtonPress) {
      btn_pressed = 1;
      x = start_x = ev.xbutton.x_root;
      y = start_y = ev.xbutton.y_root;
      width = height = 0;
    } else if (ev.type == MotionNotify) {
      if (!btn_pressed)
        continue;
      XDrawRectangle(dpy, root, sel_gc, x, y, width, height);
      x = ev.xbutton.x_root;
      y = ev.xbutton.y_root;
      if (x > start_x) {
        width = x - start_x;
        x = start_x;
      } else {
        width = start_x - x;
      }
      if (y > start_y) {
        height = y - start_y;
        y = start_y;
      } else {
        height = start_y - y;
      }
      XDrawRectangle(dpy, root, sel_gc, x, y, width, height);
      XFlush(dpy);
    } else if (ev.type == ButtonRelease)
      break;
  }
  XDrawRectangle(dpy, root, sel_gc, x, y, width, height);
  XFlush(dpy);
  XUngrabPointer(dpy, CurrentTime);
  XFreeCursor(dpy, cursor);
  XFreeGC(dpy, sel_gc);
  XSync(dpy, 1);
  *x_sel = x;
  *y_sel = y;
  *w_sel = width;
  *h_sel = height;
  XCloseDisplay(dpy);
}


x86 assembly (clang, -O0):
<xrectsel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <XOpenDisplay@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1208 <xrectsel+0x38>
jmp    14e1 <xrectsel+0x311>
mov    -0x28(%rbp),%rdi
call   1050 <DefaultRootWindow@plt>
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
movl   $0x0,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
movl   $0x0,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2d70(%rip),%rax
mov    (%rax),%esi
call   1040 <XCreateFontCursor@plt>
mov    %eax,-0x70(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    0x2d48(%rip),%rax
mov    (%rax),%edx
mov    0x2d7f(%rip),%rax
mov    (%rax),%ecx
mov    0x2d4e(%rip),%rax
or     (%rax),%ecx
mov    0x2d0d(%rip),%rax
or     (%rax),%ecx
mov    0x2d0c(%rip),%rax
mov    (%rax),%r8d
mov    0x2d02(%rip),%rax
mov    (%rax),%r9d
mov    0x2d18(%rip),%rax
mov    (%rax),%r11d
mov    -0x70(%rbp),%r10d
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1060 <XGrabPointer@plt>
mov    0x2d17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2c9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
movl   $0x1,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    0x2c99(%rip),%rax
mov    (%rax),%edx
mov    0x2cb0(%rip),%rax
or     (%rax),%edx
mov    0x2c77(%rip),%rax
or     (%rax),%edx
lea    -0x50(%rbp),%rcx
call   10b0 <XCreateGC@plt>
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1090 <XNextEvent@plt>
mov    -0x40(%rbp),%rax
mov    0x2c59(%rip),%rcx
cmp    (%rcx),%rax
jne    135c <xrectsel+0x18c>
movl   $0x1,-0x54(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    %eax,-0x58(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    %eax,-0x5c(%rbp)
movl   $0x0,-0x64(%rbp)
movl   $0x0,-0x60(%rbp)
jmp    144e <xrectsel+0x27e>
mov    -0x40(%rbp),%rax
mov    0x2c69(%rip),%rcx
cmp    (%rcx),%rax
jne    142b <xrectsel+0x25b>
cmpl   $0x0,-0x54(%rbp)
jne    137f <xrectsel+0x1af>
jmp    130f <xrectsel+0x13f>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x44(%rbp),%edx
mov    -0x58(%rbp),%ecx
mov    -0x5c(%rbp),%r8d
mov    -0x60(%rbp),%r9d
mov    -0x64(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <XDrawRectangle@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x68(%rbp),%eax
jle    13cb <xrectsel+0x1fb>
mov    -0x58(%rbp),%eax
sub    -0x68(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x68(%rbp),%eax
mov    %eax,-0x58(%rbp)
jmp    13d4 <xrectsel+0x204>
mov    -0x68(%rbp),%eax
sub    -0x58(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x6c(%rbp),%eax
jle    13f4 <xrectsel+0x224>
mov    -0x5c(%rbp),%eax
sub    -0x6c(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x6c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
jmp    13fd <xrectsel+0x22d>
mov    -0x6c(%rbp),%eax
sub    -0x5c(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x44(%rbp),%edx
mov    -0x58(%rbp),%ecx
mov    -0x5c(%rbp),%r8d
mov    -0x60(%rbp),%r9d
mov    -0x64(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <XDrawRectangle@plt>
mov    -0x28(%rbp),%rdi
call   10c0 <XFlush@plt>
jmp    1449 <xrectsel+0x279>
mov    -0x40(%rbp),%rax
mov    0x2b2a(%rip),%rcx
cmp    (%rcx),%rax
jne    1444 <xrectsel+0x274>
jmp    1453 <xrectsel+0x283>
jmp    1449 <xrectsel+0x279>
jmp    144e <xrectsel+0x27e>
jmp    130f <xrectsel+0x13f>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x44(%rbp),%edx
mov    -0x58(%rbp),%ecx
mov    -0x5c(%rbp),%r8d
mov    -0x60(%rbp),%r9d
mov    -0x64(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <XDrawRectangle@plt>
mov    -0x28(%rbp),%rdi
call   10c0 <XFlush@plt>
mov    -0x28(%rbp),%rdi
mov    0x2b51(%rip),%rax
mov    (%rax),%esi
call   1080 <XUngrabPointer@plt>
mov    -0x28(%rbp),%rdi
mov    -0x70(%rbp),%esi
call   10d0 <XFreeCursor@plt>
mov    -0x28(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   10e0 <XFreeGC@plt>
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
call   10a0 <XSync@plt>
mov    -0x58(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x5c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x60(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x64(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdi
call   10f0 <XCloseDisplay@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xrectsel>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbp
xor    %r15d,%r15d
xor    %edi,%edi
call   1070 <XOpenDisplay@plt>
test   %rax,%rax
je     1495 <xrectsel+0x2c5>
mov    %rax,%rbx
mov    %rbp,0x58(%rsp)
mov    %r13,0x60(%rsp)
mov    %r12,0x68(%rsp)
mov    %r14,0x70(%rsp)
mov    %rax,%rdi
call   1050 <DefaultRootWindow@plt>
mov    %eax,%ebp
mov    0x2d9b(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <XCreateFontCursor@plt>
mov    0x2d7a(%rip),%rcx
mov    (%rcx),%edx
mov    0x2db1(%rip),%rsi
mov    0x2d82(%rip),%rcx
mov    (%rcx),%ecx
or     (%rsi),%ecx
mov    0x2d3f(%rip),%rsi
or     (%rsi),%ecx
mov    0x2d3e(%rip),%rsi
mov    (%rsi),%r8d
mov    0x2d54(%rip),%rsi
mov    (%rsi),%edi
mov    0x2d6b(%rip),%rsi
mov    (%rsi),%esi
mov    %esi,0x10(%rsp)
mov    %eax,0x2c(%rsp)
mov    %eax,0x8(%rsp)
mov    %edi,(%rsp)
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r8d,%r9d
call   1060 <XGrabPointer@plt>
mov    0x2d4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x50(%rsp)
mov    0x2cd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4c(%rsp)
mov    0x2cdc(%rip),%rax
mov    0x2cf5(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
movl   $0x1,0x48(%rsp)
mov    0x2cb2(%rip),%rax
or     (%rax),%edx
lea    0x48(%rsp),%rcx
mov    %rbx,%rdi
mov    %ebp,0x28(%rsp)
mov    %ebp,%esi
call   10b0 <XCreateGC@plt>
mov    %eax,0x18(%rsp)
lea    0x38(%rsp),%r14
mov    0x2c95(%rip),%r12
mov    0x2cde(%rip),%rbp
xor    %r13d,%r13d
xor    %eax,%eax
jmp    130f <xrectsel+0x13f>
nopl   0x0(%rax)
mov    0x40(%rsp),%r13d
mov    0x44(%rsp),%eax
mov    $0x1,%r15d
movl   $0x0,0x20(%rsp)
mov    %r13d,0x34(%rsp)
mov    %eax,0x30(%rsp)
mov    %eax,0x24(%rsp)
movl   $0x0,0x1c(%rsp)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <XNextEvent@plt>
mov    0x38(%rsp),%rax
cmp    (%r12),%rax
je     1300 <xrectsel+0x130>
cmp    0x0(%rbp),%rax
jne    13f3 <xrectsel+0x223>
test   %r15d,%r15d
mov    $0x0,%r15d
je     1330 <xrectsel+0x160>
mov    0x1c(%rsp),%eax
mov    %eax,(%rsp)
mov    %rbx,%rdi
mov    0x28(%rsp),%r15d
mov    %r15d,%esi
mov    0x18(%rsp),%edx
mov    %r13d,%ecx
mov    0x24(%rsp),%r8d
mov    0x20(%rsp),%r9d
call   1030 <XDrawRectangle@plt>
mov    0x44(%rsp),%r8d
mov    %r8d,%eax
mov    0x30(%rsp),%edx
sub    %edx,%eax
neg    %eax
mov    %r8d,%ecx
sub    %edx,%ecx
cmovg  %edx,%r8d
cmovle %eax,%ecx
mov    0x40(%rsp),%r13d
mov    %r13d,%eax
mov    0x34(%rsp),%edx
sub    %edx,%eax
neg    %eax
mov    %r13d,%r9d
sub    %edx,%r9d
cmovg  %edx,%r13d
cmovle %eax,%r9d
mov    %ecx,0x1c(%rsp)
mov    %ecx,(%rsp)
mov    %rbx,%rdi
mov    %r15d,%esi
mov    0x18(%rsp),%edx
mov    %r13d,%ecx
mov    %r8d,0x24(%rsp)
mov    %r9d,0x20(%rsp)
call   1030 <XDrawRectangle@plt>
mov    %rbx,%rdi
call   10c0 <XFlush@plt>
mov    $0x1,%r15d
jmp    1330 <xrectsel+0x160>
mov    0x2b66(%rip),%rcx
cmp    (%rcx),%rax
jne    1330 <xrectsel+0x160>
mov    0x1c(%rsp),%r12d
mov    %r12d,(%rsp)
mov    %rbx,%rdi
mov    0x28(%rsp),%esi
mov    0x18(%rsp),%ebp
mov    %ebp,%edx
mov    %r13d,%ecx
mov    0x24(%rsp),%r14d
mov    %r14d,%r8d
mov    0x20(%rsp),%r15d
mov    %r15d,%r9d
call   1030 <XDrawRectangle@plt>
mov    %rbx,%rdi
call   10c0 <XFlush@plt>
mov    0x2b98(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <XUngrabPointer@plt>
mov    %rbx,%rdi
mov    0x2c(%rsp),%esi
call   10d0 <XFreeCursor@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   10e0 <XFreeGC@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   10a0 <XSync@plt>
mov    0x58(%rsp),%rax
mov    %r13d,(%rax)
mov    0x60(%rsp),%rax
mov    %r14d,(%rax)
mov    0x68(%rsp),%rax
mov    %r15d,(%rax)
mov    0x70(%rsp),%rax
mov    %r12d,(%rax)
mov    %rbx,%rdi
call   10f0 <XCloseDisplay@plt>
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_8__ = type { i64, %struct.TYPE_6__ }
%struct.TYPE_6__ = type { i32, i32 }
%struct.TYPE_7__ = type { i32, i32, i32 }
@XC_crosshair = global i32 0
@True = global i32 0
@PointerMotionMask = global i32 0
@ButtonPressMask = global i32 0
@ButtonReleaseMask = global i32 0
@GrabModeAsync = global i32 0
@None = global i32 0
@CurrentTime = global i32 0
@GXinvert = global i32 0
@IncludeInferiors = global i32 0
@GCFunction = global i32 0
@GCSubwindowMode = global i32 0
@GCLineWidth = global i32 0
@ButtonPress = global i64 0
@MotionNotify = global i64 0
@ButtonRelease = global i64 0
define void @xrectsel(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca %struct.TYPE_8__
%12 = alloca i32
%13 = alloca %struct.TYPE_7__
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%22 = call i32* @XOpenDisplay(i32* null)
store i32* %22, i32** %9
%23 = load i32*, i32** %9
%24 = icmp ne i32* %23, null
br i1 %24, label %26, label %25
25: ; preds = %4
br label %174
26: ; preds = %4
%27 = load i32*, i32** %9
%28 = call i32 @DefaultRootWindow(i32* %27)
store i32 %28, i32* %10
store i32 0, i32* %14
store i32 0, i32* %15
store i32 0, i32* %16
store i32 0, i32* %17
store i32 0, i32* %18
store i32 0, i32* %19
store i32 0, i32* %20
%29 = load i32*, i32** %9
%30 = load i32, i32* @XC_crosshair
%31 = call i32 @XCreateFontCursor(i32* %29, i32 %30)
store i32 %31, i32* %21
%32 = load i32*, i32** %9
%33 = load i32, i32* %10
%34 = load i32, i32* @True
%35 = load i32, i32* @PointerMotionMask
%36 = load i32, i32* @ButtonPressMask
%37 = or i32 %35, %36
%38 = load i32, i32* @ButtonReleaseMask
%39 = or i32 %37, %38
%40 = load i32, i32* @GrabModeAsync
%41 = load i32, i32* @GrabModeAsync
%42 = load i32, i32* @None
%43 = load i32, i32* %21
%44 = load i32, i32* @CurrentTime
%45 = call i32 @XGrabPointer(i32* %32, i32 %33, i32 %34, i32 %39, i32 %40, i32 %41, i32 %42, i32 %43, i32 %44)
%46 = load i32, i32* @GXinvert
%47 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %13, i32 0, i32 2
store i32 %46, i32* %47
%48 = load i32, i32* @IncludeInferiors
%49 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %13, i32 0, i32 1
store i32 %48, i32* %49
%50 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %13, i32 0, i32 0
store i32 1, i32* %50
%51 = load i32*, i32** %9
%52 = load i32, i32* %10
%53 = load i32, i32* @GCFunction
%54 = load i32, i32* @GCSubwindowMode
%55 = or i32 %53, %54
%56 = load i32, i32* @GCLineWidth
%57 = or i32 %55, %56
%58 = call i32 @XCreateGC(i32* %51, i32 %52, i32 %57, %struct.TYPE_7__* %13)
store i32 %58, i32* %12
br label %59
59: ; preds = %141, %81, %26
%60 = load i32*, i32** %9
%61 = call i32 @XNextEvent(i32* %60, %struct.TYPE_8__* %11)
%62 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %11, i32 0, i32 0
%63 = load i64, i64* %62
%64 = load i64, i64* @ButtonPress
%65 = icmp eq i64 %63, %64
br i1 %65, label %66, label %73
66: ; preds = %59
store i32 1, i32* %14
%67 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %11, i32 0, i32 1
%68 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %67, i32 0, i32 0
%69 = load i32, i32* %68
store i32 %69, i32* %19
store i32 %69, i32* %15
%70 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %11, i32 0, i32 1
%71 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %70, i32 0, i32 1
%72 = load i32, i32* %71
store i32 %72, i32* %20
store i32 %72, i32* %16
store i32 0, i32* %18
store i32 0, i32* %17
br label %141
73: ; preds = %59
%74 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %11, i32 0, i32 0
%75 = load i64, i64* %74
%76 = load i64, i64* @MotionNotify
%77 = icmp eq i64 %75, %76
br i1 %77, label %78, label %133
78: ; preds = %73
%79 = load i32, i32* %14
%80 = icmp ne i32 %79, 0
br i1 %80, label %82, label %81
81: ; preds = %78
br label %59
82: ; preds = %78
%83 = load i32*, i32** %9
%84 = load i32, i32* %10
%85 = load i32, i32* %12
%86 = load i32, i32* %15
%87 = load i32, i32* %16
%88 = load i32, i32* %17
%89 = load i32, i32* %18
%90 = call i32 @XDrawRectangle(i32* %83, i32 %84, i32 %85, i32 %86, i32 %87, i32 %88, i32 %89)
%91 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %11, i32 0, i32 1
%92 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %91, i32 0, i32 0
%93 = load i32, i32* %92
store i32 %93, i32* %15
%94 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %11, i32 0, i32 1
%95 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %94, i32 0, i32 1
%96 = load i32, i32* %95
store i32 %96, i32* %16
%97 = load i32, i32* %15
%98 = load i32, i32* %19
%99 = icmp sgt i32 %97, %98
br i1 %99, label %100, label %105
100: ; preds = %82
%101 = load i32, i32* %15
%102 = load i32, i32* %19
%103 = sub nsw i32 %101, %102
store i32 %103, i32* %17
%104 = load i32, i32* %19
store i32 %104, i32* %15
br label %109
105: ; preds = %82
%106 = load i32, i32* %19
%107 = load i32, i32* %15
%108 = sub nsw i32 %106, %107
store i32 %108, i32* %17
br label %109
109: ; preds = %105, %100
%110 = load i32, i32* %16
%111 = load i32, i32* %20
%112 = icmp sgt i32 %110, %111
br i1 %112, label %113, label %118
113: ; preds = %109
%114 = load i32, i32* %16
%115 = load i32, i32* %20
%116 = sub nsw i32 %114, %115
store i32 %116, i32* %18
%117 = load i32, i32* %20
store i32 %117, i32* %16
br label %122
118: ; preds = %109
%119 = load i32, i32* %20
%120 = load i32, i32* %16
%121 = sub nsw i32 %119, %120
store i32 %121, i32* %18
br label %122
122: ; preds = %118, %113
%123 = load i32*, i32** %9
%124 = load i32, i32* %10
%125 = load i32, i32* %12
%126 = load i32, i32* %15
%127 = load i32, i32* %16
%128 = load i32, i32* %17
%129 = load i32, i32* %18
%130 = call i32 @XDrawRectangle(i32* %123, i32 %124, i32 %125, i32 %126, i32 %127, i32 %128, i32 %129)
%131 = load i32*, i32** %9
%132 = call i32 @XFlush(i32* %131)
br label %140
133: ; preds = %73
%134 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %11, i32 0, i32 0
%135 = load i64, i64* %134
%136 = load i64, i64* @ButtonRelease
%137 = icmp eq i64 %135, %136
br i1 %137, label %138, label %139
138: ; preds = %133
br label %142
139: ; preds = %133
br label %140
140: ; preds = %139, %122
br label %141
141: ; preds = %140, %66
br label %59
142: ; preds = %138
%143 = load i32*, i32** %9
%144 = load i32, i32* %10
%145 = load i32, i32* %12
%146 = load i32, i32* %15
%147 = load i32, i32* %16
%148 = load i32, i32* %17
%149 = load i32, i32* %18
%150 = call i32 @XDrawRectangle(i32* %143, i32 %144, i32 %145, i32 %146, i32 %147, i32 %148, i32 %149)
%151 = load i32*, i32** %9
%152 = call i32 @XFlush(i32* %151)
%153 = load i32*, i32** %9
%154 = load i32, i32* @CurrentTime
%155 = call i32 @XUngrabPointer(i32* %153, i32 %154)
%156 = load i32*, i32** %9
%157 = load i32, i32* %21
%158 = call i32 @XFreeCursor(i32* %156, i32 %157)
%159 = load i32*, i32** %9
%160 = load i32, i32* %12
%161 = call i32 @XFreeGC(i32* %159, i32 %160)
%162 = load i32*, i32** %9
%163 = call i32 @XSync(i32* %162, i32 1)
%164 = load i32, i32* %15
%165 = load i32*, i32** %5
store i32 %164, i32* %165
%166 = load i32, i32* %16
%167 = load i32*, i32** %6
store i32 %166, i32* %167
%168 = load i32, i32* %17
%169 = load i32*, i32** %7
store i32 %168, i32* %169
%170 = load i32, i32* %18
%171 = load i32*, i32** %8
store i32 %170, i32* %171
%172 = load i32*, i32** %9
%173 = call i32 @XCloseDisplay(i32* %172)
br label %174
174: ; preds = %142, %25
ret void
}

LLVM IR (-O2):
%struct.TYPE_8__ = type { i64, %struct.TYPE_6__ }
%struct.TYPE_6__ = type { i32, i32 }
%struct.TYPE_7__ = type { i32, i32, i32 }
@XC_crosshair = global i32 0
@True = global i32 0
@PointerMotionMask = global i32 0
@ButtonPressMask = global i32 0
@ButtonReleaseMask = global i32 0
@GrabModeAsync = global i32 0
@None = global i32 0
@CurrentTime = global i32 0
@GXinvert = global i32 0
@IncludeInferiors = global i32 0
@GCFunction = global i32 0
@GCSubwindowMode = global i32 0
@GCLineWidth = global i32 0
@ButtonPress = global i64 0
@MotionNotify = global i64 0
@ButtonRelease = global i64 0
define void @xrectsel(i32* nocapture writeonly %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = alloca %struct.TYPE_8__
%6 = alloca %struct.TYPE_7__
%7 = tail call i32* @XOpenDisplay(i32* null)
%8 = icmp eq i32* %7, null
br i1 %8, label %93, label %9
9: ; preds = %4
%10 = tail call i32 @DefaultRootWindow(i32* %7)
%11 = bitcast %struct.TYPE_8__* %5 to i8*
%12 = bitcast %struct.TYPE_7__* %6 to i8*
%13 = load i32, i32* @XC_crosshair
%14 = tail call i32 @XCreateFontCursor(i32* %7, i32 %13)
%15 = load i32, i32* @True
%16 = load i32, i32* @PointerMotionMask
%17 = load i32, i32* @ButtonPressMask
%18 = or i32 %17, %16
%19 = load i32, i32* @ButtonReleaseMask
%20 = or i32 %18, %19
%21 = load i32, i32* @GrabModeAsync
%22 = load i32, i32* @None
%23 = load i32, i32* @CurrentTime
%24 = tail call i32 @XGrabPointer(i32* %7, i32 %10, i32 %15, i32 %20, i32 %21, i32 %21, i32 %22, i32 %14, i32 %23)
%25 = load i32, i32* @GXinvert
%26 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %6, i64 0, i32 2
store i32 %25, i32* %26
%27 = load i32, i32* @IncludeInferiors
%28 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %6, i64 0, i32 1
store i32 %27, i32* %28
%29 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %6, i64 0, i32 0
store i32 1, i32* %29
%30 = load i32, i32* @GCFunction
%31 = load i32, i32* @GCSubwindowMode
%32 = or i32 %31, %30
%33 = load i32, i32* @GCLineWidth
%34 = or i32 %32, %33
%35 = call i32 @XCreateGC(i32* %7, i32 %10, i32 %34, %struct.TYPE_7__* %6)
%36 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %5, i64 0, i32 0
%37 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %5, i64 0, i32 1, i32 0
%38 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %5, i64 0, i32 1, i32 1
br label %39
39: ; preds = %9, %57
%40 = phi i32 [ 0, %9 ], [ 1, %57 ]
%41 = phi i32 [ 0, %9 ], [ %58, %57 ]
%42 = phi i32 [ 0, %9 ], [ %59, %57 ]
br label %43
43: ; preds = %39, %65
%44 = phi i32 [ 1, %65 ], [ %40, %39 ]
%45 = phi i32 [ %72, %65 ], [ %41, %39 ]
%46 = phi i32 [ %77, %65 ], [ %42, %39 ]
%47 = phi i32 [ %73, %65 ], [ 0, %39 ]
%48 = phi i32 [ %78, %65 ], [ 0, %39 ]
br label %49
49: ; preds = %43, %81
%50 = phi i32 [ %52, %81 ], [ %44, %43 ]
br label %51
51: ; preds = %49, %63
%52 = phi i32 [ 0, %63 ], [ %50, %49 ]
%53 = call i32 @XNextEvent(i32* %7, %struct.TYPE_8__* %5)
%54 = load i64, i64* %36
%55 = load i64, i64* @ButtonPress
%56 = icmp eq i64 %54, %55
br i1 %56, label %57, label %60
57: ; preds = %51
%58 = load i32, i32* %37
%59 = load i32, i32* %38
br label %39
60: ; preds = %51
%61 = load i64, i64* @MotionNotify
%62 = icmp eq i64 %54, %61
br i1 %62, label %63, label %81
63: ; preds = %60
%64 = icmp eq i32 %52, 0
br i1 %64, label %51, label %65
65: ; preds = %63
%66 = call i32 @XDrawRectangle(i32* %7, i32 %10, i32 %35, i32 %45, i32 %46, i32 %47, i32 %48)
%67 = load i32, i32* %37
%68 = load i32, i32* %38
%69 = icmp sgt i32 %67, %41
%70 = sub nsw i32 %67, %41
%71 = sub nsw i32 %41, %67
%72 = select i1 %69, i32 %41, i32 %67
%73 = select i1 %69, i32 %70, i32 %71
%74 = icmp sgt i32 %68, %42
%75 = sub nsw i32 %68, %42
%76 = sub nsw i32 %42, %68
%77 = select i1 %74, i32 %42, i32 %68
%78 = select i1 %74, i32 %75, i32 %76
%79 = call i32 @XDrawRectangle(i32* %7, i32 %10, i32 %35, i32 %72, i32 %77, i32 %73, i32 %78)
%80 = call i32 @XFlush(i32* %7)
br label %43
81: ; preds = %60
%82 = load i64, i64* @ButtonRelease
%83 = icmp eq i64 %54, %82
br i1 %83, label %84, label %49
84: ; preds = %81
%85 = call i32 @XDrawRectangle(i32* %7, i32 %10, i32 %35, i32 %45, i32 %46, i32 %47, i32 %48)
%86 = call i32 @XFlush(i32* %7)
%87 = load i32, i32* @CurrentTime
%88 = call i32 @XUngrabPointer(i32* %7, i32 %87)
%89 = call i32 @XFreeCursor(i32* %7, i32 %14)
%90 = call i32 @XFreeGC(i32* %7, i32 %35)
%91 = call i32 @XSync(i32* %7, i32 1)
store i32 %45, i32* %0
store i32 %46, i32* %1
store i32 %47, i32* %2
store i32 %48, i32* %3
%92 = call i32 @XCloseDisplay(i32* %7)
br label %93
93: ; preds = %4, %84
ret void
}