#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_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int depth;
  int /*<<< orphan*/ visualid;
  int /*<<< orphan*/ screen;
};
typedef TYPE_1__ XVisualInfo;
typedef int /*<<< orphan*/ Visual;
typedef int /*<<< orphan*/ Screen;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ *DisplayOfScreen(int /*<<< orphan*/ *);
int VisualIDMask;
int VisualScreenMask;
int /*<<< orphan*/ XFree(char *);
TYPE_1__ *XGetVisualInfo(int /*<<< orphan*/ *, int, TYPE_1__ *, int *);
int /*<<< orphan*/ XVisualIDFromVisual(int /*<<< orphan*/ *);
int /*<<< orphan*/ abort();
int /*<<< orphan*/ screen_number(int /*<<< orphan*/ *);
int visual_depth(Screen *screen, Visual *visual) {
  Display *dpy = DisplayOfScreen(screen);
  XVisualInfo vi_in, *vi_out;
  int out_count, d;
  vi_in.screen = screen_number(screen);
  vi_in.visualid = XVisualIDFromVisual(visual);
  vi_out =
      XGetVisualInfo(dpy, VisualScreenMask | VisualIDMask, &vi_in, &out_count);
  if (!vi_out)
    abort();
  d = vi_out[0].depth;
  XFree((char *)vi_out);
  return d;
}


x86 assembly (clang, -O0):
<visual_depth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <DisplayOfScreen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <screen_number@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <XVisualIDFromVisual@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
mov    0x2e37(%rip),%rax
or     (%rax),%esi
lea    -0x28(%rbp),%rdx
lea    -0x34(%rbp),%rcx
call   1050 <XGetVisualInfo@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11ce <visual_depth+0x6e>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <XFree@plt>
mov    -0x38(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<visual_depth>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1060 <DisplayOfScreen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1080 <screen_number@plt>
mov    %eax,0x8(%rsp)
mov    %r14,%rdi
call   1070 <XVisualIDFromVisual@plt>
mov    %eax,0x4(%rsp)
mov    0x2e5a(%rip),%rax
mov    0x2e43(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rsp,%rdx
lea    0xc(%rsp),%rcx
mov    %r15,%rdi
call   1050 <XGetVisualInfo@plt>
test   %rax,%rax
je     11cc <visual_depth+0x6c>
mov    (%rax),%ebx
mov    %rax,%rdi
call   1040 <XFree@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i32, i32 }
@VisualScreenMask = global i32 0
@VisualIDMask = global i32 0
define i32 @visual_depth(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca %struct.TYPE_4__
%7 = alloca %struct.TYPE_4__*
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
%10 = load i32*, i32** %3
%11 = call i32* @DisplayOfScreen(i32* %10)
store i32* %11, i32** %5
%12 = load i32*, i32** %3
%13 = call i32 @screen_number(i32* %12)
%14 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 2
store i32 %13, i32* %14
%15 = load i32*, i32** %4
%16 = call i32 @XVisualIDFromVisual(i32* %15)
%17 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 1
store i32 %16, i32* %17
%18 = load i32*, i32** %5
%19 = load i32, i32* @VisualScreenMask
%20 = load i32, i32* @VisualIDMask
%21 = or i32 %19, %20
%22 = call %struct.TYPE_4__* @XGetVisualInfo(i32* %18, i32 %21, %struct.TYPE_4__* %6, i32* %8)
store %struct.TYPE_4__* %22, %struct.TYPE_4__** %7
%23 = load %struct.TYPE_4__*, %struct.TYPE_4__** %7
%24 = icmp ne %struct.TYPE_4__* %23, null
br i1 %24, label %27, label %25
25: ; preds = %2
%26 = call i32 (...) @abort()
unreachable
27: ; preds = %2
%28 = load %struct.TYPE_4__*, %struct.TYPE_4__** %7
%29 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %28, i64 0
%30 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %29, i32 0, i32 0
%31 = load i32, i32* %30
store i32 %31, i32* %9
%32 = load %struct.TYPE_4__*, %struct.TYPE_4__** %7
%33 = bitcast %struct.TYPE_4__* %32 to i8*
%34 = call i32 @XFree(i8* %33)
%35 = load i32, i32* %9
ret i32 %35
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32, i32 }
@VisualScreenMask = global i32 0
@VisualIDMask = global i32 0
define i32 @visual_depth(i32* %0, i32* %1) {
%3 = alloca %struct.TYPE_4__
%4 = alloca i32
%5 = tail call i32* @DisplayOfScreen(i32* %0)
%6 = bitcast %struct.TYPE_4__* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = tail call i32 @screen_number(i32* %0)
%9 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 2
store i32 %8, i32* %9
%10 = tail call i32 @XVisualIDFromVisual(i32* %1)
%11 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 1
store i32 %10, i32* %11
%12 = load i32, i32* @VisualScreenMask
%13 = load i32, i32* @VisualIDMask
%14 = or i32 %13, %12
%15 = call %struct.TYPE_4__* @XGetVisualInfo(i32* %5, i32 %14, %struct.TYPE_4__* %3, i32* %4)
%16 = icmp eq %struct.TYPE_4__* %15, null
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 (...) @abort()
unreachable
19: ; preds = %2
%20 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %15, i64 0, i32 0
%21 = load i32, i32* %20
%22 = bitcast %struct.TYPE_4__* %15 to i8*
%23 = call i32 @XFree(i8* %22)
ret i32 %21
}