#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*/ *visual;
  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 VisualDepthMask;
int VisualScreenMask;
int /*<<< orphan*/ XFree(char *);
TYPE_1__ *XGetVisualInfo(int /*<<< orphan*/ *, int, TYPE_1__ *, int *);
int /*<<< orphan*/ screen_number(int /*<<< orphan*/ *);
Visual *pick_mono_visual(Screen *screen) {
  Display *dpy = DisplayOfScreen(screen);
  XVisualInfo vi_in, *vi_out;
  int out_count;
  vi_in.depth = 1;
  vi_in.screen = screen_number(screen);
  vi_out = XGetVisualInfo(dpy, (VisualDepthMask | VisualScreenMask), &vi_in,
                          &out_count);
  if (vi_out) {
    Visual *v = (out_count > 0 ? vi_out[0].visual : 0);
    if (v && vi_out[0].depth != 1)
      v = 0;
    XFree((char *)vi_out);
    return v;
  } else
    return 0;
}


x86 assembly (clang, -O0):
<pick_mono_visual>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <DisplayOfScreen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <screen_number@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
mov    0x2e70(%rip),%rax
or     (%rax),%esi
lea    -0x30(%rbp),%rdx
lea    -0x3c(%rbp),%rcx
call   1040 <XGetVisualInfo@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1202 <pick_mono_visual+0xc2>
cmpl   $0x0,-0x3c(%rbp)
jle    11b9 <pick_mono_visual+0x79>
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x50(%rbp)
jmp    11c4 <pick_mono_visual+0x84>
xor    %eax,%eax
mov    %rax,-0x50(%rbp)
jmp    11c4 <pick_mono_visual+0x84>
mov    -0x50(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     11ec <pick_mono_visual+0xac>
mov    -0x38(%rbp),%rax
cmpl   $0x1,(%rax)
je     11ec <pick_mono_visual+0xac>
movq   $0x0,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <XFree@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    120a <pick_mono_visual+0xca>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pick_mono_visual>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
call   1050 <DisplayOfScreen@plt>
mov    %rax,%r14
movl   $0x1,0x10(%rsp)
mov    %rbx,%rdi
call   1060 <screen_number@plt>
mov    %eax,0x20(%rsp)
mov    0x2e6b(%rip),%rax
mov    0x2e7c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %r14,%rdi
call   1040 <XGetVisualInfo@plt>
test   %rax,%rax
je     11aa <pick_mono_visual+0x6a>
cmpl   $0x0,0xc(%rsp)
jle    11ae <pick_mono_visual+0x6e>
mov    0x8(%rax),%rcx
xor    %ebx,%ebx
test   %rcx,%rcx
je     11b0 <pick_mono_visual+0x70>
cmpl   $0x1,(%rax)
cmove  %rcx,%rbx
jmp    11b0 <pick_mono_visual+0x70>
xor    %ebx,%ebx
jmp    11b8 <pick_mono_visual+0x78>
xor    %ebx,%ebx
mov    %rax,%rdi
call   1030 <XFree@plt>
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i32*, i32 }
@VisualDepthMask = global i32 0
@VisualScreenMask = global i32 0
define i32* @pick_mono_visual(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca %struct.TYPE_4__
%6 = alloca %struct.TYPE_4__*
%7 = alloca i32
%8 = alloca i32*
store i32* %0, i32** %3
%9 = load i32*, i32** %3
%10 = call i32* @DisplayOfScreen(i32* %9)
store i32* %10, i32** %4
%11 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %5, i32 0, i32 0
store i32 1, i32* %11
%12 = load i32*, i32** %3
%13 = call i32 @screen_number(i32* %12)
%14 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %5, i32 0, i32 2
store i32 %13, i32* %14
%15 = load i32*, i32** %4
%16 = load i32, i32* @VisualDepthMask
%17 = load i32, i32* @VisualScreenMask
%18 = or i32 %16, %17
%19 = call %struct.TYPE_4__* @XGetVisualInfo(i32* %15, i32 %18, %struct.TYPE_4__* %5, i32* %7)
store %struct.TYPE_4__* %19, %struct.TYPE_4__** %6
%20 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%21 = icmp ne %struct.TYPE_4__* %20, null
br i1 %21, label %22, label %47
22: ; preds = %1
%23 = load i32, i32* %7
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%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
br label %31
30: ; preds = %22
br label %31
31: ; preds = %30, %25
%32 = phi i32* [ %29, %25 ], [ null, %30 ]
store i32* %32, i32** %8
%33 = load i32*, i32** %8
%34 = icmp ne i32* %33, null
br i1 %34, label %35, label %42
35: ; preds = %31
%36 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%37 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %36, i64 0
%38 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %37, i32 0, i32 0
%39 = load i32, i32* %38
%40 = icmp ne i32 %39, 1
br i1 %40, label %41, label %42
41: ; preds = %35
store i32* null, i32** %8
br label %42
42: ; preds = %41, %35, %31
%43 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%44 = bitcast %struct.TYPE_4__* %43 to i8*
%45 = call i32 @XFree(i8* %44)
%46 = load i32*, i32** %8
store i32* %46, i32** %2
br label %48
47: ; preds = %1
store i32* null, i32** %2
br label %48
48: ; preds = %47, %42
%49 = load i32*, i32** %2
ret i32* %49
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32*, i32 }
@VisualDepthMask = global i32 0
@VisualScreenMask = global i32 0
define i32* @pick_mono_visual(i32* %0) {
%2 = alloca %struct.TYPE_4__
%3 = alloca i32
%4 = tail call i32* @DisplayOfScreen(i32* %0)
%5 = bitcast %struct.TYPE_4__* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 0
store i32 1, i32* %7
%8 = tail call i32 @screen_number(i32* %0)
%9 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 2
store i32 %8, i32* %9
%10 = load i32, i32* @VisualDepthMask
%11 = load i32, i32* @VisualScreenMask
%12 = or i32 %11, %10
%13 = call %struct.TYPE_4__* @XGetVisualInfo(i32* %4, i32 %12, %struct.TYPE_4__* %2, i32* %3)
%14 = icmp eq %struct.TYPE_4__* %13, null
br i1 %14, label %31, label %15
15: ; preds = %1
%16 = load i32, i32* %3
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %15
%19 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %13, i64 0, i32 1
%20 = load i32*, i32** %19
%21 = icmp eq i32* %20, null
br i1 %21, label %27, label %22
22: ; preds = %18
%23 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %13, i64 0, i32 0
%24 = load i32, i32* %23
%25 = icmp eq i32 %24, 1
%26 = select i1 %25, i32* %20, i32* null
br label %27
27: ; preds = %15, %22, %18
%28 = phi i32* [ null, %18 ], [ %26, %22 ], [ null, %15 ]
%29 = bitcast %struct.TYPE_4__* %13 to i8*
%30 = call i32 @XFree(i8* %29)
br label %31
31: ; preds = %1, %27
%32 = phi i32* [ %28, %27 ], [ null, %1 ]
ret i32* %32
}