#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_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int type;
};
typedef TYPE_1__ XEvent;
typedef int /*<<< orphan*/ Window;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
#define ButtonPress 129
int ButtonPressMask;
#define KeyPress 128
int KeyPressMask;
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XFlush(int /*<<< orphan*/ *);
int /*<<< orphan*/ XNextEvent(int /*<<< orphan*/ *, TYPE_1__ *);
int /*<<< orphan*/ XSelectInput(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
void draw_done(Display *display, Window win) {
  XFlush(display);
  XSelectInput(display, win, ButtonPressMask | KeyPressMask);
  {
    int done = 0;
    XEvent an_event;
    while (!done) {
      XNextEvent(display, &an_event);
      switch (an_event.type) {
      case KeyPress:
      case ButtonPress:
        done = 1;
      }
    }
    XCloseDisplay(display);
  }
}


x86 assembly (clang, -O0):
<draw_done>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <XFlush@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2e82(%rip),%rax
mov    (%rax),%edx
mov    0x2e71(%rip),%rax
or     (%rax),%edx
call   1040 <XSelectInput@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1193 <draw_done+0x53>
jmp    11c0 <draw_done+0x80>
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <XNextEvent@plt>
mov    -0x18(%rbp),%eax
add    $0xffffff80,%eax
sub    $0x1,%eax
ja     11bb <draw_done+0x7b>
jmp    11b4 <draw_done+0x74>
movl   $0x1,-0x10(%rbp)
jmp    117d <draw_done+0x3d>
mov    -0x8(%rbp),%rdi
call   1060 <XCloseDisplay@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_done>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
call   1050 <XFlush@plt>
mov    0x2e8f(%rip),%rax
mov    0x2e80(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <XSelectInput@plt>
lea    0x8(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <XNextEvent@plt>
mov    0x8(%rsp),%eax
and    $0xfffffffe,%eax
cmp    $0x80,%eax
jne    1180 <draw_done+0x40>
mov    %rbx,%rdi
call   1060 <XCloseDisplay@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32 }
@ButtonPressMask = global i32 0
@KeyPressMask = global i32 0
define void @draw_done(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.TYPE_3__
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = load i32*, i32** %3
%8 = call i32 @XFlush(i32* %7)
%9 = load i32*, i32** %3
%10 = load i32, i32* %4
%11 = load i32, i32* @ButtonPressMask
%12 = load i32, i32* @KeyPressMask
%13 = or i32 %11, %12
%14 = call i32 @XSelectInput(i32* %9, i32 %10, i32 %13)
store i32 0, i32* %5
br label %15
15: ; preds = %25, %2
%16 = load i32, i32* %5
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
br i1 %18, label %19, label %26
19: ; preds = %15
%20 = load i32*, i32** %3
%21 = call i32 @XNextEvent(i32* %20, %struct.TYPE_3__* %6)
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 0
%23 = load i32, i32* %22
switch i32 %23, label %25 [
i32 128, label %24
i32 129, label %24
]
24: ; preds = %19, %19
store i32 1, i32* %5
br label %25
25: ; preds = %24, %19
br label %15
26: ; preds = %15
%27 = load i32*, i32** %3
%28 = call i32 @XCloseDisplay(i32* %27)
ret void
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32 }
@ButtonPressMask = global i32 0
@KeyPressMask = global i32 0
define void @draw_done(i32* %0, i32 %1) {
%3 = alloca %struct.TYPE_3__
%4 = tail call i32 @XFlush(i32* %0)
%5 = load i32, i32* @ButtonPressMask
%6 = load i32, i32* @KeyPressMask
%7 = or i32 %6, %5
%8 = tail call i32 @XSelectInput(i32* %0, i32 %1, i32 %7)
%9 = bitcast %struct.TYPE_3__* %3 to i8*
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 0
br label %11
11: ; preds = %2, %11
%12 = call i32 @XNextEvent(i32* %0, %struct.TYPE_3__* %3)
%13 = load i32, i32* %10
%14 = and i32 %13, -2
%15 = icmp eq i32 %14, 128
br i1 %15, label %16, label %11
16: ; preds = %11
%17 = call i32 @XCloseDisplay(i32* %0)
ret void
}