#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 colormap_size;
};
typedef TYPE_1__ XVisualInfo;
typedef int Status;
typedef int Atom;

/* Variables and functions */
#define XA_RGB_BEST_MAP 133
#define XA_RGB_BLUE_MAP 132
#define XA_RGB_DEFAULT_MAP 131
#define XA_RGB_GRAY_MAP 130
#define XA_RGB_GREEN_MAP 129
#define XA_RGB_RED_MAP 128
int /*<<< orphan*/ best_allocation(TYPE_1__ *, unsigned long *, unsigned long *,
                                   unsigned long *);
int default_allocation(TYPE_1__ *, unsigned long *, unsigned long *,
                       unsigned long *);
int /*<<< orphan*/ gray_allocation(int, unsigned long *, unsigned long *,
                                   unsigned long *);
Status XmuGetColormapAllocation(XVisualInfo *vinfo, Atom property,
                                unsigned long *red_max,
                                unsigned long *green_max,
                                unsigned long *blue_max) {
  Status status = 1;
  if (vinfo->colormap_size <= 2)
    return 0;
  switch (property) {
  case XA_RGB_DEFAULT_MAP:
    status = default_allocation(vinfo, red_max, green_max, blue_max);
    break;
  case XA_RGB_BEST_MAP:
    best_allocation(vinfo, red_max, green_max, blue_max);
    break;
  case XA_RGB_GRAY_MAP:
    gray_allocation(vinfo->colormap_size, red_max, green_max, blue_max);
    break;
  case XA_RGB_RED_MAP:
    *red_max = vinfo->colormap_size - 1;
    *green_max = *blue_max = 0;
    break;
  case XA_RGB_GREEN_MAP:
    *green_max = vinfo->colormap_size - 1;
    *red_max = *blue_max = 0;
    break;
  case XA_RGB_BLUE_MAP:
    *blue_max = vinfo->colormap_size - 1;
    *red_max = *green_max = 0;
    break;
  default:
    status = 0;
  }
  return status;
}


