#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__ {
  int width;
  int height;
};
typedef TYPE_1__ XWindowAttributes;
typedef scalar_t__ Window;
typedef int /*<<< orphan*/ Status;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
scalar_t__ DefaultRootWindow(int /*<<< orphan*/ *);
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XGetWindowAttributes(int /*<<< orphan*/ *, scalar_t__,
                                        TYPE_1__ *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int getRootWindowSize(int *w, int *h) {
  Display *pdsp = NULL;
  Window wid = 0;
  XWindowAttributes xwAttr;
  pdsp = XOpenDisplay(NULL);
  if (!pdsp) {
    fprintf(stderr, "Failed to open default display.\n");
    return -1;
  }
  wid = DefaultRootWindow(pdsp);
  if (0 > wid) {
    fprintf(stderr, "Failed to obtain the root windows Id "
                    "of the default screen of given display.\n");
    return -2;
  }
  Status ret = XGetWindowAttributes(pdsp, wid, &xwAttr);
  *w = xwAttr.width;
  *h = xwAttr.height;
  XCloseDisplay(pdsp);
  return 0;
}


x86 assembly (clang, -O0):
<getRootWindowSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <XOpenDisplay@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a9 <getRootWindowSize+0x59>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1219 <getRootWindowSize+0xc9>
mov    -0x20(%rbp),%rdi
call   1030 <DefaultRootWindow@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jle    11e3 <getRootWindowSize+0x93>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1219 <getRootWindowSize+0xc9>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <XGetWindowAttributes@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
call   1070 <XCloseDisplay@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getRootWindowSize>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edi,%edi
call   1040 <XOpenDisplay@plt>
test   %rax,%rax
je     11a5 <getRootWindowSize+0x55>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <DefaultRootWindow@plt>
test   %rax,%rax
js     11c1 <getRootWindowSize+0x71>
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1060 <XGetWindowAttributes@plt>
mov    0x8(%rsp),%eax
mov    %eax,(%r15)
mov    0xc(%rsp),%eax
mov    %eax,(%r14)
mov    %rbx,%rdi
call   1070 <XCloseDisplay@plt>
xor    %eax,%eax
jmp    11db <getRootWindowSize+0x8b>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    11db <getRootWindowSize+0x8b>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xfffffffe,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
@stderr = global i32 0
@.str = [33 x i8] c"Failed to open default display.\0A\00"
@.str.1 = [78 x i8] c"Failed to obtain the root windows Id of the default screen of given display.\0A\00"
define i32 @getRootWindowSize(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca %struct.TYPE_3__
%9 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32* null, i32** %6
store i64 0, i64* %7
%10 = call i32* @XOpenDisplay(i32* null)
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp ne i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %36
16: ; preds = %2
%17 = load i32*, i32** %6
%18 = call i64 @DefaultRootWindow(i32* %17)
store i64 %18, i64* %7
%19 = load i64, i64* %7
%20 = icmp sgt i64 0, %19
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.1, i64 0, i64 0))
store i32 -2, i32* %3
br label %36
24: ; preds = %16
%25 = load i32*, i32** %6
%26 = load i64, i64* %7
%27 = call i32 @XGetWindowAttributes(i32* %25, i64 %26, %struct.TYPE_3__* %8)
store i32 %27, i32* %9
%28 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i32 0, i32 0
%29 = load i32, i32* %28
%30 = load i32*, i32** %4
store i32 %29, i32* %30
%31 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i32 0, i32 1
%32 = load i32, i32* %31
%33 = load i32*, i32** %5
store i32 %32, i32* %33
%34 = load i32*, i32** %6
%35 = call i32 @XCloseDisplay(i32* %34)
store i32 0, i32* %3
br label %36
36: ; preds = %24, %21, %13
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
@stderr = global i32 0
@.str = [33 x i8] c"Failed to open default display.\0A\00"
@.str.1 = [78 x i8] c"Failed to obtain the root windows Id of the default screen of given display.\0A\00"
define i32 @getRootWindowSize(i32* nocapture writeonly %0, i32* nocapture writeonly %1) {
%3 = alloca %struct.TYPE_3__
%4 = bitcast %struct.TYPE_3__* %3 to i8*
%5 = tail call i32* @XOpenDisplay(i32* null)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %23
10: ; preds = %2
%11 = tail call i64 @DefaultRootWindow(i32* %5)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.1, i64 0, i64 0))
br label %23
16: ; preds = %10
%17 = call i32 @XGetWindowAttributes(i32* %5, i64 %11, %struct.TYPE_3__* %3)
%18 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 0
%19 = load i32, i32* %18
store i32 %19, i32* %0
%20 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 1
%21 = load i32, i32* %20
store i32 %21, i32* %1
%22 = call i32 @XCloseDisplay(i32* %5)
br label %23
23: ; preds = %16, %13, %7
%24 = phi i32 [ -2, %13 ], [ 0, %16 ], [ -1, %7 ]
ret i32 %24
}