// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelPointSet.cpp
// Function: gaps::R3SurfelPointSet::Draw(gaps::RNFlags) const
void R3SurfelPointSet::
Draw(RNFlags flags) const
{
  // Get convenient variables
  int c = flags[R3_SURFEL_COLOR_DRAW_FLAG];
  int n = flags[R3_SURFEL_NORMAL_DRAW_FLAG];
  int d = flags[R3_SURFEL_DISC_DRAW_FLAG];
  int id = flags[R3_SURFEL_IDENTIFIER_DRAW_FLAG];

  // Draw discs
  if (d) {
    const int nsides = 6;
    RNGrfxBegin(RN_GRFX_TRIANGLES);
    for (int i = 0; i < NPoints(); i++) {
      const R3SurfelPoint *point = Point(i);
      R3Point position = point->Position();
      R3Vector normal = point->Normal();
      R3Vector tangent1 = point->Tangent();
      R3Vector tangent2 = tangent1 % normal;
      double r1 = point->Radius(0);
      double r2 = point->Radius(1);
      if (r1 <= 0) r1 = 0.1;
      if (r2 <= 0) r2 = r1;
      if (c) RNLoadRgb(point->Color());
      if (id) RNLoadRgba(point->Identifier());
      else if (n) R3LoadNormal(normal);
      R3Point p[nsides];
      for (int j = 0; j < nsides; j++) {
        double angle = RN_TWO_PI*j/nsides;
        p[j] = position;
        p[j] += cos(angle) * r1 * tangent1;
        p[j] += sin(angle) * r2 * tangent2;
      }
      for (int j = 0; j < nsides; j++) {
        R3LoadPoint(position);
        R3LoadPoint(p[(j+1)%nsides]);
        R3LoadPoint(p[j]);
      }
    }
    RNGrfxEnd();
  }
  else {
    // Draw surfels with color
    RNGrfxBegin(RN_GRFX_POINTS);
    for (int i = 0; i < NPoints(); i++) {
      const R3SurfelPoint *point = Point(i);
      if (c) RNLoadRgb(point->Color());
      if (id) RNLoadRgba(point->Identifier());
      else if (n) R3LoadNormal(point->Normal());
      R3LoadPoint(point->Position());
    }
    RNGrfxEnd();
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rdi, 0x20(%rsp)
movq %rsi, 0x8(%rsp)
testb $0x10, %sil
jne 0x314a3
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x13130
leaq 0xc0(%rsp), %r14
xorl %r12d, %r12d
movq 0x20(%rsp), %rcx
movslq 0x10(%rcx), %rax
cmpq %rax, %r12
jge 0x316d6
movq 0x8(%rcx), %r13
movq 0x8(%rsp), %rax
testb $0x1, %al
je 0x31459
movq 0x8(%r13,%rbx), %rdi
addq $0x2c, %rdi
callq 0x13680
movq 0x8(%rsp), %rax
leaq (%rbx,%r13), %r15
testb $0x4, %al
jne 0x3147a
testb $0x2, %al
je 0x31487
movq %r14, %rdi
movq %r15, %rsi
callq 0x2d0ce
movq %r14, %rdi
callq 0x137c0
jmp 0x31487
movq 0x8(%r13,%rbx), %rax
movl 0x20(%rax), %edi
callq 0x2d196
movq %r14, %rdi
movq %r15, %rsi
callq 0x16310
movq %r14, %rdi
callq 0x13150
incq %r12
addq $0x10, %rbx
jmp 0x31427
pushq $0x4
popq %rdi
callq 0x13130
leaq 0xa02c6(%rip), %rax     # 0xd1778
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
xorl %r14d, %r14d
leaq 0xa8(%rsp), %r15
leaq 0x90(%rsp), %r13
leaq 0x78(%rsp), %rbp
leaq 0x60(%rsp), %r12
movq 0x20(%rsp), %rcx
movslq 0x10(%rcx), %rax
cmpq %rax, %r14
jge 0x316d6
movq 0x8(%rcx), %rax
movq %rax, 0x10(%rsp)
movq %r14, 0x38(%rsp)
shlq $0x4, %r14
leaq (%rax,%r14), %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x16310
leaq 0x48(%rsp), %rdi
movq %rbx, %rsi
callq 0x2d0ce
movq %r13, %rdi
movq %rbx, 0x30(%rsp)
movq %rbx, %rsi
callq 0x2d118
movq %rbp, %rdi
movq %r13, %rsi
leaq 0x48(%rsp), %rdx
callq 0x7902e
movq 0x10(%rsp), %rax
movq 0x8(%rax,%r14), %rdi
movd 0x1c(%rdi), %xmm0
pxor %xmm2, %xmm2
punpcklwd %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1],xmm0[2],xmm2[2],xmm0[3],xmm2[3]
cvtdq2ps %xmm0, %xmm0
mulps 0x96e96(%rip), %xmm0    # 0xc83f0
movaps %xmm0, %xmm1
cmpnleps %xmm2, %xmm1
unpcklps %xmm1, %xmm1            # xmm1 = xmm1[0,0,1,1]
movmskpd %xmm1, %eax
testb $0x1, %al
jne 0x31576
movsd 0x96dfc(%rip), %xmm1    # 0xc8370
jmp 0x3157a
cvtss2sd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
testb $0x2, %al
movq 0x8(%rsp), %rax
jne 0x31591
movsd 0x18(%rsp), %xmm0
jmp 0x31599
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x28(%rsp)
testb $0x1, %al
je 0x315b1
addq $0x2c, %rdi
callq 0x13680
movq 0x8(%rsp), %rax
testb $0x4, %al
jne 0x315c5
testb $0x2, %al
je 0x315d6
leaq 0x48(%rsp), %rdi
callq 0x137c0
jmp 0x315d6
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rax
movl 0x20(%rax), %edi
callq 0x2d196
xorl %ebx, %ebx
leaq (%rsp,%rbx), %rdi
addq $0xc0, %rdi
callq 0x781ba
addq $0x18, %rbx
cmpq $0x90, %rbx
jne 0x315d8
leaq 0xc0(%rsp), %r14
xorl %ebx, %ebx
cmpq $0x6, %rbx
je 0x3167f
cvtsi2sd %ebx, %xmm0
mulsd 0x40(%rsp), %xmm0
divsd 0x96d61(%rip), %xmm0    # 0xc8378
movsd %xmm0, 0x10(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x784a6
movsd 0x10(%rsp), %xmm0
callq 0x13990
mulsd 0x18(%rsp), %xmm0
movq %r12, %rdi
movq %r13, %rsi
callq 0x79072
movq %r14, %rdi
movq %r12, %rsi
callq 0x7850c
movsd 0x10(%rsp), %xmm0
callq 0x13100
mulsd 0x28(%rsp), %xmm0
movq %r12, %rdi
movq %rbp, %rsi
callq 0x79072
movq %r14, %rdi
movq %r12, %rsi
callq 0x7850c
incq %rbx
addq $0x18, %r14
jmp 0x315ff
leaq 0xc0(%rsp), %r14
pushq $-0x6
popq %rbx
testq %rbx, %rbx
je 0x316c9
movq %r15, %rdi
callq 0x13150
leaq 0x7(%rbx), %rax
incq %rbx
movl $0x0, %ecx
cmovneq %rax, %rcx
imulq $0x18, %rcx, %rax
leaq (%rsp,%rax), %rdi
addq $0xc0, %rdi
callq 0x13150
movq %r14, %rdi
callq 0x13150
addq $0x18, %r14
jmp 0x3168a
movq 0x38(%rsp), %r14
incq %r14
jmp 0x314d9
callq 0x136d0
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop