#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 ExposureMask;
scalar_t__ KeyPress;
int KeyPressMask;
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, int, 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, scalar_t__, 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);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int main(void) {
  Display *display;
  Window window;
  XEvent event;
  char *msg = "Hello, World!";
  int s;
  display = XOpenDisplay(NULL);
  if (display == NULL) {
    fprintf(stderr, "Cannot open display\n");
    exit(1);
  }
  s = DefaultScreen(display);
  window =
      XCreateSimpleWindow(display, RootWindow(display, s), 10, 10, 200, 200, 1,
                          BlackPixel(display, s), WhitePixel(display, s));
  XSelectInput(display, window, ExposureMask | KeyPressMask);
  XMapWindow(display, window);
  int fall = 0;
  unsigned long fcount = 0;
  for (;;) {
    XNextEvent(display, &event);
    if (!(fcount++ % 10000))
      fall++;
    XFillRectangle(display, window, DefaultGC(display, s), 20, 0 + fall, 100,
                   100);
    if (event.type == Expose) {
      XFillRectangle(display, window, DefaultGC(display, s), 20, 0 + fall, 100,
                     100);
      XDrawString(display, window, DefaultGC(display, s), 50, 50, msg,
                  strlen(msg));
    }
    if (event.type == KeyPress)
      break;
  }
  XCloseDisplay(display);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xde7(%rip),%rax
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <XOpenDisplay@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1254 <main+0x54>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
lea    0xdc9(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1110 <DefaultScreen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   10a0 <RootWindow@plt>
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   10e0 <BlackPixel@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1060 <WhitePixel@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%esi
mov    -0x3c(%rbp),%r10d
mov    $0xa,%ecx
mov    $0xc8,%r9d
mov    %ecx,%edx
mov    %r9d,%r8d
movl   $0x1,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   10d0 <XCreateSimpleWindow@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2ced(%rip),%rax
mov    (%rax),%edx
mov    0x2d04(%rip),%rax
or     (%rax),%edx
call   10b0 <XSelectInput@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10f0 <XMapWindow@plt>
movl   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <XNextEvent@plt>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
mov    $0x2710,%ecx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
jne    1337 <main+0x137>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1040 <DefaultGC@plt>
mov    -0x58(%rbp),%rdi
mov    -0x4c(%rbp),%esi
mov    %eax,%edx
mov    -0x30(%rbp),%eax
add    $0x0,%eax
movslq %eax,%r8
mov    $0x14,%ecx
mov    $0x64,%r9d
movl   $0x64,(%rsp)
call   1050 <XFillRectangle@plt>
mov    -0x20(%rbp),%rax
mov    0x2c63(%rip),%rcx
cmp    (%rcx),%rax
jne    141e <main+0x21e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1040 <DefaultGC@plt>
mov    -0x80(%rbp),%rdi
mov    -0x74(%rbp),%esi
mov    %eax,%edx
mov    -0x30(%rbp),%eax
add    $0x0,%eax
movslq %eax,%r8
mov    $0x14,%ecx
mov    $0x64,%r9d
movl   $0x64,(%rsp)
call   1050 <XFillRectangle@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1040 <DefaultGC@plt>
mov    %eax,-0x64(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%esi
mov    -0x64(%rbp),%edx
mov    -0x60(%rbp),%r9
mov    $0x32,%r8d
mov    %r8d,%ecx
mov    %eax,(%rsp)
call   10c0 <XDrawString@plt>
mov    -0x20(%rbp),%rax
mov    0x2baf(%rip),%rcx
cmp    (%rcx),%rax
jne    1437 <main+0x237>
jmp    143c <main+0x23c>
jmp    12fe <main+0xfe>
mov    -0x10(%rbp),%rdi
call   1120 <XCloseDisplay@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xor    %r14d,%r14d
xor    %edi,%edi
call   1070 <XOpenDisplay@plt>
test   %rax,%rax
je     13eb <main+0x1eb>
mov    %rax,%r13
mov    %rax,%rdi
call   1110 <DefaultScreen@plt>
mov    %eax,%ebx
mov    %r13,%rdi
mov    %eax,%esi
call   10a0 <RootWindow@plt>
mov    %eax,%r12d
mov    %r13,%rdi
mov    %ebx,%esi
call   10e0 <BlackPixel@plt>
mov    %eax,%ebp
mov    %r13,%rdi
mov    %ebx,0x1c(%rsp)
mov    %ebx,%esi
call   1060 <WhitePixel@plt>
mov    %eax,0x10(%rsp)
mov    %ebp,0x8(%rsp)
movl   $0x1,(%rsp)
mov    %r13,%rdi
mov    %r12d,%esi
mov    $0xa,%edx
mov    $0xa,%ecx
mov    $0xc8,%r8d
mov    $0xc8,%r9d
call   10d0 <XCreateSimpleWindow@plt>
mov    %eax,%ebx
mov    0x2d32(%rip),%rax
mov    0x2d4b(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %r13,%rdi
mov    %ebx,%esi
call   10b0 <XSelectInput@plt>
mov    %r13,%rdi
mov    %ebx,0x18(%rsp)
mov    %ebx,%esi
call   10f0 <XMapWindow@plt>
xor    %r15d,%r15d
xor    %r12d,%r12d
jmp    12d8 <main+0xd8>
nopl   0x0(%rax)
add    $0xffffffffffffffff,%r15
add    $0x1,%r12
mov    0x2d09(%rip),%rcx
cmp    (%rcx),%rax
je     13d2 <main+0x1d2>
mov    %r14d,%ebp
mov    %r12,%rax
movabs $0x346dc5d63886594b,%rcx
c5 6d 34
mul    %rcx
shr    $0xb,%rdx
imul   $0x2710,%rdx,%rbx
mov    %r13,%rdi
lea    0x20(%rsp),%rsi
call   1090 <XNextEvent@plt>
xor    %r14d,%r14d
add    %r15,%rbx
sete   %r14b
add    %ebp,%r14d
mov    %r13,%rdi
mov    0x1c(%rsp),%esi
call   1040 <DefaultGC@plt>
movl   $0x64,(%rsp)
mov    %r13,%rdi
mov    0x18(%rsp),%esi
mov    %eax,%edx
mov    $0x14,%ecx
mov    %r14,%r8
mov    $0x64,%r9d
call   1050 <XFillRectangle@plt>
mov    0x20(%rsp),%rax
mov    0x2c9d(%rip),%rcx
cmp    (%rcx),%rax
jne    12c0 <main+0xc0>
mov    %r13,%rdi
mov    0x1c(%rsp),%ebx
mov    %ebx,%esi
call   1040 <DefaultGC@plt>
movl   $0x64,(%rsp)
mov    %r13,%rdi
mov    0x18(%rsp),%ebp
mov    %ebp,%esi
mov    %eax,%edx
mov    $0x14,%ecx
mov    %r14,%r8
mov    $0x64,%r9d
call   1050 <XFillRectangle@plt>
mov    %r13,%rdi
mov    %ebx,%esi
call   1040 <DefaultGC@plt>
mov    %r13,%rbx
mov    %eax,%r13d
lea    0xc62(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,(%rsp)
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r13d,%edx
mov    %rbx,%r13
mov    $0x32,%ecx
mov    $0x32,%r8d
lea    0xc3d(%rip),%r9
call   10c0 <XDrawString@plt>
mov    0x20(%rsp),%rax
jmp    12c0 <main+0xc0>
mov    %r13,%rdi
call   1120 <XCloseDisplay@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bd6(%rip),%rax
mov    (%rax),%edi
lea    0xc13(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64 }
@.str = [14 x i8] c"Hello, World!\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"Cannot open display\0A\00"
@ExposureMask = global i32 0
@KeyPressMask = global i32 0
@Expose = global i64 0
@KeyPress = global i64 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca %struct.TYPE_3__
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
store i32 0, i32* %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %5
%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 %16
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = load i32*, i32** %2
%18 = call i32 @DefaultScreen(i32* %17)
store i32 %18, i32* %6
%19 = load i32*, i32** %2
%20 = load i32*, i32** %2
%21 = load i32, i32* %6
%22 = call i32 @RootWindow(i32* %20, i32 %21)
%23 = load i32*, i32** %2
%24 = load i32, i32* %6
%25 = call i32 @BlackPixel(i32* %23, i32 %24)
%26 = load i32*, i32** %2
%27 = load i32, i32* %6
%28 = call i32 @WhitePixel(i32* %26, i32 %27)
%29 = call i32 @XCreateSimpleWindow(i32* %19, i32 %22, i32 10, i32 10, i32 200, i32 200, i32 1, i32 %25, i32 %28)
store i32 %29, i32* %3
%30 = load i32*, i32** %2
%31 = load i32, i32* %3
%32 = load i32, i32* @ExposureMask
%33 = load i32, i32* @KeyPressMask
%34 = or i32 %32, %33
%35 = call i32 @XSelectInput(i32* %30, i32 %31, i32 %34)
%36 = load i32*, i32** %2
%37 = load i32, i32* %3
%38 = call i32 @XMapWindow(i32* %36, i32 %37)
store i32 0, i32* %7
store i64 0, i64* %8
br label %39
39: ; preds = %88, %16
%40 = load i32*, i32** %2
%41 = call i32 @XNextEvent(i32* %40, %struct.TYPE_3__* %4)
%42 = load i64, i64* %8
%43 = add i64 %42, 1
store i64 %43, i64* %8
%44 = urem i64 %42, 10000
%45 = icmp ne i64 %44, 0
br i1 %45, label %49, label %46
46: ; preds = %39
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %49
49: ; preds = %46, %39
%50 = load i32*, i32** %2
%51 = load i32, i32* %3
%52 = load i32*, i32** %2
%53 = load i32, i32* %6
%54 = call i32 @DefaultGC(i32* %52, i32 %53)
%55 = load i32, i32* %7
%56 = add nsw i32 0, %55
%57 = sext i32 %56 to i64
%58 = call i32 @XFillRectangle(i32* %50, i32 %51, i32 %54, i32 20, i64 %57, i32 100, i32 100)
%59 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i32 0, i32 0
%60 = load i64, i64* %59
%61 = load i64, i64* @Expose
%62 = icmp eq i64 %60, %61
br i1 %62, label %63, label %82
63: ; preds = %49
%64 = load i32*, i32** %2
%65 = load i32, i32* %3
%66 = load i32*, i32** %2
%67 = load i32, i32* %6
%68 = call i32 @DefaultGC(i32* %66, i32 %67)
%69 = load i32, i32* %7
%70 = add nsw i32 0, %69
%71 = sext i32 %70 to i64
%72 = call i32 @XFillRectangle(i32* %64, i32 %65, i32 %68, i32 20, i64 %71, i32 100, i32 100)
%73 = load i32*, i32** %2
%74 = load i32, i32* %3
%75 = load i32*, i32** %2
%76 = load i32, i32* %6
%77 = call i32 @DefaultGC(i32* %75, i32 %76)
%78 = load i8*, i8** %5
%79 = load i8*, i8** %5
%80 = call i32 @strlen(i8* %79)
%81 = call i32 @XDrawString(i32* %73, i32 %74, i32 %77, i32 50, i32 50, i8* %78, i32 %80)
br label %82
82: ; preds = %63, %49
%83 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i32 0, i32 0
%84 = load i64, i64* %83
%85 = load i64, i64* @KeyPress
%86 = icmp eq i64 %84, %85
br i1 %86, label %87, label %88
87: ; preds = %82
br label %89
88: ; preds = %82
br label %39
89: ; preds = %87
%90 = load i32*, i32** %2
%91 = call i32 @XCloseDisplay(i32* %90)
ret i32 0
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64 }
@.str = [14 x i8] c"Hello, World!\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"Cannot open display\0A\00"
@ExposureMask = global i32 0
@KeyPressMask = global i32 0
@Expose = global i64 0
@KeyPress = global i64 0
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.1, 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 10, i32 10, i32 200, i32 200, i32 1, i32 %12, i32 %13)
%15 = load i32, i32* @ExposureMask
%16 = load i32, i32* @KeyPressMask
%17 = or i32 %16, %15
%18 = tail call i32 @XSelectInput(i32* %3, i32 %14, i32 %17)
%19 = tail call i32 @XMapWindow(i32* %3, i32 %14)
%20 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
br label %21
21: ; preds = %43, %9
%22 = phi i32 [ 0, %9 ], [ %29, %43 ]
%23 = phi i64 [ 0, %9 ], [ %25, %43 ]
%24 = call i32 @XNextEvent(i32* %3, %struct.TYPE_3__* %1)
%25 = add i64 %23, 1
%26 = urem i64 %23, 10000
%27 = icmp eq i64 %26, 0
%28 = zext i1 %27 to i32
%29 = add nuw nsw i32 %22, %28
%30 = call i32 @DefaultGC(i32* %3, i32 %10)
%31 = zext i32 %29 to i64
%32 = call i32 @XFillRectangle(i32* %3, i32 %14, i32 %30, i32 20, i64 %31, i32 100, i32 100)
%33 = load i64, i64* %20
%34 = load i64, i64* @Expose
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %43
36: ; preds = %21
%37 = call i32 @DefaultGC(i32* %3, i32 %10)
%38 = call i32 @XFillRectangle(i32* %3, i32 %14, i32 %37, i32 20, i64 %31, i32 100, i32 100)
%39 = call i32 @DefaultGC(i32* %3, i32 %10)
%40 = call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%41 = call i32 @XDrawString(i32* %3, i32 %14, i32 %39, i32 50, i32 50, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %40)
%42 = load i64, i64* %20
br label %43
43: ; preds = %36, %21
%44 = phi i64 [ %42, %36 ], [ %33, %21 ]
%45 = load i64, i64* @KeyPress
%46 = icmp eq i64 %44, %45
br i1 %46, label %47, label %21
47: ; preds = %43
%48 = call i32 @XCloseDisplay(i32* %3)
ret i32 0
}