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

/* Variables and functions */
int /*<<< orphan*/ AllocNone;
int /*<<< orphan*/ DefaultColormap(int /*<<< orphan*/ *, int);
int DefaultScreen(int /*<<< orphan*/ *);
int /*<<< orphan*/ *DefaultScreenOfDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ *DefaultVisual(int /*<<< orphan*/ *, int);
int MaxCmapsOfScreen(int /*<<< orphan*/ *);
int /*<<< orphan*/ XCreateColormap(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                   int /*<<< orphan*/ *, int /*<<< orphan*/);
Colormap alloc_colormap(Display *dpy, Window parent, Visual *vis) {
  Screen *scr = DefaultScreenOfDisplay(dpy);
  int scrnum = DefaultScreen(dpy);
  if (MaxCmapsOfScreen(scr) == 1 && vis == DefaultVisual(dpy, scrnum)) {
    return DefaultColormap(dpy, scrnum);
  } else {
    return XCreateColormap(dpy, parent, vis, AllocNone);
  }
}


x86 assembly (clang, -O0):
<alloc_colormap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <DefaultScreenOfDisplay@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <DefaultScreen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <MaxCmapsOfScreen@plt>
cmp    $0x1,%eax
jne    11d6 <alloc_colormap+0x76>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1080 <DefaultVisual@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
jne    11d6 <alloc_colormap+0x76>
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1050 <DefaultColormap@plt>
mov    %eax,-0x4(%rbp)
jmp    11f2 <alloc_colormap+0x92>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    0x2e00(%rip),%rax
mov    (%rax),%ecx
call   1060 <XCreateColormap@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_colormap>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %esi,%r14d
mov    %rdi,%rbp
call   1030 <DefaultScreenOfDisplay@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1070 <DefaultScreen@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1040 <MaxCmapsOfScreen@plt>
cmp    $0x1,%eax
jne    11a1 <alloc_colormap+0x41>
mov    %rbp,%rdi
mov    %r15d,%esi
call   1080 <DefaultVisual@plt>
cmp    %r12,%rax
je     11c0 <alloc_colormap+0x60>
mov    0x2e40(%rip),%rax
mov    (%rax),%ecx
mov    %rbp,%rdi
mov    %r14d,%esi
mov    %r12,%rdx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <XCreateColormap@plt>
mov    %rbp,%rdi
mov    %r15d,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <DefaultColormap@plt>

LLVM IR (-O0):
@AllocNone = global i32 0
define i32 @alloc_colormap(i32* %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%10 = load i32*, i32** %5
%11 = call i32* @DefaultScreenOfDisplay(i32* %10)
store i32* %11, i32** %8
%12 = load i32*, i32** %5
%13 = call i32 @DefaultScreen(i32* %12)
store i32 %13, i32* %9
%14 = load i32*, i32** %8
%15 = call i32 @MaxCmapsOfScreen(i32* %14)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %27
17: ; preds = %3
%18 = load i32*, i32** %7
%19 = load i32*, i32** %5
%20 = load i32, i32* %9
%21 = call i32* @DefaultVisual(i32* %19, i32 %20)
%22 = icmp eq i32* %18, %21
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = load i32*, i32** %5
%25 = load i32, i32* %9
%26 = call i32 @DefaultColormap(i32* %24, i32 %25)
store i32 %26, i32* %4
br label %33
27: ; preds = %17, %3
%28 = load i32*, i32** %5
%29 = load i32, i32* %6
%30 = load i32*, i32** %7
%31 = load i32, i32* @AllocNone
%32 = call i32 @XCreateColormap(i32* %28, i32 %29, i32* %30, i32 %31)
store i32 %32, i32* %4
br label %33
33: ; preds = %27, %23
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@AllocNone = global i32 0
define i32 @alloc_colormap(i32* %0, i32 %1, i32* %2) {
%4 = tail call i32* @DefaultScreenOfDisplay(i32* %0)
%5 = tail call i32 @DefaultScreen(i32* %0)
%6 = tail call i32 @MaxCmapsOfScreen(i32* %4)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %13
8: ; preds = %3
%9 = tail call i32* @DefaultVisual(i32* %0, i32 %5)
%10 = icmp eq i32* %9, %2
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @DefaultColormap(i32* %0, i32 %5)
br label %16
13: ; preds = %8, %3
%14 = load i32, i32* @AllocNone
%15 = tail call i32 @XCreateColormap(i32* %0, i32 %1, i32* %2, i32 %14)
br label %16
16: ; preds = %13, %11
%17 = phi i32 [ %12, %11 ], [ %15, %13 ]
ret i32 %17
}