#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__ {
  scalar_t__ type;
};
typedef TYPE_1__ XEvent;
typedef int /*<<< orphan*/ Window;
typedef int /*<<< orphan*/ Display;
typedef int /*<<< orphan*/ Atom;

/* Variables and functions */
int BlackPixel(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ ClientMessage;
int /*<<< orphan*/ DefaultRootWindow(int /*<<< orphan*/ *);
int /*<<< orphan*/ DefaultScreen(int /*<<< orphan*/ *);
int /*<<< orphan*/ ScreenOfDisplay(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XCreateSimpleWindow(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                       int /*<<< orphan*/, int /*<<< orphan*/,
                                       int, int, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ XDestroyWindow(int /*<<< orphan*/ *, int /*<<< orphan*/);
int XHeightOfScreen(int /*<<< orphan*/);
int /*<<< orphan*/ XInternAtom(int /*<<< orphan*/ *, char *,
                               int /*<<< orphan*/);
int /*<<< orphan*/ XMapWindow(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XNextEvent(int /*<<< orphan*/ *, TYPE_1__ *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XSetWMProtocols(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                   int /*<<< orphan*/ *, int);
int XWidthOfScreen(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int main(void) {
  Display *display;
  Window window;
  XEvent event;
  display = XOpenDisplay(NULL);
  if (display == NULL) {
    fprintf(stderr, "Error: Cannot open display!\n");
    return 1;
  }
  int width = XWidthOfScreen(ScreenOfDisplay(display, DefaultScreen(display)));
  int height =
      XHeightOfScreen(ScreenOfDisplay(display, DefaultScreen(display)));
  int blackColor = BlackPixel(display, DefaultScreen(display));
  window = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0, width,
                               height, 0, blackColor, blackColor);
  Atom delwindow = XInternAtom(display, "WM_DELETE_WINDOW", 0);
  XSetWMProtocols(display, window, &delwindow, 1);
  XMapWindow(display, window);
  for (;;) {
    XNextEvent(display, &event);
    if (event.type == ClientMessage)
      break;
  }
  XDestroyWindow(display, window);
  XCloseDisplay(display);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <XOpenDisplay@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1238 <main+0x48>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
lea    0xdd9(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1362 <main+0x172>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1100 <DefaultScreen@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
call   10e0 <ScreenOfDisplay@plt>
mov    %eax,%edi
call   1040 <XWidthOfScreen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1100 <DefaultScreen@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
call   10e0 <ScreenOfDisplay@plt>
mov    %eax,%edi
call   1050 <XHeightOfScreen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1100 <DefaultScreen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
call   10d0 <BlackPixel@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <DefaultRootWindow@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
mov    -0x24(%rbp),%r8d
mov    -0x28(%rbp),%r9d
mov    -0x2c(%rbp),%r10d
mov    -0x2c(%rbp),%eax
xor    %ecx,%ecx
mov    %ecx,%edx
movl   $0x0,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   10c0 <XCreateSimpleWindow@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xd2d(%rip),%rsi
xor    %edx,%edx
call   10b0 <XInternAtom@plt>
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x30(%rbp),%rdx
mov    $0x1,%ecx
call   1090 <XSetWMProtocols@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10f0 <XMapWindow@plt>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10a0 <XNextEvent@plt>
mov    -0x20(%rbp),%rax
mov    0x2cb5(%rip),%rcx
cmp    (%rcx),%rax
jne    1341 <main+0x151>
jmp    1346 <main+0x156>
jmp    131b <main+0x12b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <XDestroyWindow@plt>
mov    -0x10(%rbp),%rdi
call   1110 <XCloseDisplay@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1070 <XOpenDisplay@plt>
test   %rax,%rax
je     12fc <main+0x10c>
mov    %rax,%r12
mov    %rax,%rdi
call   1100 <DefaultScreen@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   10e0 <ScreenOfDisplay@plt>
mov    %eax,%edi
call   1040 <XWidthOfScreen@plt>
mov    %eax,%r14d
mov    %r12,%rdi
call   1100 <DefaultScreen@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   10e0 <ScreenOfDisplay@plt>
mov    %eax,%edi
call   1050 <XHeightOfScreen@plt>
mov    %eax,%r15d
mov    %r12,%rdi
call   1100 <DefaultScreen@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   10d0 <BlackPixel@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1030 <DefaultRootWindow@plt>
sub    $0x8,%rsp
mov    %r12,%rdi
mov    %eax,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14d,%r8d
mov    %r15d,%r9d
push   %rbp
push   %rbp
push   $0x0
call   10c0 <XCreateSimpleWindow@plt>
add    $0x20,%rsp
mov    %eax,%r14d
lea    0xd90(%rip),%rsi
mov    %r12,%rdi
xor    %edx,%edx
call   10b0 <XInternAtom@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %r12,%rdi
mov    %r14d,%esi
mov    $0x1,%ecx
call   1090 <XSetWMProtocols@plt>
mov    %r12,%rdi
mov    %r14d,%esi
call   10f0 <XMapWindow@plt>
lea    0x8(%rsp),%rbp
mov    0x2d21(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbp,%rsi
call   10a0 <XNextEvent@plt>
mov    0x8(%rsp),%rax
cmp    (%rbx),%rax
jne    12d0 <main+0xe0>
mov    %r12,%rdi
mov    %r14d,%esi
call   1060 <XDestroyWindow@plt>
mov    %r12,%rdi
call   1110 <XCloseDisplay@plt>
xor    %eax,%eax
jmp    1316 <main+0x126>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
lea    0xcf4(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64 }
@stderr = global i32 0
@.str = [29 x i8] c"Error: Cannot open display!\0A\00"
@.str.1 = [17 x i8] c"WM_DELETE_WINDOW\00"
@ClientMessage = global i64 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca %struct.TYPE_3__
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32* @XOpenDisplay(i32* null)
store i32* %9, i32** %2
%10 = load i32*, i32** %2
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %61
15: ; preds = %0
%16 = load i32*, i32** %2
%17 = load i32*, i32** %2
%18 = call i32 @DefaultScreen(i32* %17)
%19 = call i32 @ScreenOfDisplay(i32* %16, i32 %18)
%20 = call i32 @XWidthOfScreen(i32 %19)
store i32 %20, i32* %5
%21 = load i32*, i32** %2
%22 = load i32*, i32** %2
%23 = call i32 @DefaultScreen(i32* %22)
%24 = call i32 @ScreenOfDisplay(i32* %21, i32 %23)
%25 = call i32 @XHeightOfScreen(i32 %24)
store i32 %25, i32* %6
%26 = load i32*, i32** %2
%27 = load i32*, i32** %2
%28 = call i32 @DefaultScreen(i32* %27)
%29 = call i32 @BlackPixel(i32* %26, i32 %28)
store i32 %29, i32* %7
%30 = load i32*, i32** %2
%31 = load i32*, i32** %2
%32 = call i32 @DefaultRootWindow(i32* %31)
%33 = load i32, i32* %5
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = load i32, i32* %7
%37 = call i32 @XCreateSimpleWindow(i32* %30, i32 %32, i32 0, i32 0, i32 %33, i32 %34, i32 0, i32 %35, i32 %36)
store i32 %37, i32* %3
%38 = load i32*, i32** %2
%39 = call i32 @XInternAtom(i32* %38, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 0)
store i32 %39, i32* %8
%40 = load i32*, i32** %2
%41 = load i32, i32* %3
%42 = call i32 @XSetWMProtocols(i32* %40, i32 %41, i32* %8, i32 1)
%43 = load i32*, i32** %2
%44 = load i32, i32* %3
%45 = call i32 @XMapWindow(i32* %43, i32 %44)
br label %46
46: ; preds = %54, %15
%47 = load i32*, i32** %2
%48 = call i32 @XNextEvent(i32* %47, %struct.TYPE_3__* %4)
%49 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i32 0, i32 0
%50 = load i64, i64* %49
%51 = load i64, i64* @ClientMessage
%52 = icmp eq i64 %50, %51
br i1 %52, label %53, label %54
53: ; preds = %46
br label %55
54: ; preds = %46
br label %46
55: ; preds = %53
%56 = load i32*, i32** %2
%57 = load i32, i32* %3
%58 = call i32 @XDestroyWindow(i32* %56, i32 %57)
%59 = load i32*, i32** %2
%60 = call i32 @XCloseDisplay(i32* %59)
store i32 0, i32* %1
br label %61
61: ; preds = %55, %12
%62 = load i32, i32* %1
ret i32 %62
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64 }
@stderr = global i32 0
@.str = [29 x i8] c"Error: Cannot open display!\0A\00"
@.str.1 = [17 x i8] c"WM_DELETE_WINDOW\00"
@ClientMessage = global i64 0
define i32 @main() {
%1 = alloca %struct.TYPE_3__
%2 = alloca i32
%3 = bitcast %struct.TYPE_3__* %1 to i8*
%4 = tail call i32* @XOpenDisplay(i32* null)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %33
9: ; preds = %0
%10 = tail call i32 @DefaultScreen(i32* %4)
%11 = tail call i32 @ScreenOfDisplay(i32* %4, i32 %10)
%12 = tail call i32 @XWidthOfScreen(i32 %11)
%13 = tail call i32 @DefaultScreen(i32* %4)
%14 = tail call i32 @ScreenOfDisplay(i32* %4, i32 %13)
%15 = tail call i32 @XHeightOfScreen(i32 %14)
%16 = tail call i32 @DefaultScreen(i32* %4)
%17 = tail call i32 @BlackPixel(i32* %4, i32 %16)
%18 = tail call i32 @DefaultRootWindow(i32* %4)
%19 = tail call i32 @XCreateSimpleWindow(i32* %4, i32 %18, i32 0, i32 0, i32 %12, i32 %15, i32 0, i32 %17, i32 %17)
%20 = bitcast i32* %2 to i8*
%21 = tail call i32 @XInternAtom(i32* %4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 0)
store i32 %21, i32* %2
%22 = call i32 @XSetWMProtocols(i32* %4, i32 %19, i32* %2, i32 1)
%23 = call i32 @XMapWindow(i32* %4, i32 %19)
%24 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
br label %25
25: ; preds = %25, %9
%26 = call i32 @XNextEvent(i32* %4, %struct.TYPE_3__* %1)
%27 = load i64, i64* %24
%28 = load i64, i64* @ClientMessage
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %25
30: ; preds = %25
%31 = call i32 @XDestroyWindow(i32* %4, i32 %19)
%32 = call i32 @XCloseDisplay(i32* %4)
br label %33
33: ; preds = %30, %6
%34 = phi i32 [ 1, %6 ], [ 0, %30 ]
ret i32 %34
}