#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_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_5__ {
  TYPE_1__ *screen;
};
typedef TYPE_2__ XWindowAttributes;
typedef int /*<<< orphan*/ Window;
struct TYPE_4__ {
  int width;
  int height;
};
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XGetInputFocus(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                  int *);
int /*<<< orphan*/ XGetWindowAttributes(int /*<<< orphan*/ *,
                                        int /*<<< orphan*/, TYPE_2__ *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/);
void xserver_resolution(int *const width, int *const height) {
  Display *display = XOpenDisplay(0);
  if (display != 0) {
    Window window;
    int revert_to_return;
    XWindowAttributes window_attributes;
    XGetInputFocus(display, &window, &revert_to_return);
    XGetWindowAttributes(display, window, &window_attributes);
    width[0] = window_attributes.screen[0].width;
    height[0] = window_attributes.screen[0].height;
    XCloseDisplay(display);
  } else {
    width[0] = -1;
    height[0] = -1;
  }
}


x86 assembly (clang, -O0):
<xserver_resolution>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %edi,%edi
call   1030 <XOpenDisplay@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ae <xserver_resolution+0x6e>
mov    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <XGetInputFocus@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x28(%rbp),%rdx
call   1040 <XGetWindowAttributes@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rdi
call   1050 <XCloseDisplay@plt>
jmp    11c2 <xserver_resolution+0x82>
mov    -0x8(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xserver_resolution>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edi,%edi
call   1030 <XOpenDisplay@plt>
test   %rax,%rax
je     119b <xserver_resolution+0x5b>
mov    %rax,%rbx
lea    0xc(%rsp),%rsi
lea    0x1c(%rsp),%rdx
mov    %rax,%rdi
call   1060 <XGetInputFocus@plt>
mov    0xc(%rsp),%esi
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <XGetWindowAttributes@plt>
mov    0x10(%rsp),%rax
mov    (%rax),%ecx
mov    %ecx,(%r15)
mov    0x4(%rax),%eax
mov    %eax,(%r14)
mov    %rbx,%rdi
call   1050 <XCloseDisplay@plt>
jmp    11a9 <xserver_resolution+0x69>
movl   $0xffffffff,(%r15)
movl   $0xffffffff,(%r14)
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { %struct.TYPE_4__* }
%struct.TYPE_4__ = type { i32, i32 }
define void @xserver_resolution(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.TYPE_5__
store i32* %0, i32** %3
store i32* %1, i32** %4
%9 = call i32* @XOpenDisplay(i32 0)
store i32* %9, i32** %5
%10 = load i32*, i32** %5
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %34
12: ; preds = %2
%13 = load i32*, i32** %5
%14 = call i32 @XGetInputFocus(i32* %13, i32* %6, i32* %7)
%15 = load i32*, i32** %5
%16 = load i32, i32* %6
%17 = call i32 @XGetWindowAttributes(i32* %15, i32 %16, %struct.TYPE_5__* %8)
%18 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 0
%19 = load %struct.TYPE_4__*, %struct.TYPE_4__** %18
%20 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %19, i64 0
%21 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = load i32*, i32** %3
%24 = getelementptr inbounds i32, i32* %23, i64 0
store i32 %22, i32* %24
%25 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 0
%26 = load %struct.TYPE_4__*, %struct.TYPE_4__** %25
%27 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %26, i64 0
%28 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %27, i32 0, i32 1
%29 = load i32, i32* %28
%30 = load i32*, i32** %4
%31 = getelementptr inbounds i32, i32* %30, i64 0
store i32 %29, i32* %31
%32 = load i32*, i32** %5
%33 = call i32 @XCloseDisplay(i32* %32)
br label %39
34: ; preds = %2
%35 = load i32*, i32** %3
%36 = getelementptr inbounds i32, i32* %35, i64 0
store i32 -1, i32* %36
%37 = load i32*, i32** %4
%38 = getelementptr inbounds i32, i32* %37, i64 0
store i32 -1, i32* %38
br label %39
39: ; preds = %34, %12
ret void
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { %struct.TYPE_4__* }
%struct.TYPE_4__ = type { i32, i32 }
define void @xserver_resolution(i32* nocapture writeonly %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.TYPE_5__
%6 = tail call i32* @XOpenDisplay(i32 0)
%7 = icmp eq i32* %6, null
br i1 %7, label %22, label %8
8: ; preds = %2
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = bitcast %struct.TYPE_5__* %5 to i8*
%12 = call i32 @XGetInputFocus(i32* %6, i32* %3, i32* %4)
%13 = load i32, i32* %3
%14 = call i32 @XGetWindowAttributes(i32* %6, i32 %13, %struct.TYPE_5__* %5)
%15 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 0
%16 = load %struct.TYPE_4__*, %struct.TYPE_4__** %15
%17 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %16, i64 0, i32 0
%18 = load i32, i32* %17
store i32 %18, i32* %0
%19 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %16, i64 0, i32 1
%20 = load i32, i32* %19
store i32 %20, i32* %1
%21 = call i32 @XCloseDisplay(i32* %6)
br label %23
22: ; preds = %2
store i32 -1, i32* %0
store i32 -1, i32* %1
br label %23
23: ; preds = %22, %8
ret void
}