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

/* Variables and functions */
int /*<<< orphan*/ BlackPixel(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ DefaultGC(int /*<<< orphan*/ *, int);
int DefaultScreen(int /*<<< orphan*/ *);
scalar_t__ Expose;
int /*<<< orphan*/ ExposureMask;
int /*<<< orphan*/ RootWindow(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ WhitePixel(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XCreateSimpleWindow(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                       int /*<<< orphan*/, int /*<<< orphan*/,
                                       int, int, int, int /*<<< orphan*/,
                                       int /*<<< orphan*/);
int /*<<< orphan*/ XDrawString(int /*<<< orphan*/ *, int /*<<< orphan*/,
                               int /*<<< orphan*/, int, int, char *,
                               int /*<<< orphan*/);
int /*<<< orphan*/ XFillRectangle(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                  int /*<<< orphan*/, int, int, int, int);
int /*<<< orphan*/ XMapWindow(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XNextEvent(int /*<<< orphan*/ *, TYPE_1__ *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XSelectInput(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int main(void) {
  Display *display;
  int screen;
  Window root_window;
  Window window;
  XEvent event;
  if ((display = XOpenDisplay(NULL)) == NULL) {
    fprintf(stderr, "Cannot open display\n");
    exit(1);
  }
  screen = DefaultScreen(display);
  root_window = RootWindow(display, screen);
  window = XCreateSimpleWindow(display, root_window, 0, 0, 800, 600, 50,
                               BlackPixel(display, screen),
                               WhitePixel(display, screen));
  XSelectInput(display, window, ExposureMask);
  XMapWindow(display, window);
  for (;;) {
    XNextEvent(display, &event);
    if (event.type == Expose) {
      XFillRectangle(display, window, DefaultGC(display, screen), 20, 20, 10,
                     10);
      XDrawString(display, window, DefaultGC(display, screen), 10, 50,
                  "Hello world!", strlen("Hello world!"));
    }
  }
  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)
cmp    $0x0,%rax
jne    1235 <main+0x45>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
lea    0xdda(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1110 <DefaultScreen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10a0 <RootWindow@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10e0 <BlackPixel@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <WhitePixel@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%r10d
xor    %ecx,%ecx
mov    $0x320,%r8d
mov    $0x258,%r9d
mov    %ecx,%edx
movl   $0x32,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   10d0 <XCreateSimpleWindow@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    0x2d16(%rip),%rax
mov    (%rax),%edx
call   10b0 <XSelectInput@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10f0 <XMapWindow@plt>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1090 <XNextEvent@plt>
mov    -0x28(%rbp),%rax
mov    0x2d03(%rip),%rcx
cmp    (%rcx),%rax
jne    1379 <main+0x189>
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <DefaultGC@plt>
mov    -0x58(%rbp),%rdi
mov    -0x4c(%rbp),%esi
mov    %eax,%edx
mov    $0x14,%r8d
mov    $0xa,%r9d
mov    %r8d,%ecx
movl   $0xa,(%rsp)
call   1050 <XFillRectangle@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <DefaultGC@plt>
mov    %eax,-0x3c(%rbp)
lea    0xcc5(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%esi
mov    -0x3c(%rbp),%edx
mov    $0xa,%ecx
mov    $0x32,%r8d
lea    0xca4(%rip),%r9
mov    %eax,(%rsp)
call   10c0 <XDrawString@plt>
jmp    12cd <main+0xdd>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xor    %edi,%edi
call   1070 <XOpenDisplay@plt>
test   %rax,%rax
je     1326 <main+0x136>
mov    %rax,%r12
mov    %rax,%rdi
call   1110 <DefaultScreen@plt>
mov    %eax,%ebx
mov    %r12,%rdi
mov    %eax,%esi
call   10a0 <RootWindow@plt>
mov    %eax,%r15d
mov    %r12,%rdi
mov    %ebx,%esi
call   10e0 <BlackPixel@plt>
mov    %eax,%ebp
mov    %r12,%rdi
mov    %ebx,0x1c(%rsp)
mov    %ebx,%esi
call   1060 <WhitePixel@plt>
mov    %eax,0x10(%rsp)
mov    %ebp,0x8(%rsp)
movl   $0x32,(%rsp)
mov    %r12,%rdi
mov    %r15d,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    $0x320,%r8d
mov    $0x258,%r9d
call   10d0 <XCreateSimpleWindow@plt>
mov    %eax,%r13d
mov    0x2d5a(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    %r13d,%esi
call   10b0 <XSelectInput@plt>
mov    %r12,%rdi
mov    %r13d,%esi
call   10f0 <XMapWindow@plt>
lea    0x20(%rsp),%r15
mov    0x2d4e(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
call   1090 <XNextEvent@plt>
mov    0x20(%rsp),%rax
cmp    (%rbx),%rax
jne    12a0 <main+0xb0>
mov    %r12,%rdi
mov    0x1c(%rsp),%ebp
mov    %ebp,%esi
call   1040 <DefaultGC@plt>
movl   $0xa,(%rsp)
mov    %r12,%rdi
mov    %r13d,%esi
mov    %eax,%edx
mov    $0x14,%ecx
mov    $0x14,%r8d
mov    $0xa,%r9d
call   1050 <XFillRectangle@plt>
mov    %r12,%rdi
mov    %ebp,%esi
call   1040 <DefaultGC@plt>
mov    %eax,%ebp
lea    0xd1a(%rip),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,(%rsp)
mov    %r12,%rdi
mov    %r13d,%esi
mov    %ebp,%edx
mov    $0xa,%ecx
mov    $0x32,%r8d
mov    %r14,%r9
call   10c0 <XDrawString@plt>
jmp    12a0 <main+0xb0>
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
lea    0xcca(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64 }
@stderr = global i32 0
@.str = [21 x i8] c"Cannot open display\0A\00"
@ExposureMask = global i32 0
@Expose = global i64 0
@.str.1 = [13 x i8] c"Hello world!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.TYPE_3__
store i32 0, i32* %1
%7 = call i32* @XOpenDisplay(i32* null)
store i32* %7, i32** %2
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = load i32*, i32** %2
%15 = call i32 @DefaultScreen(i32* %14)
store i32 %15, i32* %3
%16 = load i32*, i32** %2
%17 = load i32, i32* %3
%18 = call i32 @RootWindow(i32* %16, i32 %17)
store i32 %18, i32* %4
%19 = load i32*, i32** %2
%20 = load i32, i32* %4
%21 = load i32*, i32** %2
%22 = load i32, i32* %3
%23 = call i32 @BlackPixel(i32* %21, i32 %22)
%24 = load i32*, i32** %2
%25 = load i32, i32* %3
%26 = call i32 @WhitePixel(i32* %24, i32 %25)
%27 = call i32 @XCreateSimpleWindow(i32* %19, i32 %20, i32 0, i32 0, i32 800, i32 600, i32 50, i32 %23, i32 %26)
store i32 %27, i32* %5
%28 = load i32*, i32** %2
%29 = load i32, i32* %5
%30 = load i32, i32* @ExposureMask
%31 = call i32 @XSelectInput(i32* %28, i32 %29, i32 %30)
%32 = load i32*, i32** %2
%33 = load i32, i32* %5
%34 = call i32 @XMapWindow(i32* %32, i32 %33)
br label %35
35: ; preds = %56, %13
%36 = load i32*, i32** %2
%37 = call i32 @XNextEvent(i32* %36, %struct.TYPE_3__* %6)
%38 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 0
%39 = load i64, i64* %38
%40 = load i64, i64* @Expose
%41 = icmp eq i64 %39, %40
br i1 %41, label %42, label %56
42: ; preds = %35
%43 = load i32*, i32** %2
%44 = load i32, i32* %5
%45 = load i32*, i32** %2
%46 = load i32, i32* %3
%47 = call i32 @DefaultGC(i32* %45, i32 %46)
%48 = call i32 @XFillRectangle(i32* %43, i32 %44, i32 %47, i32 20, i32 20, i32 10, i32 10)
%49 = load i32*, i32** %2
%50 = load i32, i32* %5
%51 = load i32*, i32** %2
%52 = load i32, i32* %3
%53 = call i32 @DefaultGC(i32* %51, i32 %52)
%54 = call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%55 = call i32 @XDrawString(i32* %49, i32 %50, i32 %53, i32 10, i32 50, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %42, %35
br label %35
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64 }
@stderr = global i32 0
@.str = [21 x i8] c"Cannot open display\0A\00"
@ExposureMask = global i32 0
@Expose = global i64 0
@.str.1 = [13 x i8] c"Hello world!\00"
define i32 @main() {
%1 = alloca %struct.TYPE_3__
%2 = bitcast %struct.TYPE_3__* %1 to i8*
%3 = tail call i32* @XOpenDisplay(i32* null)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = tail call i32 @DefaultScreen(i32* %3)
%11 = tail call i32 @RootWindow(i32* %3, i32 %10)
%12 = tail call i32 @BlackPixel(i32* %3, i32 %10)
%13 = tail call i32 @WhitePixel(i32* %3, i32 %10)
%14 = tail call i32 @XCreateSimpleWindow(i32* %3, i32 %11, i32 0, i32 0, i32 800, i32 600, i32 50, i32 %12, i32 %13)
%15 = load i32, i32* @ExposureMask
%16 = tail call i32 @XSelectInput(i32* %3, i32 %14, i32 %15)
%17 = tail call i32 @XMapWindow(i32* %3, i32 %14)
%18 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
br label %19
19: ; preds = %30, %9
%20 = call i32 @XNextEvent(i32* %3, %struct.TYPE_3__* %1)
%21 = load i64, i64* %18
%22 = load i64, i64* @Expose
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %30
24: ; preds = %19
%25 = call i32 @DefaultGC(i32* %3, i32 %10)
%26 = call i32 @XFillRectangle(i32* %3, i32 %14, i32 %25, i32 20, i32 20, i32 10, i32 10)
%27 = call i32 @DefaultGC(i32* %3, i32 %10)
%28 = call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @XDrawString(i32* %3, i32 %14, i32 %27, i32 10, i32 50, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %24, %19
br label %19
}