#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*/ GC;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
unsigned long BlackPixel(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ DefaultRootWindow(int /*<<< orphan*/ *);
int /*<<< orphan*/ DefaultScreen(int /*<<< orphan*/ *);
scalar_t__ MapNotify;
int /*<<< orphan*/ StructureNotifyMask;
unsigned long WhitePixel(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XCreateGC(int /*<<< orphan*/ *, int /*<<< orphan*/,
                             int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ XCreateSimpleWindow(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                       int /*<<< orphan*/, int /*<<< orphan*/,
                                       int, int, int /*<<< orphan*/,
                                       unsigned long, unsigned long);
int /*<<< orphan*/ XDrawLine(int /*<<< orphan*/ *, int /*<<< orphan*/,
                             int /*<<< orphan*/, int, int, int, int);
int /*<<< orphan*/ XFlush(int /*<<< orphan*/ *);
int /*<<< orphan*/ XMapWindow(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XNextEvent(int /*<<< orphan*/ *, TYPE_1__ *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XSelextInput(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                int /*<<< orphan*/);
int /*<<< orphan*/ XSetForeground(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                  unsigned long);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  Display *d = XOpenDisplay(NULL);
  if (!d) {
    fprintf(stderr, "Could not open display.");
    exit(1);
  }
  unsigned long int black = BlackPixel(d, DefaultScreen(d));
  unsigned long int white = WhitePixel(d, DefaultScreen(d));
  Window w = XCreateSimpleWindow(d, DefaultRootWindow(d), 0, 0, 300, 300, 0,
                                 black, white);
  XSelextInput(d, w, StructureNotifyMask);
  XMapWindow(d, w);
  GC gc = XCreateGC(d, w, 0, NULL);
  XSetForeground(d, gc, white);
  while (1) {
    XEvent e;
    XNextEvent(d, &e);
    if (e.type == MapNotify)
      break;
  }
  XDrawLine(d, w, gc, 10, 60, 180, 20);
  XFlush(d);
  sleep(10);
  XCloseDisplay(d);
}


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   1050 <XOpenDisplay@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    125d <main+0x4d>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xdb2(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
call   1100 <DefaultScreen@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
call   10a0 <BlackPixel@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1100 <DefaultScreen@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
call   1040 <WhitePixel@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <DefaultRootWindow@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
mov    -0x20(%rbp),%r10
mov    -0x28(%rbp),%rax
xor    %ecx,%ecx
mov    $0x12c,%r9d
mov    %ecx,%edx
mov    %r9d,%r8d
movl   $0x0,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1090 <XCreateSimpleWindow@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    0x2ce8(%rip),%rax
mov    (%rax),%edx
call   10e0 <XSelextInput@plt>
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   10d0 <XMapWindow@plt>
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%esi
xor    %edx,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1080 <XCreateGC@plt>
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   10b0 <XSetForeground@plt>
mov    -0x18(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1070 <XNextEvent@plt>
mov    -0x38(%rbp),%rax
mov    0x2ca8(%rip),%rcx
cmp    (%rcx),%rax
jne    134e <main+0x13e>
jmp    1353 <main+0x143>
jmp    1328 <main+0x118>
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    $0xa,%ecx
mov    $0x3c,%r8d
mov    $0xb4,%r9d
movl   $0x14,(%rsp)
call   1130 <XDrawLine@plt>
mov    -0x18(%rbp),%rdi
call   10c0 <XFlush@plt>
mov    $0xa,%edi
call   1120 <sleep@plt>
mov    -0x18(%rbp),%rdi
call   1110 <XCloseDisplay@plt>
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
push   %rax
xor    %edi,%edi
call   1050 <XOpenDisplay@plt>
test   %rax,%rax
je     1348 <main+0x138>
mov    %rax,%r13
mov    %rax,%rdi
call   1100 <DefaultScreen@plt>
mov    %r13,%rdi
mov    %eax,%esi
call   10a0 <BlackPixel@plt>
mov    %rax,%rbp
mov    %r13,%rdi
call   1100 <DefaultScreen@plt>
mov    %r13,%rdi
mov    %eax,%esi
call   1040 <WhitePixel@plt>
mov    %rax,%r14
mov    %r13,%rdi
call   1030 <DefaultRootWindow@plt>
sub    $0x8,%rsp
mov    %r13,%rdi
mov    %eax,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    $0x12c,%r8d
mov    $0x12c,%r9d
push   %r14
push   %rbp
push   $0x0
call   1090 <XCreateSimpleWindow@plt>
add    $0x20,%rsp
mov    %eax,%r12d
mov    0x2d47(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
mov    %r12d,%esi
call   10e0 <XSelextInput@plt>
mov    %r13,%rdi
mov    %r12d,%esi
call   10d0 <XMapWindow@plt>
mov    %r13,%rdi
mov    %r12d,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1080 <XCreateGC@plt>
mov    %eax,%r15d
mov    %r13,%rdi
mov    %eax,%esi
mov    %r14,%rdx
call   10b0 <XSetForeground@plt>
mov    %rsp,%rbp
mov    0x2d16(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %rbp,%rsi
call   1070 <XNextEvent@plt>
mov    (%rsp),%rax
cmp    (%rbx),%rax
jne    12e0 <main+0xd0>
sub    $0x8,%rsp
mov    %r13,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
mov    $0xa,%ecx
mov    $0x3c,%r8d
mov    $0xb4,%r9d
push   $0x14
call   1130 <XDrawLine@plt>
add    $0x10,%rsp
mov    %r13,%rdi
call   10c0 <XFlush@plt>
mov    $0xa,%edi
call   1120 <sleep@plt>
mov    %r13,%rdi
call   1110 <XCloseDisplay@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c81(%rip),%rax
mov    (%rax),%edi
lea    0xca8(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64 }
@stderr = global i32 0
@.str = [24 x i8] c"Could not open display.\00"
@StructureNotifyMask = global i32 0
@MapNotify = global i64 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.TYPE_3__
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32* @XOpenDisplay(i32* null)
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = icmp ne i32* %13, null
br i1 %14, label %19, label %15
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i32*, i32** %6
%21 = load i32*, i32** %6
%22 = call i32 @DefaultScreen(i32* %21)
%23 = call i64 @BlackPixel(i32* %20, i32 %22)
store i64 %23, i64* %7
%24 = load i32*, i32** %6
%25 = load i32*, i32** %6
%26 = call i32 @DefaultScreen(i32* %25)
%27 = call i64 @WhitePixel(i32* %24, i32 %26)
store i64 %27, i64* %8
%28 = load i32*, i32** %6
%29 = load i32*, i32** %6
%30 = call i32 @DefaultRootWindow(i32* %29)
%31 = load i64, i64* %7
%32 = load i64, i64* %8
%33 = call i32 @XCreateSimpleWindow(i32* %28, i32 %30, i32 0, i32 0, i32 300, i32 300, i32 0, i64 %31, i64 %32)
store i32 %33, i32* %9
%34 = load i32*, i32** %6
%35 = load i32, i32* %9
%36 = load i32, i32* @StructureNotifyMask
%37 = call i32 @XSelextInput(i32* %34, i32 %35, i32 %36)
%38 = load i32*, i32** %6
%39 = load i32, i32* %9
%40 = call i32 @XMapWindow(i32* %38, i32 %39)
%41 = load i32*, i32** %6
%42 = load i32, i32* %9
%43 = call i32 @XCreateGC(i32* %41, i32 %42, i32 0, i32* null)
store i32 %43, i32* %10
%44 = load i32*, i32** %6
%45 = load i32, i32* %10
%46 = load i64, i64* %8
%47 = call i32 @XSetForeground(i32* %44, i32 %45, i64 %46)
br label %48
48: ; preds = %19, %56
%49 = load i32*, i32** %6
%50 = call i32 @XNextEvent(i32* %49, %struct.TYPE_3__* %11)
%51 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i32 0, i32 0
%52 = load i64, i64* %51
%53 = load i64, i64* @MapNotify
%54 = icmp eq i64 %52, %53
br i1 %54, label %55, label %56
55: ; preds = %48
br label %57
56: ; preds = %48
br label %48
57: ; preds = %55
%58 = load i32*, i32** %6
%59 = load i32, i32* %9
%60 = load i32, i32* %10
%61 = call i32 @XDrawLine(i32* %58, i32 %59, i32 %60, i32 10, i32 60, i32 180, i32 20)
%62 = load i32*, i32** %6
%63 = call i32 @XFlush(i32* %62)
%64 = call i32 @sleep(i32 10)
%65 = load i32*, i32** %6
%66 = call i32 @XCloseDisplay(i32* %65)
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64 }
@stderr = global i32 0
@.str = [24 x i8] c"Could not open display.\00"
@StructureNotifyMask = global i32 0
@MapNotify = global i64 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.TYPE_3__
%4 = tail call i32* @XOpenDisplay(i32* null)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = tail call i32 @DefaultScreen(i32* %4)
%12 = tail call i64 @BlackPixel(i32* %4, i32 %11)
%13 = tail call i32 @DefaultScreen(i32* %4)
%14 = tail call i64 @WhitePixel(i32* %4, i32 %13)
%15 = tail call i32 @DefaultRootWindow(i32* %4)
%16 = tail call i32 @XCreateSimpleWindow(i32* %4, i32 %15, i32 0, i32 0, i32 300, i32 300, i32 0, i64 %12, i64 %14)
%17 = load i32, i32* @StructureNotifyMask
%18 = tail call i32 @XSelextInput(i32* %4, i32 %16, i32 %17)
%19 = tail call i32 @XMapWindow(i32* %4, i32 %16)
%20 = tail call i32 @XCreateGC(i32* %4, i32 %16, i32 0, i32* null)
%21 = tail call i32 @XSetForeground(i32* %4, i32 %20, i64 %14)
%22 = bitcast %struct.TYPE_3__* %3 to i8*
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 0
br label %24
24: ; preds = %24, %10
%25 = call i32 @XNextEvent(i32* %4, %struct.TYPE_3__* %3)
%26 = load i64, i64* %23
%27 = load i64, i64* @MapNotify
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %24
29: ; preds = %24
%30 = call i32 @XDrawLine(i32* %4, i32 %16, i32 %20, i32 10, i32 60, i32 180, i32 20)
%31 = call i32 @XFlush(i32* %4)
%32 = call i32 @sleep(i32 10)
%33 = call i32 @XCloseDisplay(i32* %4)
ret i32 0
}