// File: tomfunkhouser[P]gaps/apps/prpview/prpview.cpp
// Function: NormalizedColor(gaps::R3MeshVertex*)
static RNRgb 
NormalizedColor(R3MeshVertex *vertex)
{
  // Check color scheme
  RNRgb c(0, 0, 0);
  if (color_with_labels) {
    // Color with deterministic value based on int label
    int ivalue = (current_property->VertexValue(vertex) + 0.5);
    c[0] = (ivalue % 7) / 6.0;
    c[1] = (ivalue % 5) / 4.0;
    c[2] = (ivalue % 2) / 1.0;
  }
  else {
    // Compute normalized value
    RNScalar value = NormalizedValue(vertex);
    if (flip_color_range) value = 1.0 - value;
    
    // Compute color
    if (color_with_redness) {
      c[0] = 0.8;
      c[1] = 0.8 * (1 - value);
      c[2] = 0.8 * (1 - value);
    }
    else {
      if (value < 0.5) {
        c[0] = 1 - 2 * value;
        c[1] = 2 * value;
      }
      else {
        c[1] = 1 - 2 * (value - 0.5);
        c[2] = 2 * (value - 0.5);
      }
    }
  }
  
  // Return color
  return c;
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x48(%rsp)
movq %rdi, %rax
movq %rax, 0x50(%rsp)
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0xf7470
cmpl $0x0, 0x1dc854(%rip)    # 0x204d24
je 0x285ae
movq 0x1dc7db(%rip), %rdi    # 0x204cb8
movq 0x68(%rsp), %rsi
callq 0x2b020
movq 0x48(%rsp), %rdi
movsd 0x16db64(%rip), %xmm1   # 0x196058
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x64(%rsp)
movl 0x64(%rsp), %eax
movl $0x7, %ecx
cltd
idivl %ecx
cvtsi2sd %edx, %xmm0
movsd 0x16db68(%rip), %xmm1   # 0x196080
divsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
xorl %esi, %esi
callq 0x2b060
movsd 0x30(%rsp), %xmm0
movq 0x48(%rsp), %rdi
movsd %xmm0, (%rax)
movl 0x64(%rsp), %eax
movl $0x5, %ecx
cltd
idivl %ecx
cvtsi2sd %edx, %xmm0
movsd 0x16db28(%rip), %xmm1   # 0x196078
divsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rsp)
movl $0x1, %esi
callq 0x2b060
movsd 0x38(%rsp), %xmm0
movq 0x48(%rsp), %rdi
movsd %xmm0, (%rax)
movl 0x64(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cvtsi2sd %edx, %xmm0
movsd 0x16dadd(%rip), %xmm1   # 0x196068
divsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movl $0x2, %esi
callq 0x2b060
movsd 0x40(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0x28768
movq 0x68(%rsp), %rdi
callq 0x28780
movsd %xmm0, 0x58(%rsp)
cmpl $0x0, 0x1dc75b(%rip)    # 0x204d20
je 0x285db
movsd 0x16da99(%rip), %xmm0   # 0x196068
subsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
cmpl $0x0, 0x1dc6ba(%rip)    # 0x204c9c
je 0x28677
movq 0x48(%rsp), %rdi
xorl %esi, %esi
callq 0x2b060
movq 0x48(%rsp), %rdi
movsd 0x16da27(%rip), %xmm0   # 0x196028
movsd %xmm0, (%rax)
movsd 0x16da5b(%rip), %xmm1   # 0x196068
subsd 0x58(%rsp), %xmm1
movsd 0x16da0d(%rip), %xmm0   # 0x196028
mulsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movl $0x1, %esi
callq 0x2b060
movsd 0x20(%rsp), %xmm0
movq 0x48(%rsp), %rdi
movsd %xmm0, (%rax)
movsd 0x16da22(%rip), %xmm1   # 0x196068
subsd 0x58(%rsp), %xmm1
movsd 0x16d9d4(%rip), %xmm0   # 0x196028
mulsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
movl $0x2, %esi
callq 0x2b060
movsd 0x28(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0x28766
movsd 0x16d9d9(%rip), %xmm0   # 0x196058
ucomisd 0x58(%rsp), %xmm0
jbe 0x286e8
movq 0x48(%rsp), %rdi
movsd 0x58(%rsp), %xmm1
addsd %xmm1, %xmm1
movsd 0x16d9ca(%rip), %xmm0   # 0x196068
subsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
xorl %esi, %esi
callq 0x2b060
movsd 0x10(%rsp), %xmm0
movq 0x48(%rsp), %rdi
movsd %xmm0, (%rax)
movsd 0x16d9aa(%rip), %xmm0   # 0x196070
mulsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movl $0x1, %esi
callq 0x2b060
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0x28764
movq 0x48(%rsp), %rdi
movsd 0x58(%rsp), %xmm1
movsd 0x16d95d(%rip), %xmm0   # 0x196058
subsd %xmm0, %xmm1
addsd %xmm1, %xmm1
movsd 0x16d95d(%rip), %xmm0   # 0x196068
subsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
movl $0x1, %esi
callq 0x2b060
movsd (%rsp), %xmm0
movq 0x48(%rsp), %rdi
movsd %xmm0, (%rax)
movsd 0x58(%rsp), %xmm1
movsd 0x16d91e(%rip), %xmm0   # 0x196058
subsd %xmm0, %xmm1
movsd 0x16d92a(%rip), %xmm0   # 0x196070
mulsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movl $0x2, %esi
callq 0x2b060
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0x28766
jmp 0x28768
movq 0x50(%rsp), %rax
addq $0x78, %rsp
retq
nopw %cs:(%rax,%rax)