x86 assembly (clang, -O0):
<XmuGetColormapAllocation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x2,(%rax)
jg     116b <XmuGetColormapAllocation+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    127e <XmuGetColormapAllocation+0x14e>
mov    -0x14(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x5,%eax
ja     1271 <XmuGetColormapAllocation+0x141>
mov    -0x40(%rbp),%rax
lea    0xe75(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1050 <default_allocation@plt>
mov    %eax,-0x34(%rbp)
jmp    1278 <XmuGetColormapAllocation+0x148>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1040 <best_allocation@plt>
jmp    1278 <XmuGetColormapAllocation+0x148>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1030 <gray_allocation@plt>
jmp    1278 <XmuGetColormapAllocation+0x148>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sub    $0x1,%eax
movslq %eax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
jmp    1278 <XmuGetColormapAllocation+0x148>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sub    $0x1,%eax
movslq %eax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
jmp    1278 <XmuGetColormapAllocation+0x148>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sub    $0x1,%eax
movslq %eax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
jmp    1278 <XmuGetColormapAllocation+0x148>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<XmuGetColormapAllocation>:
push   %rax
mov    %rdi,%r9
mov    (%rdi),%edi
xor    %eax,%eax
cmp    $0x3,%edi
jl     11d0 <XmuGetColormapAllocation+0xa0>
add    $0xffffff80,%esi
cmp    $0x5,%esi
ja     11d0 <XmuGetColormapAllocation+0xa0>
lea    0xeac(%rip),%rax
movslq (%rax,%rsi,4),%rsi
add    %rax,%rsi
jmp    *%rsi
add    $0xffffffff,%edi
mov    %rdi,(%rdx)
movq   $0x0,(%r8)
movq   $0x0,(%rcx)
jmp    11cb <XmuGetColormapAllocation+0x9b>
add    $0xffffffff,%edi
mov    %rdi,(%rcx)
movq   $0x0,(%r8)
jmp    11b1 <XmuGetColormapAllocation+0x81>
mov    %rdx,%rsi
mov    %rcx,%rdx
mov    %r8,%rcx
call   1030 <gray_allocation@plt>
jmp    11cb <XmuGetColormapAllocation+0x9b>
mov    %r9,%rdi
mov    %rdx,%rsi
mov    %rcx,%rdx
mov    %r8,%rcx
pop    %rax
jmp    1050 <default_allocation@plt>
add    $0xffffffff,%edi
mov    %rdi,(%r8)
movq   $0x0,(%rcx)
movq   $0x0,(%rdx)
jmp    11cb <XmuGetColormapAllocation+0x9b>
mov    %r9,%rdi
mov    %rdx,%rsi
mov    %rcx,%rdx
mov    %r8,%rcx
call   1040 <best_allocation@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32 }
define i32 @XmuGetColormapAllocation(%struct.TYPE_5__* %0, i32 %1, i64* %2, i64* %3, i64* %4) {
%6 = alloca i32
%7 = alloca %struct.TYPE_5__*
%8 = alloca i32
%9 = alloca i64*
%10 = alloca i64*
%11 = alloca i64*
%12 = alloca i32
store %struct.TYPE_5__* %0, %struct.TYPE_5__** %7
store i32 %1, i32* %8
store i64* %2, i64** %9
store i64* %3, i64** %10
store i64* %4, i64** %11
store i32 1, i32* %12
%13 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%14 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = icmp sle i32 %15, 2
br i1 %16, label %17, label %18
17: ; preds = %5
store i32 0, i32* %6
br label %70
18: ; preds = %5
%19 = load i32, i32* %8
switch i32 %19, label %67 [
i32 131, label %20
i32 133, label %26
i32 130, label %32
i32 128, label %40
i32 129, label %49
i32 132, label %58
]
20: ; preds = %18
%21 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%22 = load i64*, i64** %9
%23 = load i64*, i64** %10
%24 = load i64*, i64** %11
%25 = call i32 @default_allocation(%struct.TYPE_5__* %21, i64* %22, i64* %23, i64* %24)
store i32 %25, i32* %12
br label %68
26: ; preds = %18
%27 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%28 = load i64*, i64** %9
%29 = load i64*, i64** %10
%30 = load i64*, i64** %11
%31 = call i32 @best_allocation(%struct.TYPE_5__* %27, i64* %28, i64* %29, i64* %30)
br label %68
32: ; preds = %18
%33 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%34 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %33, i32 0, i32 0
%35 = load i32, i32* %34
%36 = load i64*, i64** %9
%37 = load i64*, i64** %10
%38 = load i64*, i64** %11
%39 = call i32 @gray_allocation(i32 %35, i64* %36, i64* %37, i64* %38)
br label %68
40: ; preds = %18
%41 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%42 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %41, i32 0, i32 0
%43 = load i32, i32* %42
%44 = sub nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = load i64*, i64** %9
store i64 %45, i64* %46
%47 = load i64*, i64** %11
store i64 0, i64* %47
%48 = load i64*, i64** %10
store i64 0, i64* %48
br label %68
49: ; preds = %18
%50 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%51 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %50, i32 0, i32 0
%52 = load i32, i32* %51
%53 = sub nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = load i64*, i64** %10
store i64 %54, i64* %55
%56 = load i64*, i64** %11
store i64 0, i64* %56
%57 = load i64*, i64** %9
store i64 0, i64* %57
br label %68
58: ; preds = %18
%59 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%60 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %59, i32 0, i32 0
%61 = load i32, i32* %60
%62 = sub nsw i32 %61, 1
%63 = sext i32 %62 to i64
%64 = load i64*, i64** %11
store i64 %63, i64* %64
%65 = load i64*, i64** %10
store i64 0, i64* %65
%66 = load i64*, i64** %9
store i64 0, i64* %66
br label %68
67: ; preds = %18
store i32 0, i32* %12
br label %68
68: ; preds = %67, %58, %49, %40, %32, %26, %20
%69 = load i32, i32* %12
store i32 %69, i32* %6
br label %70
70: ; preds = %68, %17
%71 = load i32, i32* %6
ret i32 %71
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32 }
define i32 @XmuGetColormapAllocation(%struct.TYPE_5__* %0, i32 %1, i64* %2, i64* %3, i64* %4) {
%6 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %0, i64 0, i32 0
%7 = load i32, i32* %6
%8 = icmp slt i32 %7, 3
br i1 %8, label %25, label %9
9: ; preds = %5
switch i32 %1, label %25 [
i32 131, label %10
i32 133, label %12
i32 130, label %14
i32 128, label %16
i32 129, label %19
i32 132, label %22
]
10: ; preds = %9
%11 = tail call i32 @default_allocation(%struct.TYPE_5__* %0, i64* %2, i64* %3, i64* %4)
br label %25
12: ; preds = %9
%13 = tail call i32 @best_allocation(%struct.TYPE_5__* %0, i64* %2, i64* %3, i64* %4)
br label %25
14: ; preds = %9
%15 = tail call i32 @gray_allocation(i32 %7, i64* %2, i64* %3, i64* %4)
br label %25
16: ; preds = %9
%17 = add nsw i32 %7, -1
%18 = zext i32 %17 to i64
store i64 %18, i64* %2
store i64 0, i64* %4
store i64 0, i64* %3
br label %25
19: ; preds = %9
%20 = add nsw i32 %7, -1
%21 = zext i32 %20 to i64
store i64 %21, i64* %3
store i64 0, i64* %4
store i64 0, i64* %2
br label %25
22: ; preds = %9
%23 = add nsw i32 %7, -1
%24 = zext i32 %23 to i64
store i64 %24, i64* %4
store i64 0, i64* %3
store i64 0, i64* %2
br label %25
25: ; preds = %10, %12, %14, %16, %19, %22, %9, %5
%26 = phi i32 [ 0, %5 ], [ 1, %22 ], [ 1, %19 ], [ 1, %16 ], [ 1, %14 ], [ 1, %12 ], [ %11, %10 ], [ 0, %9 ]
ret i32 %26
}