#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_11__ TYPE_6__;
typedef struct TYPE_10__ TYPE_4__;
typedef struct TYPE_9__ TYPE_3__;
typedef struct TYPE_8__ TYPE_2__;
typedef struct TYPE_7__ TYPE_1__;

/* Type definitions */
struct TYPE_7__ {
  int window;
  int /*<<< orphan*/ event;
};
typedef TYPE_1__ xcb_unmap_notify_event_t;
struct TYPE_8__ {
  int /*<<< orphan*/ root;
};
typedef TYPE_2__ xcb_screen_t;
struct TYPE_9__ {
  int window;
  int /*<<< orphan*/ event;
};
typedef TYPE_3__ xcb_map_notify_event_t;
struct TYPE_10__ {
  int response_type;
};
typedef TYPE_4__ xcb_generic_event_t;
typedef int /*<<< orphan*/ xcb_drawable_t;
typedef int /*<<< orphan*/ xcb_connection_t;
typedef int /*<<< orphan*/ uint32_t;
struct TYPE_11__ {
  TYPE_2__ *data;
};

/* Variables and functions */
int /*<<< orphan*/ XCB_CW_EVENT_MASK;
int /*<<< orphan*/ XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY;
#define XCB_MAP_NOTIFY 129
#define XCB_UNMAP_NOTIFY 128
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ xcb_change_window_attributes_checked(int /*<<< orphan*/ *,
                                                        int /*<<< orphan*/,
                                                        int /*<<< orphan*/,
                                                        int /*<<< orphan*/ *);
