// File: /workspace/github_c_makefile_star2_O2/jrrk[P]cbzone/c_gpr.c
// Function: setcolormap
void setcolormap()
{
  int dallocated, pallocated;
  Bool success = False;
  Visual* visual;

  if (opt->mono || depth == 1) {        /* mono? */
    setmonomap();
    return;
  }

  visual = DefaultVisual(d, screen_num);
  standardizecolors(visual);

  if (opt->max_colors < 2)
    if (depth<8)
      cr = 1<<depth;
    else
      cr = 256;
  else
    cr = opt->max_colors;

  if (opt->fading_colors < 1)
    opt->fading_colors = cr;

  do {
    countcolors();
    reducecolors();

    if (opt->mono) {
      setmonomap();
      return;
    }

    if (opt->fading_colors > 1)
      createfadedcolors();

    if (DisplayCells(d, screen_num) >= cw) {
      cmap = dcmap;
      dallocated = writecolormap(&success);
    }
    else
      dallocated = DisplayCells(d, screen_num);

    pallocated = 0;
    if (!success) {
      XFreeColors(d, cmap, pixels, dallocated, 0);
      if (!opt->defaultcolormap) {
        cmap = XCreateColormap(d, root, visual, AllocNone);
        pallocated = writecolormap(&success);
        if (!success) {
          XFreeColors(d, cmap, pixels, pallocated, 0);
          XFreeColormap(d, cmap);
        }
      }
    }

    cr = dallocated>pallocated ? dallocated : pallocated;
  } while (!success);

  setcoloroptvalues();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
andl $0x0, 0xc(%rsp)
leaq 0xd340(%rip), %r12      # 0x13590
movq (%r12), %rax
cmpl $0x0, 0x13c(%rax)
jne 0x63ef
cmpl $0x1, 0xd40c(%rip)      # 0x13674
je 0x63ef
movq 0xd3c3(%rip), %rax      # 0x13638
movq 0xe8(%rax), %rax
movslq 0xd3f5(%rip), %rcx      # 0x13678
shlq $0x7, %rcx
movq 0x40(%rax,%rcx), %rbx
movq %rbx, %rdi
callq 0x5e17
movq (%r12), %rax
movl 0xd3d6(%rip), %ecx      # 0x13674
pushq $0x1
popq %rdx
shll %cl, %edx
cmpl $0x8, %ecx
movl $0x100, %ecx            # imm = 0x100
cmovll %edx, %ecx
movl 0x14c(%rax), %edx
cmpl $0x2, %edx
cmovgel %edx, %ecx
movl %ecx, 0xd3a0(%rip)      # 0x13660
cmpl $0x0, 0x148(%rax)
jg 0x62cf
movl %ecx, 0x148(%rax)
leaq 0xc(%rsp), %r14
callq 0x6080
callq 0x6165
movq (%r12), %rax
cmpl $0x0, 0x13c(%rax)
jne 0x63ef
cmpl $0x2, 0x148(%rax)
jl 0x62fd
callq 0x5c67
movq 0xd334(%rip), %rax      # 0x13638
movq 0xe8(%rax), %rax
movslq 0xd366(%rip), %rcx      # 0x13678
shlq $0x7, %rcx
movq 0x40(%rax,%rcx), %rax
movl 0x34(%rax), %ebp
cmpl 0xd340(%rip), %ebp      # 0x13664
jl 0x6349
movq 0xd31b(%rip), %rax      # 0x13648
movq %rax, 0xd31c(%rip)      # 0x13650
movq %r14, %rdi
callq 0x5eec
movl %eax, %ebp
cmpl $0x0, 0xc(%rsp)
jne 0x6400
movq 0xd2e8(%rip), %rdi      # 0x13638
movq 0xd2f9(%rip), %rsi      # 0x13650
movq 0xd2c2(%rip), %rdx      # 0x13620
xorl %r15d, %r15d
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x41d0
movq (%r12), %rax
cmpl $0x0, 0x144(%rax)
jne 0x63dc
movq 0xd2b9(%rip), %rdi      # 0x13638
movq 0xd2fa(%rip), %rsi      # 0x13680
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x4210
movq %rax, 0xd2b9(%rip)      # 0x13650
movq %r14, %rdi
callq 0x5eec
movl %eax, %r15d
cmpl $0x0, 0xc(%rsp)
jne 0x6403
movq 0xd288(%rip), %rdi      # 0x13638
movq 0xd299(%rip), %rsi      # 0x13650
movq 0xd262(%rip), %rdx      # 0x13620
movl %r15d, %ecx
xorl %r8d, %r8d
callq 0x41d0
movq 0xd268(%rip), %rdi      # 0x13638
movq 0xd279(%rip), %rsi      # 0x13650
callq 0x40d0
cmpl %r15d, %ebp
cmovgl %ebp, %r15d
movl %r15d, 0xd276(%rip)     # 0x13660
jmp 0x62d4
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x5bea
xorl %r15d, %r15d
cmpl %r15d, %ebp
cmovgl %ebp, %r15d
movl %r15d, 0xd24f(%rip)     # 0x13660
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x5dcb