#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 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 */
unsigned long BlackPixel(int /*<<< orphan*/ *, int);
#define ButtonPress 129
int ButtonPressMask;
#define ConfigureNotify 128
int /*<<< orphan*/ DefaultRootWindow(int /*<<< orphan*/ *);
int DefaultScreen(int /*<<< orphan*/ *);
int StructureNotifyMask;
unsigned long WhitePixel(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XCreateSimpleWindow(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                       int, int, int, int, int, unsigned long,
                                       unsigned long);
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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int screen_num, width, height;
  unsigned long background, border;
  Window win;
  XEvent ev;
  Display *dpy;
  dpy = XOpenDisplay(NULL);
  if (!dpy) {
    fprintf(stderr, "unable to connect to display\n");
    return 7;
  }
  screen_num = DefaultScreen(dpy);
  background = BlackPixel(dpy, screen_num);
  border = WhitePixel(dpy, screen_num);
  width = 400;
  height = 400;
  win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, width, height,
                            2, border, background);
  XSelectInput(dpy, win, ButtonPressMask | StructureNotifyMask);
  XMapWindow(dpy, win);
  while (1) {
    XNextEvent(dpy, &ev);
    switch (ev.type) {
    case ConfigureNotify:
      if (width != ev.xconfigure.width || height != ev.xconfigure.height) {
        width = ev.xconfigure.width;
        height = ev.xconfigure.height;
        printf("Size changed to: %d by %d\n", width, height);
      }
      break;
    case ButtonPress:
      XCloseDisplay(dpy);
      return 0;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <XOpenDisplay@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    120f <main+0x4f>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
lea    0xe02(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x7,-0x4(%rbp)
jmp    1345 <main+0x185>
mov    -0x48(%rbp),%rdi
call   10d0 <DefaultScreen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10b0 <BlackPixel@plt>
mov    %rax,-0x28(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <WhitePixel@plt>
mov    %rax,-0x30(%rbp)
movl   $0x190,-0x18(%rbp)
movl   $0x190,-0x1c(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <DefaultRootWindow@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
mov    -0x18(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    -0x30(%rbp),%r10
mov    -0x28(%rbp),%rax
mov    $0xa,%ecx
mov    %ecx,%edx
movl   $0x2,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   10a0 <XCreateSimpleWindow@plt>
mov    %eax,-0x34(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    0x2d4a(%rip),%rax
mov    (%rax),%edx
mov    0x2d31(%rip),%rax
or     (%rax),%edx
call   1090 <XSelectInput@plt>
mov    -0x48(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   10c0 <XMapWindow@plt>
mov    -0x48(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1080 <XNextEvent@plt>
mov    -0x40(%rbp),%eax
mov    %eax,-0x54(%rbp)
sub    $0x80,%eax
je     12f0 <main+0x130>
jmp    12dd <main+0x11d>
mov    -0x54(%rbp),%eax
sub    $0x81,%eax
je     132b <main+0x16b>
jmp    1340 <main+0x180>
mov    -0x18(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jne    1308 <main+0x148>
mov    -0x1c(%rbp),%eax
cmp    -0x38(%rbp),%eax
je     1326 <main+0x166>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xcfd(%rip),%rdi
call   1040 <printf@plt>
jmp    1340 <main+0x180>
mov    -0x48(%rbp),%rdi
call   10e0 <XCloseDisplay@plt>
movl   $0x0,-0x4(%rbp)
jmp    1345 <main+0x185>
jmp    12ba <main+0xfa>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %edi,%edi
call   1060 <XOpenDisplay@plt>
test   %rax,%rax
je     12d3 <main+0x113>
mov    %rax,%r12
mov    %rax,%rdi
call   10d0 <DefaultScreen@plt>
mov    %eax,%ebx
mov    %r12,%rdi
mov    %eax,%esi
call   10b0 <BlackPixel@plt>
mov    %rax,%rbp
mov    %r12,%rdi
mov    %ebx,%esi
call   1050 <WhitePixel@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1030 <DefaultRootWindow@plt>
sub    $0x8,%rsp
mov    $0x190,%r13d
mov    %r12,%rdi
mov    %eax,%esi
mov    $0xa,%edx
mov    $0xa,%ecx
mov    $0x190,%r8d
mov    $0x190,%r9d
push   %rbp
push   %rbx
push   $0x2
call   10a0 <XCreateSimpleWindow@plt>
add    $0x20,%rsp
mov    %eax,%ebx
mov    0x2da0(%rip),%rax
mov    0x2d89(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %r12,%rdi
mov    %ebx,%esi
call   1090 <XSelectInput@plt>
mov    %r12,%rdi
mov    %ebx,%esi
call   10c0 <XMapWindow@plt>
lea    0x8(%rsp),%r14
mov    $0x190,%r15d
jmp    1287 <main+0xc7>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x81,%eax
je     12c7 <main+0x107>
mov    %r12,%rdi
mov    %r14,%rsi
call   1080 <XNextEvent@plt>
mov    0x8(%rsp),%eax
cmp    $0x80,%eax
jne    1280 <main+0xc0>
mov    0xc(%rsp),%ebp
mov    0x10(%rsp),%ebx
cmp    %ebp,%r15d
jne    12af <main+0xef>
cmp    %ebx,%r13d
je     1287 <main+0xc7>
lea    0xd68(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1040 <printf@plt>
mov    %ebx,%r13d
mov    %ebp,%r15d
jmp    1287 <main+0xc7>
mov    %r12,%rdi
call   10e0 <XCloseDisplay@plt>
xor    %eax,%eax
jmp    12ed <main+0x12d>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
lea    0xd1d(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x7,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32, %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i32, i32 }
@stderr = global i32 0
@.str = [30 x i8] c"unable to connect to display\0A\00"
@ButtonPressMask = global i32 0
@StructureNotifyMask = global i32 0
@.str.1 = [27 x i8] c"Size changed to: %d by %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca %struct.TYPE_5__
%13 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32* @XOpenDisplay(i32* null)
store i32* %14, i32** %13
%15 = load i32*, i32** %13
%16 = icmp ne i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 7, i32* %3
br label %78
20: ; preds = %2
%21 = load i32*, i32** %13
%22 = call i32 @DefaultScreen(i32* %21)
store i32 %22, i32* %6
%23 = load i32*, i32** %13
%24 = load i32, i32* %6
%25 = call i64 @BlackPixel(i32* %23, i32 %24)
store i64 %25, i64* %9
%26 = load i32*, i32** %13
%27 = load i32, i32* %6
%28 = call i64 @WhitePixel(i32* %26, i32 %27)
store i64 %28, i64* %10
store i32 400, i32* %7
store i32 400, i32* %8
%29 = load i32*, i32** %13
%30 = load i32*, i32** %13
%31 = call i32 @DefaultRootWindow(i32* %30)
%32 = load i32, i32* %7
%33 = load i32, i32* %8
%34 = load i64, i64* %10
%35 = load i64, i64* %9
%36 = call i32 @XCreateSimpleWindow(i32* %29, i32 %31, i32 10, i32 10, i32 %32, i32 %33, i32 2, i64 %34, i64 %35)
store i32 %36, i32* %11
%37 = load i32*, i32** %13
%38 = load i32, i32* %11
%39 = load i32, i32* @ButtonPressMask
%40 = load i32, i32* @StructureNotifyMask
%41 = or i32 %39, %40
%42 = call i32 @XSelectInput(i32* %37, i32 %38, i32 %41)
%43 = load i32*, i32** %13
%44 = load i32, i32* %11
%45 = call i32 @XMapWindow(i32* %43, i32 %44)
br label %46
46: ; preds = %20, %77
%47 = load i32*, i32** %13
%48 = call i32 @XNextEvent(i32* %47, %struct.TYPE_5__* %12)
%49 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 0
%50 = load i32, i32* %49
switch i32 %50, label %77 [
i32 128, label %51
i32 129, label %74
]
51: ; preds = %46
%52 = load i32, i32* %7
%53 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 1
%54 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %53, i32 0, i32 0
%55 = load i32, i32* %54
%56 = icmp ne i32 %52, %55
br i1 %56, label %63, label %57
57: ; preds = %51
%58 = load i32, i32* %8
%59 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 1
%60 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %59, i32 0, i32 1
%61 = load i32, i32* %60
%62 = icmp ne i32 %58, %61
br i1 %62, label %63, label %73
63: ; preds = %57, %51
%64 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 1
%65 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %64, i32 0, i32 0
%66 = load i32, i32* %65
store i32 %66, i32* %7
%67 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 1
%68 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %67, i32 0, i32 1
%69 = load i32, i32* %68
store i32 %69, i32* %8
%70 = load i32, i32* %7
%71 = load i32, i32* %8
%72 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %70, i32 %71)
br label %73
73: ; preds = %63, %57
br label %77
74: ; preds = %46
%75 = load i32*, i32** %13
%76 = call i32 @XCloseDisplay(i32* %75)
store i32 0, i32* %3
br label %78
77: ; preds = %46, %73
br label %46
78: ; preds = %74, %17
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i32, i32 }
@stderr = global i32 0
@.str = [30 x i8] c"unable to connect to display\0A\00"
@ButtonPressMask = global i32 0
@StructureNotifyMask = global i32 0
@.str.1 = [27 x i8] c"Size changed to: %d by %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.TYPE_5__
%4 = bitcast %struct.TYPE_5__* %3 to i8*
%5 = tail call i32* @XOpenDisplay(i32* null)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %41
10: ; preds = %2
%11 = tail call i32 @DefaultScreen(i32* %5)
%12 = tail call i64 @BlackPixel(i32* %5, i32 %11)
%13 = tail call i64 @WhitePixel(i32* %5, i32 %11)
%14 = tail call i32 @DefaultRootWindow(i32* %5)
%15 = tail call i32 @XCreateSimpleWindow(i32* %5, i32 %14, i32 10, i32 10, i32 400, i32 400, i32 2, i64 %13, i64 %12)
%16 = load i32, i32* @ButtonPressMask
%17 = load i32, i32* @StructureNotifyMask
%18 = or i32 %17, %16
%19 = tail call i32 @XSelectInput(i32* %5, i32 %15, i32 %18)
%20 = tail call i32 @XMapWindow(i32* %5, i32 %15)
%21 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 0
%22 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 1, i32 0
%23 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 1, i32 1
br label %24
24: ; preds = %37, %10
%25 = phi i32 [ %33, %37 ], [ 400, %10 ]
%26 = phi i32 [ %31, %37 ], [ 400, %10 ]
br label %27
27: ; preds = %36, %24
%28 = call i32 @XNextEvent(i32* %5, %struct.TYPE_5__* %3)
%29 = load i32, i32* %21
switch i32 %29, label %36 [
i32 128, label %30
i32 129, label %39
]
30: ; preds = %27
%31 = load i32, i32* %22
%32 = icmp eq i32 %26, %31
%33 = load i32, i32* %23
%34 = icmp eq i32 %25, %33
%35 = select i1 %32, i1 %34, i1 false
br i1 %35, label %36, label %37
36: ; preds = %30, %27
br label %27
37: ; preds = %30
%38 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %31, i32 %33)
br label %24
39: ; preds = %27
%40 = call i32 @XCloseDisplay(i32* %5)
br label %41
41: ; preds = %39, %7
%42 = phi i32 [ 0, %39 ], [ 7, %7 ]
ret i32 %42
}