#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 scalar_t__ VisualID;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int VisualIDMask;
int VisualScreenMask;
TYPE_1__ *XGetVisualInfo(int /*<<< orphan*/ *, long, TYPE_1__ *, int *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, unsigned long,
                           int);
int /*<<< orphan*/ stderr;
XVisualInfo *pgx_visual_info(Display *display, int screen, VisualID vid) {
  XVisualInfo *vi = NULL;
  XVisualInfo template;
  int nret = 0;
  template.visualid = vid;
  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", (unsigned long)template.visualid, screen);
    vi = NULL;
  };
  return vi;
}


x86 assembly (clang, -O0):
<pgx_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),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e85(%rip),%rax
mov    (%rax),%eax
mov    0x2e8c(%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     118f <pgx_visual_info+0x6f>
cmpl   $0x1,-0x34(%rbp)
jge    11bb <pgx_visual_info+0x9b>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rcx
mov    -0xc(%rbp),%r8d
lea    0xe59(%rip),%rsi
lea    0xe98(%rip),%rdx
call   1040 <fprintf@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pgx_visual_info>:
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebx
movl   $0x0,0xc(%rsp)
mov    %rdx,0x18(%rsp)
mov    %esi,0x10(%rsp)
mov    0x2ea1(%rip),%rax
mov    0x2eaa(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
movslq %ecx,%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
call   1030 <XGetVisualInfo@plt>
test   %rax,%rax
je     1168 <pgx_visual_info+0x48>
cmpl   $0x0,0xc(%rsp)
jg     118e <pgx_visual_info+0x6e>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    0x18(%rsp),%rcx
lea    0xe83(%rip),%rsi
lea    0xec2(%rip),%rdx
mov    %ebx,%r8d
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
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 = [7 x i8] c"pgxwin\00"
define %struct.TYPE_5__* @pgx_visual_info(i32* %0, i32 %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i64
%7 = alloca %struct.TYPE_5__*
%8 = alloca %struct.TYPE_5__
%9 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i64 %2, i64* %6
store %struct.TYPE_5__* null, %struct.TYPE_5__** %7
store i32 0, i32* %9
%10 = load i64, i64* %6
%11 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 1
store i64 %10, i64* %11
%12 = load i32, i32* %5
%13 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 0
store i32 %12, i32* %13
%14 = load i32*, i32** %4
%15 = load i32, i32* @VisualIDMask
%16 = load i32, i32* @VisualScreenMask
%17 = or i32 %15, %16
%18 = sext i32 %17 to i64
%19 = call %struct.TYPE_5__* @XGetVisualInfo(i32* %14, i64 %18, %struct.TYPE_5__* %8, i32* %9)
store %struct.TYPE_5__* %19, %struct.TYPE_5__** %7
%20 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%21 = icmp eq %struct.TYPE_5__* %20, null
br i1 %21, label %25, label %22
22: ; preds = %3
%23 = load i32, i32* %9
%24 = icmp slt i32 %23, 1
br i1 %24, label %25, label %31
25: ; preds = %22, %3
%26 = load i32, i32* @stderr
%27 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 1
%28 = load i64, i64* %27
%29 = load i32, i32* %5
%30 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %28, i32 %29)
store %struct.TYPE_5__* null, %struct.TYPE_5__** %7
br label %31
31: ; preds = %25, %22
%32 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
ret %struct.TYPE_5__* %32
}

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 = [7 x i8] c"pgxwin\00"
define %struct.TYPE_5__* @pgx_visual_info(i32* %0, i32 %1, i64 %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 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 1
store i64 %2, i64* %8
%9 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 0
store i32 %1, i32* %9
%10 = load i32, i32* @VisualIDMask
%11 = load i32, i32* @VisualScreenMask
%12 = or i32 %11, %10
%13 = sext i32 %12 to i64
%14 = call %struct.TYPE_5__* @XGetVisualInfo(i32* %0, i64 %13, %struct.TYPE_5__* %4, i32* %5)
%15 = icmp eq %struct.TYPE_5__* %14, null
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 1
%18 = select i1 %15, i1 true, i1 %17
br i1 %18, label %19, label %23
19: ; preds = %3
%20 = load i32, i32* @stderr
%21 = load i64, i64* %8
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %21, i32 %1)
br label %23
23: ; preds = %3, %19
%24 = phi %struct.TYPE_5__* [ null, %19 ], [ %14, %3 ]
ret %struct.TYPE_5__* %24
}