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

/* Variables and functions */
int /*<<< orphan*/ False;
int /*<<< orphan*/ XAllocColorCells(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                    int /*<<< orphan*/, unsigned long *, int,
                                    unsigned long *, int);
int allocate_color_planes(Display *dpy, Colormap cmap, int nplanes,
                          unsigned long *plane_masks,
                          unsigned long *base_pixel_ret) {
  while (nplanes > 1 && !XAllocColorCells(dpy, cmap, False, plane_masks,
                                          nplanes, base_pixel_ret, 1))
    nplanes--;
  return nplanes;
}


x86 assembly (clang, -O0):
<allocate_color_planes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0x1,-0x10(%rbp)
mov    %al,-0x21(%rbp)
jle    116c <allocate_color_planes+0x5c>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2ea1(%rip),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8d
mov    -0x20(%rbp),%r9
movl   $0x1,(%rsp)
call   1030 <XAllocColorCells@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    117c <allocate_color_planes+0x6c>
jmp    118a <allocate_color_planes+0x7a>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    112a <allocate_color_planes+0x1a>
mov    -0x10(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate_color_planes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
cmp    $0x2,%edx
jl     1172 <allocate_color_planes+0x62>
mov    %r8,%r14
mov    %rcx,%r15
mov    %esi,%r12d
mov    %rdi,%rbp
mov    0x2eb3(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13),%edx
movl   $0x1,(%rsp)
mov    %rbp,%rdi
mov    %r12d,%esi
mov    %r15,%rcx
mov    %ebx,%r8d
mov    %r14,%r9
call   1030 <XAllocColorCells@plt>
test   %eax,%eax
jne    1172 <allocate_color_planes+0x62>
lea    -0x1(%rbx),%eax
cmp    $0x2,%ebx
mov    %eax,%ebx
jg     1140 <allocate_color_planes+0x30>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@False = global i32 0
define i32 @allocate_color_planes(i32* %0, i32 %1, i32 %2, i64* %3, i64* %4) {
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64*
%10 = alloca i64*
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i64* %3, i64** %9
store i64* %4, i64** %10
br label %11
11: ; preds = %26, %5
%12 = load i32, i32* %8
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = load i32*, i32** %6
%16 = load i32, i32* %7
%17 = load i32, i32* @False
%18 = load i64*, i64** %9
%19 = load i32, i32* %8
%20 = load i64*, i64** %10
%21 = call i32 @XAllocColorCells(i32* %15, i32 %16, i32 %17, i64* %18, i32 %19, i64* %20, i32 1)
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br label %24
24: ; preds = %14, %11
%25 = phi i1 [ false, %11 ], [ %23, %14 ]
br i1 %25, label %26, label %29
26: ; preds = %24
%27 = load i32, i32* %8
%28 = add nsw i32 %27, -1
store i32 %28, i32* %8
br label %11
29: ; preds = %24
%30 = load i32, i32* %8
ret i32 %30
}

LLVM IR (-O2):
@False = global i32 0
define i32 @allocate_color_planes(i32* %0, i32 %1, i32 %2, i64* %3, i64* %4) {
%6 = icmp sgt i32 %2, 1
br i1 %6, label %7, label %15
7: ; preds = %5, %12
%8 = phi i32 [ %13, %12 ], [ %2, %5 ]
%9 = load i32, i32* @False
%10 = tail call i32 @XAllocColorCells(i32* %0, i32 %1, i32 %9, i64* %3, i32 %8, i64* %4, i32 1)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = add nsw i32 %8, -1
%14 = icmp sgt i32 %8, 2
br i1 %14, label %7, label %15
15: ; preds = %7, %12, %5
%16 = phi i32 [ %2, %5 ], [ 1, %12 ], [ %8, %7 ]
ret i32 %16
}