int /*<<< orphan*/ *xcb_connect(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ xcb_flush(int /*<<< orphan*/ *);
int /*<<< orphan*/ xcb_get_setup(int /*<<< orphan*/ *);
TYPE_6__ xcb_setup_roots_iterator(int /*<<< orphan*/);
TYPE_4__ *xcb_wait_for_event(int /*<<< orphan*/ *);
void driver_main_loop() {
  xcb_connection_t *dpy;
  xcb_screen_t *screen;
  xcb_drawable_t root;
  xcb_generic_event_t *ev;
  dpy = xcb_connect(NULL, NULL);
  screen = xcb_setup_roots_iterator(xcb_get_setup(dpy)).data;
  root = screen->root;
  uint32_t values[2];
  values[0] = XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY;
  xcb_change_window_attributes_checked(dpy, root, XCB_CW_EVENT_MASK, values);
  xcb_flush(dpy);
  for (;;) {
    ev = xcb_wait_for_event(dpy);
    switch (ev->response_type & ~0x80) {
    case XCB_MAP_NOTIFY: {
      if (((xcb_map_notify_event_t *)ev)->event == root) {
        printf("Window was created %d\n",
               ((xcb_map_notify_event_t *)ev)->window);
      }
    } break;
    case XCB_UNMAP_NOTIFY: {
      if (((xcb_unmap_notify_event_t *)ev)->event == root) {
        printf("Window was destroyed %d\n",
               ((xcb_unmap_notify_event_t *)ev)->window);
      }
    } break;
    }
  }
}


x86 assembly (clang, -O0):
<driver_main_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
xor    %eax,%eax
mov    %eax,%esi
mov    %rsi,%rdi
call   1030 <xcb_connect@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <xcb_get_setup@plt>
mov    %eax,%edi
call   1060 <xcb_setup_roots_iterator@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2e19(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
call   1070 <xcb_change_window_attributes_checked@plt>
mov    -0x8(%rbp),%rdi
call   1040 <xcb_flush@plt>
mov    -0x8(%rbp),%rdi
call   1080 <xcb_wait_for_event@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
and    $0xffffff7f,%eax
mov    %eax,-0x34(%rbp)
sub    $0x80,%eax
je     1240 <driver_main_loop+0xd0>
jmp    1206 <driver_main_loop+0x96>
mov    -0x34(%rbp),%eax
sub    $0x81,%eax
jne    1267 <driver_main_loop+0xf7>
jmp    1219 <driver_main_loop+0xa9>
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
cmp    -0x14(%rbp),%eax
jne    123b <driver_main_loop+0xcb>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xdca(%rip),%rdi
call   1050 <printf@plt>
jmp    1267 <driver_main_loop+0xf7>
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
cmp    -0x14(%rbp),%eax
jne    1262 <driver_main_loop+0xf2>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xdba(%rip),%rdi
call   1050 <printf@plt>
jmp    1267 <driver_main_loop+0xf7>
jmp    11db <driver_main_loop+0x6b>

x86 assembly (clang, -O2):
<driver_main_loop>:
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
xor    %esi,%esi
call   1030 <xcb_connect@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <xcb_get_setup@plt>
mov    %eax,%edi
call   1050 <xcb_setup_roots_iterator@plt>
mov    (%rax),%esi
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
call   1060 <xcb_change_window_attributes_checked@plt>
mov    %rbx,%rdi
call   1040 <xcb_flush@plt>
nopl   (%rax)
mov    %rbx,%rdi
call   1070 <xcb_wait_for_event@plt>
jmp    11b0 <driver_main_loop+0x50>

LLVM IR (-O0):
%struct.TYPE_8__ = type { i32 }
%struct.TYPE_10__ = type { i32 }
%struct.TYPE_11__ = type { %struct.TYPE_8__* }
%struct.TYPE_9__ = type { i32, i32 }
%struct.TYPE_7__ = type { i32, i32 }
@XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY = global i32 0
@XCB_CW_EVENT_MASK = global i32 0
@.str = [23 x i8] c"Window was created %d\0A\00"
@.str.1 = [25 x i8] c"Window was destroyed %d\0A\00"
define void @driver_main_loop() {
%1 = alloca i32*
%2 = alloca %struct.TYPE_8__*
%3 = alloca i32
%4 = alloca %struct.TYPE_10__*
%5 = alloca %struct.TYPE_11__
%6 = alloca [2 x i32]
%7 = call i32* @xcb_connect(i32* null, i32* null)
store i32* %7, i32** %1
%8 = load i32*, i32** %1
%9 = call i32 @xcb_get_setup(i32* %8)
%10 = call %struct.TYPE_8__* @xcb_setup_roots_iterator(i32 %9)
%11 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %5, i32 0, i32 0
store %struct.TYPE_8__* %10, %struct.TYPE_8__** %11
%12 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %5, i32 0, i32 0
%13 = load %struct.TYPE_8__*, %struct.TYPE_8__** %12
store %struct.TYPE_8__* %13, %struct.TYPE_8__** %2
%14 = load %struct.TYPE_8__*, %struct.TYPE_8__** %2
%15 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %14, i32 0, i32 0
%16 = load i32, i32* %15
store i32 %16, i32* %3
%17 = load i32, i32* @XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
store i32 %17, i32* %18
%19 = load i32*, i32** %1
%20 = load i32, i32* %3
%21 = load i32, i32* @XCB_CW_EVENT_MASK
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%23 = call i32 @xcb_change_window_attributes_checked(i32* %19, i32 %20, i32 %21, i32* %22)
%24 = load i32*, i32** %1
%25 = call i32 @xcb_flush(i32* %24)
br label %26
26: ; preds = %61, %0
%27 = load i32*, i32** %1
%28 = call %struct.TYPE_10__* @xcb_wait_for_event(i32* %27)
store %struct.TYPE_10__* %28, %struct.TYPE_10__** %4
%29 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%30 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %29, i32 0, i32 0
%31 = load i32, i32* %30
%32 = and i32 %31, -129
switch i32 %32, label %61 [
i32 129, label %33
i32 128, label %47
]
33: ; preds = %26
%34 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%35 = bitcast %struct.TYPE_10__* %34 to %struct.TYPE_9__*
%36 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %35, i32 0, i32 1
%37 = load i32, i32* %36
%38 = load i32, i32* %3
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %46
40: ; preds = %33
%41 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%42 = bitcast %struct.TYPE_10__* %41 to %struct.TYPE_9__*
%43 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %40, %33
br label %61
47: ; preds = %26
%48 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%49 = bitcast %struct.TYPE_10__* %48 to %struct.TYPE_7__*
%50 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %49, i32 0, i32 1
%51 = load i32, i32* %50
%52 = load i32, i32* %3
%53 = icmp eq i32 %51, %52
br i1 %53, label %54, label %60
54: ; preds = %47
%55 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%56 = bitcast %struct.TYPE_10__* %55 to %struct.TYPE_7__*
%57 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %56, i32 0, i32 0
%58 = load i32, i32* %57
%59 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %54, %47
br label %61
61: ; preds = %26, %60, %46
br label %26
}

LLVM IR (-O2):
%struct.TYPE_8__ = type { i32 }
%struct.TYPE_10__ = type { i32 }
@XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY = global i32 0
@XCB_CW_EVENT_MASK = global i32 0
define void @driver_main_loop() {
%1 = alloca [2 x i32]
%2 = tail call i32* @xcb_connect(i32* null, i32* null)
%3 = tail call i32 @xcb_get_setup(i32* %2)
%4 = tail call %struct.TYPE_8__* @xcb_setup_roots_iterator(i32 %3)
%5 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %4, i64 0, i32 0
%6 = load i32, i32* %5
%7 = bitcast [2 x i32]* %1 to i8*
%8 = load i32, i32* @XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
store i32 %8, i32* %9
%10 = load i32, i32* @XCB_CW_EVENT_MASK
%11 = call i32 @xcb_change_window_attributes_checked(i32* %2, i32 %6, i32 %10, i32* %9)
%12 = call i32 @xcb_flush(i32* %2)
br label %13
13: ; preds = %13, %0
%14 = call %struct.TYPE_10__* @xcb_wait_for_event(i32* %2)
br label %13
}