#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ XEvent;
struct TYPE_3__ {
  int *l;
};
struct TYPE_4__ {
  int format;
  TYPE_1__ data;
  int /*<<< orphan*/ message_type;
  int /*<<< orphan*/ window;
  int /*<<< orphan*/ type;
};
typedef TYPE_2__ XClientMessageEvent;
typedef int /*<<< orphan*/ Window;
typedef int /*<<< orphan*/ Display;
typedef int /*<<< orphan*/ Bool;
typedef int /*<<< orphan*/ Atom;

/* Variables and functions */
int /*<<< orphan*/ AnyPropertyType;
int /*<<< orphan*/ ClientMessage;
int CurrentTime;
int /*<<< orphan*/ False;
int SubstructureNotifyMask;
int SubstructureRedirectMask;
scalar_t__ Success;
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XDefaultRootWindow(int /*<<< orphan*/ *);
int /*<<< orphan*/ XFree(unsigned char *);
scalar_t__ XGetWindowProperty(int /*<<< orphan*/ *, int /*<<< orphan*/,
                              int /*<<< orphan*/, long, long,
                              int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/ *, int *, unsigned long *,
                              unsigned long *, unsigned char **);
int /*<<< orphan*/ XInternAtom(int /*<<< orphan*/ *, char *,
                               int /*<<< orphan*/);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XSendEvent(int /*<<< orphan*/ *, int /*<<< orphan*/,
                              int /*<<< orphan*/, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ XSync(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, unsigned long);
int /*<<< orphan*/ strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  Display *display = XOpenDisplay(NULL);
  if (!display) {
    return (1);
  }
  Window root = XDefaultRootWindow(display);
  Atom property = XInternAtom(display, "_NET_ACTIVE_WINDOW", False);
  if (argc > 1) {
    Window window = (Window)strtoul(argv[1], NULL, 0);
    XClientMessageEvent ev;
    ev.type = ClientMessage;
    ev.window = window;
    ev.message_type = property;
    ev.format = 32;
    ev.data.l[0] = 1;
    ev.data.l[1] = CurrentTime;
    ev.data.l[2] = 0;
    ev.data.l[3] = 0;
    ev.data.l[4] = 0;
    XSendEvent(display, root, False,
               SubstructureRedirectMask | SubstructureNotifyMask,
               (XEvent *)&ev);
    XSync(display, False);
  } else {
    long offset = 0;
    long length = ~0;
    Bool delete = False;
    Atom req_type = AnyPropertyType;
    Atom actual_type_return;
    int actual_format_return;
    unsigned long nitems_return;
    unsigned long bytes_after_return;
    unsigned char *prop_return;
    if (XGetWindowProperty(display, root, property, offset, length, delete,
                           req_type, &actual_type_return, &actual_format_return,
                           &nitems_return, &bytes_after_return,
                           &prop_return) != Success) {
      XCloseDisplay(display);
      return (1);
    }
    printf("%lu\n", *(unsigned long *)prop_return);
    XFree(prop_return);
  }
  XCloseDisplay(display);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0xb8,%rsp
movl   $0x0,-0x1c(%rbp)
mov    %edi,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <XOpenDisplay@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11e2 <main+0x42>
movl   $0x1,-0x1c(%rbp)
jmp    139e <main+0x1fe>
mov    -0x30(%rbp),%rdi
call   1090 <XDefaultRootWindow@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2dd7(%rip),%rax
mov    (%rax),%edx
lea    0xdfe(%rip),%rsi
call   1070 <XInternAtom@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x1,-0x20(%rbp)
jle    12c6 <main+0x126>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10a0 <strtoul@plt>
mov    %eax,-0x3c(%rbp)
mov    0x2d97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x50(%rbp)
movl   $0x20,-0x60(%rbp)
mov    -0x58(%rbp),%rax
movl   $0x1,(%rax)
mov    0x2d7e(%rip),%rax
mov    (%rax),%ecx
mov    -0x58(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x58(%rbp),%rax
movl   $0x0,0x8(%rax)
mov    -0x58(%rbp),%rax
movl   $0x0,0xc(%rax)
mov    -0x58(%rbp),%rax
movl   $0x0,0x10(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    0x2d3e(%rip),%rax
mov    (%rax),%edx
mov    0x2d1d(%rip),%rax
mov    (%rax),%ecx
mov    0x2d0c(%rip),%rax
or     (%rax),%ecx
lea    -0x60(%rbp),%r8
call   1030 <XSendEvent@plt>
mov    -0x30(%rbp),%rdi
mov    0x2d16(%rip),%rax
mov    (%rax),%esi
call   1080 <XSync@plt>
jmp    138e <main+0x1ee>
movq   $0x0,-0x68(%rbp)
movq   $0xffffffffffffffff,-0x70(%rbp)
ff
mov    0x2cf3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    0x2cff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x38(%rbp),%edx
mov    -0x68(%rbp),%rcx
mov    -0x70(%rbp),%r8
mov    -0x74(%rbp),%r9d
mov    -0x78(%rbp),%r15d
lea    -0x7c(%rbp),%r14
lea    -0x80(%rbp),%rbx
lea    -0x88(%rbp),%r11
lea    -0x90(%rbp),%r10
lea    -0x98(%rbp),%rax
mov    %r15d,(%rsp)
mov    %r14,0x8(%rsp)
mov    %rbx,0x10(%rsp)
mov    %r11,0x18(%rsp)
mov    %r10,0x20(%rsp)
mov    %rax,0x28(%rsp)
call   10b0 <XGetWindowProperty@plt>
mov    0x2caa(%rip),%rcx
cmp    (%rcx),%rax
je     136c <main+0x1cc>
mov    -0x30(%rbp),%rdi
call   10c0 <XCloseDisplay@plt>
movl   $0x1,-0x1c(%rbp)
jmp    139e <main+0x1fe>
mov    -0x98(%rbp),%rax
mov    (%rax),%rsi
lea    0xc96(%rip),%rdi
call   1040 <printf@plt>
mov    -0x98(%rbp),%rdi
call   1050 <XFree@plt>
mov    -0x30(%rbp),%rdi
call   10c0 <XCloseDisplay@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xor    %edi,%edi
call   1050 <XOpenDisplay@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     124a <main+0xda>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <XDefaultRootWindow@plt>
mov    %eax,%r15d
mov    0x2e2f(%rip),%rbp
mov    0x0(%rbp),%edx
lea    0xe4d(%rip),%rsi
mov    %rbx,%rdi
call   1060 <XInternAtom@plt>
mov    0x0(%rbp),%r9d
mov    0x2e22(%rip),%rcx
mov    (%rcx),%ebp
lea    0x8(%rsp),%r10
lea    0x18(%rsp),%r11
lea    0x20(%rsp),%r12
lea    0x10(%rsp),%r13
xor    %r14d,%r14d
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %eax,%edx
xor    %ecx,%ecx
mov    $0xffffffffffffffff,%r8
push   %r10
push   %r11
push   %r12
push   %r13
lea    0x34(%rsp),%rax
push   %rax
push   %rbp
call   1080 <XGetWindowProperty@plt>
add    $0x30,%rsp
mov    0x2de9(%rip),%rcx
cmp    (%rcx),%rax
jne    123c <main+0xcc>
mov    0x8(%rsp),%rax
mov    (%rax),%rsi
lea    0xdf0(%rip),%rdi
call   1030 <printf@plt>
mov    0x8(%rsp),%rdi
call   1040 <XFree@plt>
mov    %rbx,%rdi
call   1090 <XCloseDisplay@plt>
jmp    124a <main+0xda>
mov    %rbx,%rdi
call   1090 <XCloseDisplay@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, %struct.TYPE_3__, i32, i32, i32 }
%struct.TYPE_3__ = type { i32* }
@.str = [19 x i8] c"_NET_ACTIVE_WINDOW\00"
@False = global i32 0
@ClientMessage = global i32 0
@CurrentTime = global i32 0
@SubstructureRedirectMask = global i32 0
@SubstructureNotifyMask = global i32 0
@AnyPropertyType = global i32 0
@Success = global i64 0
@.str.1 = [5 x i8] c"%lu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.TYPE_4__
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i64
%18 = alloca i64
%19 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%20 = call i32* @XOpenDisplay(i32* null)
store i32* %20, i32** %6
%21 = load i32*, i32** %6
%22 = icmp ne i32* %21, null
br i1 %22, label %24, label %23
23: ; preds = %2
store i32 1, i32* %3
br label %102
24: ; preds = %2
%25 = load i32*, i32** %6
%26 = call i32 @XDefaultRootWindow(i32* %25)
store i32 %26, i32* %7
%27 = load i32*, i32** %6
%28 = load i32, i32* @False
%29 = call i32 @XInternAtom(i32* %27, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %28)
store i32 %29, i32* %8
%30 = load i32, i32* %4
%31 = icmp sgt i32 %30, 1
br i1 %31, label %32, label %76
32: ; preds = %24
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @strtoul(i8* %35, i32* null, i32 0)
store i32 %36, i32* %9
%37 = load i32, i32* @ClientMessage
%38 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 4
store i32 %37, i32* %38
%39 = load i32, i32* %9
%40 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 3
store i32 %39, i32* %40
%41 = load i32, i32* %8
%42 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 2
store i32 %41, i32* %42
%43 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 0
store i32 32, i32* %43
%44 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 1
%45 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %44, i32 0, i32 0
%46 = load i32*, i32** %45
%47 = getelementptr inbounds i32, i32* %46, i64 0
store i32 1, i32* %47
%48 = load i32, i32* @CurrentTime
%49 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 1
%50 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %49, i32 0, i32 0
%51 = load i32*, i32** %50
%52 = getelementptr inbounds i32, i32* %51, i64 1
store i32 %48, i32* %52
%53 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 1
%54 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %53, i32 0, i32 0
%55 = load i32*, i32** %54
%56 = getelementptr inbounds i32, i32* %55, i64 2
store i32 0, i32* %56
%57 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 1
%58 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %57, i32 0, i32 0
%59 = load i32*, i32** %58
%60 = getelementptr inbounds i32, i32* %59, i64 3
store i32 0, i32* %60
%61 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 1
%62 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %61, i32 0, i32 0
%63 = load i32*, i32** %62
%64 = getelementptr inbounds i32, i32* %63, i64 4
store i32 0, i32* %64
%65 = load i32*, i32** %6
%66 = load i32, i32* %7
%67 = load i32, i32* @False
%68 = load i32, i32* @SubstructureRedirectMask
%69 = load i32, i32* @SubstructureNotifyMask
%70 = or i32 %68, %69
%71 = bitcast %struct.TYPE_4__* %10 to i32*
%72 = call i32 @XSendEvent(i32* %65, i32 %66, i32 %67, i32 %70, i32* %71)
%73 = load i32*, i32** %6
%74 = load i32, i32* @False
%75 = call i32 @XSync(i32* %73, i32 %74)
br label %99
76: ; preds = %24
store i64 0, i64* %11
store i64 -1, i64* %12
%77 = load i32, i32* @False
store i32 %77, i32* %13
%78 = load i32, i32* @AnyPropertyType
store i32 %78, i32* %14
%79 = load i32*, i32** %6
%80 = load i32, i32* %7
%81 = load i32, i32* %8
%82 = load i64, i64* %11
%83 = load i64, i64* %12
%84 = load i32, i32* %13
%85 = load i32, i32* %14
%86 = call i64 @XGetWindowProperty(i32* %79, i32 %80, i32 %81, i64 %82, i64 %83, i32 %84, i32 %85, i32* %15, i32* %16, i64* %17, i64* %18, i8** %19)
%87 = load i64, i64* @Success
%88 = icmp ne i64 %86, %87
br i1 %88, label %89, label %92
89: ; preds = %76
%90 = load i32*, i32** %6
%91 = call i32 @XCloseDisplay(i32* %90)
store i32 1, i32* %3
br label %102
92: ; preds = %76
%93 = load i8*, i8** %19
%94 = bitcast i8* %93 to i64*
%95 = load i64, i64* %94
%96 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %95)
%97 = load i8*, i8** %19
%98 = call i32 @XFree(i8* %97)
br label %99
99: ; preds = %92, %32
%100 = load i32*, i32** %6
%101 = call i32 @XCloseDisplay(i32* %100)
store i32 0, i32* %3
br label %102
102: ; preds = %99, %89, %23
%103 = load i32, i32* %3
ret i32 %103
}

