#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_1__;

/* Type definitions */
struct TYPE_5__ {
  int screen;
  scalar_t__ visualid;
};
typedef TYPE_1__ XVisualInfo;
typedef int /*<<< orphan*/ Visual;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int VisualIDMask;
int VisualScreenMask;
TYPE_1__ *XGetVisualInfo(int /*<<< orphan*/ *, long, TYPE_1__ *, int *);
scalar_t__ XVisualIDFromVisual(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, unsigned long,
                           int);
int /*<<< orphan*/ stderr;
XVisualInfo *xw_visual_info(Display *display, int screen, Visual *visual) {
  XVisualInfo *vi = NULL;
  XVisualInfo template;
  int nret = 0;
  template.visualid = XVisualIDFromVisual(visual);
  template.screen = screen;
  vi = XGetVisualInfo(display, (long)(VisualIDMask | VisualScreenMask),
                      &template, &nret);
  if (vi == NULL || nret < 1) {
    fprintf(stderr,
            "%s: Error getting visual information for visual ID 0x%lx, screen "
            "%d.\n",
            "pgxwin_server", (unsigned long)template.visualid, screen);
    vi = NULL;
  };
  return vi;
}


x86 assembly (clang, -O0):
<xw_visual_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <XVisualIDFromVisual@plt>
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e70(%rip),%rax
mov    (%rax),%eax
mov    0x2e77(%rip),%rcx
or     (%rcx),%eax
movslq %eax,%rsi
lea    -0x30(%rbp),%rdx
lea    -0x34(%rbp),%rcx
call   1030 <XGetVisualInfo@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a4 <xw_visual_info+0x74>
cmpl   $0x1,-0x34(%rbp)
jge    11d0 <xw_visual_info+0xa0>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rcx
mov    -0xc(%rbp),%r8d
lea    0xe44(%rip),%rsi
lea    0xe83(%rip),%rdx
call   1050 <fprintf@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xw_visual_info>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
movl   $0x0,0x4(%rsp)
mov    %rdx,%rdi
call   1040 <XVisualIDFromVisual@plt>
mov    %rax,0x10(%rsp)
mov    %ebp,0x8(%rsp)
mov    0x2e85(%rip),%rax
mov    0x2e8e(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
movslq %ecx,%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rbx,%rdi
call   1030 <XGetVisualInfo@plt>
test   %rax,%rax
je     1187 <xw_visual_info+0x57>
cmpl   $0x0,0x4(%rsp)
jg     11ad <xw_visual_info+0x7d>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rsp),%rcx
lea    0xe64(%rip),%rsi
lea    0xea3(%rip),%rdx
mov    %ebp,%r8d
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32, i64 }
@VisualIDMask = global i32 0
@VisualScreenMask = global i32 0
@stderr = global i32 0
@.str = [70 x i8] c"%s: Error getting visual information for visual ID 0x%lx, screen %d.\0A\00"
@.str.1 = [14 x i8] c"pgxwin_server\00"
define %struct.TYPE_5__* @xw_visual_info(i32* %0, i32 %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca %struct.TYPE_5__*
%8 = alloca %struct.TYPE_5__
%9 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store %struct.TYPE_5__* null, %struct.TYPE_5__** %7
store i32 0, i32* %9
%10 = load i32*, i32** %6
%11 = call i64 @XVisualIDFromVisual(i32* %10)
%12 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 1
store i64 %11, i64* %12
%13 = load i32, i32* %5
%14 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 0
store i32 %13, i32* %14
%15 = load i32*, i32** %4
%16 = load i32, i32* @VisualIDMask
%17 = load i32, i32* @VisualScreenMask
%18 = or i32 %16, %17
%19 = sext i32 %18 to i64
%20 = call %struct.TYPE_5__* @XGetVisualInfo(i32* %15, i64 %19, %struct.TYPE_5__* %8, i32* %9)
store %struct.TYPE_5__* %20, %struct.TYPE_5__** %7
%21 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%22 = icmp eq %struct.TYPE_5__* %21, null
br i1 %22, label %26, label %23
23: ; preds = %3
%24 = load i32, i32* %9
%25 = icmp slt i32 %24, 1
br i1 %25, label %26, label %32
26: ; preds = %23, %3
%27 = load i32, i32* @stderr
%28 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 1
%29 = load i64, i64* %28
%30 = load i32, i32* %5
%31 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %29, i32 %30)
store %struct.TYPE_5__* null, %struct.TYPE_5__** %7
br label %32
32: ; preds = %26, %23
%33 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
ret %struct.TYPE_5__* %33
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, i64 }
@VisualIDMask = global i32 0
@VisualScreenMask = global i32 0
@stderr = global i32 0
@.str = [70 x i8] c"%s: Error getting visual information for visual ID 0x%lx, screen %d.\0A\00"
@.str.1 = [14 x i8] c"pgxwin_server\00"
define %struct.TYPE_5__* @xw_visual_info(i32* %0, i32 %1, i32* %2) {
%4 = alloca %struct.TYPE_5__
%5 = alloca i32
%6 = bitcast %struct.TYPE_5__* %4 to i8*
%7 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%8 = tail call i64 @XVisualIDFromVisual(i32* %2)
%9 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 1
store i64 %8, i64* %9
%10 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 0
store i32 %1, i32* %10
%11 = load i32, i32* @VisualIDMask
%12 = load i32, i32* @VisualScreenMask
%13 = or i32 %12, %11
%14 = sext i32 %13 to i64
%15 = call %struct.TYPE_5__* @XGetVisualInfo(i32* %0, i64 %14, %struct.TYPE_5__* %4, i32* %5)
%16 = icmp eq %struct.TYPE_5__* %15, null
%17 = load i32, i32* %5
%18 = icmp slt i32 %17, 1
%19 = select i1 %16, i1 true, i1 %18
br i1 %19, label %20, label %24
20: ; preds = %3
%21 = load i32, i32* @stderr
%22 = load i64, i64* %9
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %22, i32 %1)
br label %24
24: ; preds = %3, %20
%25 = phi %struct.TYPE_5__* [ null, %20 ], [ %15, %3 ]
ret %struct.TYPE_5__* %25
}