#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 */
struct TYPE_4__ {
  int x;
  int y;
  int width;
  int height;
};
struct TYPE_5__ {
  int type;
  TYPE_1__ xconfigure;
};
typedef TYPE_2__ XEvent;
typedef int /*<<< orphan*/ Window;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
#define ConfigureNotify 129
int /*<<< orphan*/ CopyFromParent;
#define Expose 128
int ExposureMask;
int /*<<< orphan*/ RootWindow(int /*<<< orphan*/ *, int /*<<< orphan*/);
int StructureNotifyMask;
int /*<<< orphan*/ WhitePixel(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XCreateWindow(int /*<<< orphan*/ *, int /*<<< orphan*/, int,
                                 int, int, int, int, int /*<<< orphan*/,
                                 int /*<<< orphan*/, int /*<<< orphan*/,
                                 int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ XFlush(int /*<<< orphan*/ *);
int /*<<< orphan*/ XMapWindow(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XNextEvent(int /*<<< orphan*/ *, TYPE_2__ *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XSelectInput(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ XSetWindowBackground(int /*<<< orphan*/ *,
                                        int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int main() {
  Display *display;
  Window win;
  XEvent report;
  XEvent msg;
  int x = 10, y = 10, h = 2000, w = 2000;
  display = XOpenDisplay(NULL);
  if (display == NULL) {
    fprintf(stderr, "couldn't connect to X server :0\n");
    return 0;
  }
  win = XCreateWindow(display, RootWindow(display, 0), x, y, w, h, 10,
                      CopyFromParent, CopyFromParent, CopyFromParent, 0, NULL);
  XSetWindowBackground(display, win, WhitePixel(display, 0));
  XMapWindow(display, win);
  XFlush(display);
  sleep(2);
  XSelectInput(display, win, ExposureMask | StructureNotifyMask);
  while (1) {
    XNextEvent(display, &report);
    switch (report.type) {
    case Expose:
      printf("exposed\n");
      break;
    case ConfigureNotify:
      x = report.xconfigure.x;
      y = report.xconfigure.y;
      w = report.xconfigure.width;
      h = report.xconfigure.height;
      printf("confignotify %i,%i-%ix%i\n", x, y, w, h);
      break;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0xa8,%rsp
movl   $0x0,-0xc(%rbp)
movl   $0xa,-0x4c(%rbp)
movl   $0xa,-0x50(%rbp)
movl   $0x7d0,-0x54(%rbp)
movl   $0x7d0,-0x58(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <XOpenDisplay@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1228 <main+0x68>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xde9(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %rbp
ret
mov    -0x18(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1090 <RootWindow@plt>
mov    -0x70(%rbp),%rdi
mov    %eax,%esi
mov    -0x4c(%rbp),%edx
mov    -0x50(%rbp),%ecx
mov    -0x58(%rbp),%r8d
mov    -0x54(%rbp),%r9d
mov    0x2d72(%rip),%rax
mov    (%rax),%r11d
mov    0x2d68(%rip),%rax
mov    (%rax),%r10d
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
xor    %ebx,%ebx
xor    %ebx,%ebx
movl   $0xa,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %eax,0x18(%rsp)
movl   $0x0,0x20(%rsp)
movq   $0x0,0x28(%rsp)
call   1080 <XCreateWindow@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1040 <WhitePixel@plt>
mov    -0x68(%rbp),%rdi
mov    -0x5c(%rbp),%esi
mov    %eax,%edx
call   10d0 <XSetWindowBackground@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10c0 <XMapWindow@plt>
mov    -0x18(%rbp),%rdi
call   10b0 <XFlush@plt>
mov    $0x2,%edi
call   10e0 <sleep@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    0x2cde(%rip),%rax
mov    (%rax),%edx
mov    0x2ce5(%rip),%rax
or     (%rax),%edx
call   10a0 <XSelectInput@plt>
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <XNextEvent@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x74(%rbp)
sub    $0x80,%eax
je     1338 <main+0x178>
jmp    1325 <main+0x165>
mov    -0x74(%rbp),%eax
sub    $0x81,%eax
je     134b <main+0x18b>
jmp    137e <main+0x1be>
lea    0xce2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    137e <main+0x1be>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x4c(%rbp),%esi
mov    -0x50(%rbp),%edx
mov    -0x58(%rbp),%ecx
mov    -0x54(%rbp),%r8d
lea    0xcb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1302 <main+0x142>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %edi,%edi
call   1060 <XOpenDisplay@plt>
test   %rax,%rax
je     12e1 <main+0x111>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
call   10a0 <RootWindow@plt>
mov    0x2dc9(%rip),%rcx
mov    (%rcx),%ebx
mov    %r14,%rdi
mov    %eax,%esi
mov    $0xa,%edx
mov    $0xa,%ecx
mov    $0x7d0,%r8d
mov    $0x7d0,%r9d
push   $0x0
push   $0x0
push   %rbx
push   %rbx
push   %rbx
push   $0xa
call   1090 <XCreateWindow@plt>
add    $0x30,%rsp
mov    %eax,%ebx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <WhitePixel@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   10e0 <XSetWindowBackground@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   10d0 <XMapWindow@plt>
mov    %r14,%rdi
call   10c0 <XFlush@plt>
mov    $0x2,%edi
call   10f0 <sleep@plt>
mov    0x2d67(%rip),%rax
mov    0x2d70(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %r14,%rdi
mov    %ebx,%esi
call   10b0 <XSelectInput@plt>
mov    %rsp,%rbx
lea    0xd99(%rip),%r15
lea    0xdac(%rip),%r12
jmp    12bb <main+0xeb>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x4(%rsp),%esi
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%ecx
mov    0x10(%rsp),%r8d
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <XNextEvent@plt>
mov    (%rsp),%eax
cmp    $0x81,%eax
je     12a0 <main+0xd0>
cmp    $0x80,%eax
jne    12bb <main+0xeb>
mov    %r12,%rdi
call   1030 <puts@plt>
jmp    12bb <main+0xeb>
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
lea    0xd0f(%rip),%rsi
call   1070 <fprintf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32, %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i32, i32, i32, i32 }
@stderr = global i32 0
@.str = [33 x i8] c"couldn't connect to X server :0\0A\00"
@CopyFromParent = global i32 0
@ExposureMask = global i32 0
@StructureNotifyMask = global i32 0
@.str.1 = [9 x i8] c"exposed\0A\00"
@.str.2 = [26 x i8] c"confignotify %i,%i-%ix%i\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca %struct.TYPE_5__
%5 = alloca %struct.TYPE_5__
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i32 10, i32* %6
store i32 10, i32* %7
store i32 2000, i32* %8
store i32 2000, i32* %9
%10 = call i32* @XOpenDisplay(i32* null)
store i32* %10, i32** %2
%11 = load i32*, i32** %2
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
ret i32 0
16: ; preds = %0
%17 = load i32*, i32** %2
%18 = load i32*, i32** %2
%19 = call i32 @RootWindow(i32* %18, i32 0)
%20 = load i32, i32* %6
%21 = load i32, i32* %7
%22 = load i32, i32* %9
%23 = load i32, i32* %8
%24 = load i32, i32* @CopyFromParent
%25 = load i32, i32* @CopyFromParent
%26 = load i32, i32* @CopyFromParent
%27 = call i32 @XCreateWindow(i32* %17, i32 %19, i32 %20, i32 %21, i32 %22, i32 %23, i32 10, i32 %24, i32 %25, i32 %26, i32 0, i32* null)
store i32 %27, i32* %3
%28 = load i32*, i32** %2
%29 = load i32, i32* %3
%30 = load i32*, i32** %2
%31 = call i32 @WhitePixel(i32* %30, i32 0)
%32 = call i32 @XSetWindowBackground(i32* %28, i32 %29, i32 %31)
%33 = load i32*, i32** %2
%34 = load i32, i32* %3
%35 = call i32 @XMapWindow(i32* %33, i32 %34)
%36 = load i32*, i32** %2
%37 = call i32 @XFlush(i32* %36)
%38 = call i32 @sleep(i32 2)
%39 = load i32*, i32** %2
%40 = load i32, i32* %3
%41 = load i32, i32* @ExposureMask
%42 = load i32, i32* @StructureNotifyMask
%43 = or i32 %41, %42
%44 = call i32 @XSelectInput(i32* %39, i32 %40, i32 %43)
br label %45
45: ; preds = %16, %70
%46 = load i32*, i32** %2
%47 = call i32 @XNextEvent(i32* %46, %struct.TYPE_5__* %4)
%48 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i32 0, i32 0
%49 = load i32, i32* %48
switch i32 %49, label %70 [
i32 128, label %50
i32 129, label %52
]
50: ; preds = %45
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %70
52: ; preds = %45
%53 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i32 0, i32 1
%54 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %53, i32 0, i32 0
%55 = load i32, i32* %54
store i32 %55, i32* %6
%56 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i32 0, i32 1
%57 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %56, i32 0, i32 1
%58 = load i32, i32* %57
store i32 %58, i32* %7
%59 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i32 0, i32 1
%60 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %59, i32 0, i32 2
%61 = load i32, i32* %60
store i32 %61, i32* %9
%62 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i32 0, i32 1
%63 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %62, i32 0, i32 3
%64 = load i32, i32* %63
store i32 %64, i32* %8
%65 = load i32, i32* %6
%66 = load i32, i32* %7
%67 = load i32, i32* %9
%68 = load i32, i32* %8
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %65, i32 %66, i32 %67, i32 %68)
br label %70
70: ; preds = %45, %52, %50
br label %45
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i32, i32, i32, i32 }
@stderr = global i32 0
@.str = [33 x i8] c"couldn't connect to X server :0\0A\00"
@CopyFromParent = global i32 0
@ExposureMask = global i32 0
@StructureNotifyMask = global i32 0
@.str.2 = [26 x i8] c"confignotify %i,%i-%ix%i\0A\00"
@str = [8 x i8] c"exposed\00"
define i32 @main() {
%1 = alloca %struct.TYPE_5__
%2 = bitcast %struct.TYPE_5__* %1 to i8*
%3 = tail call i32* @XOpenDisplay(i32* null)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
ret i32 0
8: ; preds = %0
%9 = tail call i32 @RootWindow(i32* %3, i32 0)
%10 = load i32, i32* @CopyFromParent
%11 = tail call i32 @XCreateWindow(i32* %3, i32 %9, i32 10, i32 10, i32 2000, i32 2000, i32 10, i32 %10, i32 %10, i32 %10, i32 0, i32* null)
%12 = tail call i32 @WhitePixel(i32* %3, i32 0)
%13 = tail call i32 @XSetWindowBackground(i32* %3, i32 %11, i32 %12)
%14 = tail call i32 @XMapWindow(i32* %3, i32 %11)
%15 = tail call i32 @XFlush(i32* %3)
%16 = tail call i32 @sleep(i32 2)
%17 = load i32, i32* @ExposureMask
%18 = load i32, i32* @StructureNotifyMask
%19 = or i32 %18, %17
%20 = tail call i32 @XSelectInput(i32* %3, i32 %11, i32 %19)
%21 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %1, i64 0, i32 0
%22 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %1, i64 0, i32 1, i32 0
%23 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %1, i64 0, i32 1, i32 1
%24 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %1, i64 0, i32 1, i32 2
%25 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %1, i64 0, i32 1, i32 3
br label %26
26: ; preds = %29, %8
%27 = call i32 @XNextEvent(i32* %3, %struct.TYPE_5__* %1)
%28 = load i32, i32* %21
switch i32 %28, label %29 [
i32 128, label %30
i32 129, label %32
]
29: ; preds = %26, %32, %30
br label %26
30: ; preds = %26
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %29
32: ; preds = %26
%33 = load i32, i32* %22
%34 = load i32, i32* %23
%35 = load i32, i32* %24
%36 = load i32, i32* %25
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %33, i32 %34, i32 %35, i32 %36)
br label %29
}