LLVM IR (-O2):
@.str = [19 x i8] c"_NET_ACTIVE_WINDOW\00"
@False = global i32 0
@ClientMessage = global i32 0
@CurrentTime = global i32 0
@SubstructureRedirectMask = global i32 0
@SubstructureNotifyMask = global i32 0
@AnyPropertyType = global i32 0
@Success = global i64 0
@.str.1 = [5 x i8] c"%lu\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = tail call i32* @XOpenDisplay(i32* null)
%9 = icmp eq i32* %8, null
br i1 %9, label %35, label %10
10: ; preds = %2
%11 = tail call i32 @XDefaultRootWindow(i32* %8)
%12 = load i32, i32* @False
%13 = tail call i32 @XInternAtom(i32* %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = icmp slt i32 %0, 2
%15 = load i32, i32* @False
%16 = load i32, i32* @AnyPropertyType
%17 = bitcast i32* %3 to i8*
%18 = bitcast i32* %4 to i8*
%19 = bitcast i64* %5 to i8*
%20 = bitcast i64* %6 to i8*
%21 = bitcast i8** %7 to i8*
%22 = call i64 @XGetWindowProperty(i32* %8, i32 %11, i32 %13, i64 0, i64 -1, i32 %15, i32 %16, i32* %3, i32* %4, i64* %5, i64* %6, i8** %7)
%23 = load i64, i64* @Success
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %33
25: ; preds = %10
%26 = bitcast i8** %7 to i64**
%27 = load i64*, i64** %26
%28 = load i64, i64* %27
%29 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %28)
%30 = load i8*, i8** %7
%31 = call i32 @XFree(i8* %30)
%32 = call i32 @XCloseDisplay(i32* %8)
br label %35
33: ; preds = %10
%34 = call i32 @XCloseDisplay(i32* %8)
br label %35
35: ; preds = %33, %25, %2
%36 = phi i32 [ 1, %2 ], [ 0, %25 ], [ 1, %33 ]
ret i32 %36
}