#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 */

/* Type definitions */
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int DisplayHeight(int /*<<< orphan*/ *, int /*<<< orphan*/);
int DisplayWidth(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int init(int *width, int *height, int *err) {
  Display *display = NULL;
  display = XOpenDisplay(NULL);
  if (!display) {
    printf("XOpenDisplay failed\n");
    goto fail;
  }
  *width = DisplayWidth(display, 0);
  *height = DisplayHeight(display, 0);
  *err = 0;
  return (int)display;
fail:
  *err = -1;
  return 0;
}


x86 assembly (clang, -O0):
<init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <XOpenDisplay@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1185 <init+0x45>
lea    0xe85(%rip),%rdi
call   1050 <printf@plt>
jmp    11c1 <init+0x81>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1040 <DisplayWidth@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1030 <DisplayHeight@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    11d2 <init+0x92>
mov    -0x20(%rbp),%rax
movl   $0xffffffff,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r13
xor    %r12d,%r12d
xor    %edi,%edi
call   1060 <XOpenDisplay@plt>
test   %rax,%rax
je     118b <init+0x4b>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <DisplayWidth@plt>
mov    %eax,0x0(%r13)
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <DisplayHeight@plt>
mov    %eax,(%r14)
movl   $0x0,(%r15)
mov    %ebx,%r12d
jmp    119e <init+0x5e>
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
movl   $0xffffffff,(%r15)
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [21 x i8] c"XOpenDisplay failed\0A\00"
define i32 @init(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* null, i32** %8
%9 = call i32* @XOpenDisplay(i32* null)
store i32* %9, i32** %8
%10 = load i32*, i32** %8
%11 = icmp ne i32* %10, null
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %24
14: ; preds = %3
%15 = load i32*, i32** %8
%16 = call i32 @DisplayWidth(i32* %15, i32 0)
%17 = load i32*, i32** %5
store i32 %16, i32* %17
%18 = load i32*, i32** %8
%19 = call i32 @DisplayHeight(i32* %18, i32 0)
%20 = load i32*, i32** %6
store i32 %19, i32* %20
%21 = load i32*, i32** %7
store i32 0, i32* %21
%22 = load i32*, i32** %8
%23 = ptrtoint i32* %22 to i32
store i32 %23, i32* %4
br label %26
24: ; preds = %12
%25 = load i32*, i32** %7
store i32 -1, i32* %25
store i32 0, i32* %4
br label %26
26: ; preds = %24, %14
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
@str = [20 x i8] c"XOpenDisplay failed\00"
define i32 @init(i32* nocapture writeonly %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = tail call i32* @XOpenDisplay(i32* null)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
store i32 -1, i32* %2
br label %13
8: ; preds = %3
%9 = tail call i32 @DisplayWidth(i32* %4, i32 0)
store i32 %9, i32* %0
%10 = tail call i32 @DisplayHeight(i32* %4, i32 0)
store i32 %10, i32* %1
store i32 0, i32* %2
%11 = ptrtoint i32* %4 to i64
%12 = trunc i64 %11 to i32
br label %13
13: ; preds = %6, %8
%14 = phi i32 [ %12, %8 ], [ 0, %6 ]
ret i32 %14
}