#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*/ Visual;
typedef int /*<<< orphan*/ Screen;
typedef int /*<<< orphan*/ Bool;

/* Variables and functions */
int /*<<< orphan*/ *DefaultVisualOfScreen(int /*<<< orphan*/ *);
int /*<<< orphan*/ DisplayOfScreen(int /*<<< orphan*/ *);
int /*<<< orphan*/ True;
int /*<<< orphan*/ free(char *);
char *get_string_resource(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ *get_visual(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
                               int /*<<< orphan*/);
Visual *get_visual_resource(Screen *screen, char *name, char *class,
                            Bool prefer_writable_cells) {
  char *string = get_string_resource(DisplayOfScreen(screen), name, class);
  Visual *v = get_visual(screen, string, prefer_writable_cells, True);
  if (string)
    free(string);
  if (v)
    return v;
  else
    return DefaultVisualOfScreen(screen);
}


x86 assembly (clang, -O0):
<get_visual_resource>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <DisplayOfScreen@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <get_string_resource@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    0x2e53(%rip),%rax
mov    (%rax),%ecx
call   1030 <get_visual@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11b4 <get_visual_resource+0x64>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
cmpq   $0x0,-0x38(%rbp)
je     11cc <get_visual_resource+0x7c>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d9 <get_visual_resource+0x89>
mov    -0x10(%rbp),%rdi
call   1070 <DefaultVisualOfScreen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_visual_resource>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rdi,%r14
call   1060 <DisplayOfScreen@plt>
mov    %eax,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1050 <get_string_resource@plt>
mov    %rax,%rbx
mov    0x2e69(%rip),%rax
mov    (%rax),%ecx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <get_visual@plt>
mov    %rax,%r15
test   %rbx,%rbx
je     119f <get_visual_resource+0x4f>
mov    %rbx,%rdi
call   1040 <free@plt>
test   %r15,%r15
je     11b2 <get_visual_resource+0x62>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <DefaultVisualOfScreen@plt>

LLVM IR (-O0):
@True = global i32 0
define i32* @get_visual_resource(i32* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
store i32* %0, i32** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%12 = load i32*, i32** %6
%13 = call i32 @DisplayOfScreen(i32* %12)
%14 = load i8*, i8** %7
%15 = load i8*, i8** %8
%16 = call i8* @get_string_resource(i32 %13, i8* %14, i8* %15)
store i8* %16, i8** %10
%17 = load i32*, i32** %6
%18 = load i8*, i8** %10
%19 = load i32, i32* %9
%20 = load i32, i32* @True
%21 = call i32* @get_visual(i32* %17, i8* %18, i32 %19, i32 %20)
store i32* %21, i32** %11
%22 = load i8*, i8** %10
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %4
%25 = load i8*, i8** %10
%26 = call i32 @free(i8* %25)
br label %27
27: ; preds = %24, %4
%28 = load i32*, i32** %11
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = load i32*, i32** %11
store i32* %31, i32** %5
br label %35
32: ; preds = %27
%33 = load i32*, i32** %6
%34 = call i32* @DefaultVisualOfScreen(i32* %33)
store i32* %34, i32** %5
br label %35
35: ; preds = %32, %30
%36 = load i32*, i32** %5
ret i32* %36
}

LLVM IR (-O2):
@True = global i32 0
define i32* @get_visual_resource(i32* %0, i8* %1, i8* %2, i32 %3) {
%5 = tail call i32 @DisplayOfScreen(i32* %0)
%6 = tail call i8* @get_string_resource(i32 %5, i8* %1, i8* %2)
%7 = load i32, i32* @True
%8 = tail call i32* @get_visual(i32* %0, i8* %6, i32 %3, i32 %7)
%9 = icmp eq i8* %6, null
br i1 %9, label %12, label %10
10: ; preds = %4
%11 = tail call i32 @free(i8* %6)
br label %12
12: ; preds = %10, %4
%13 = icmp eq i32* %8, null
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = tail call i32* @DefaultVisualOfScreen(i32* %0)
br label %16
16: ; preds = %12, %14
%17 = phi i32* [ %15, %14 ], [ %8, %12 ]
ret i32* %17
}