// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Grid.cpp
// Function: gaps::R3Grid::SetWorldToGridTransformation(gaps::R3Point const&, gaps::R3Vector const&, gaps::R3Vector const&, double)
void R3Grid::
SetWorldToGridTransformation(const R3Point& world_origin, const R3Vector& world_axis1, const R3Vector& world_axis2, RNLength world_radius)
{
  // Just checking
  if (grid_size == 0) return;

  // Compute grid origin
  R3Vector grid_diagonal(XResolution()-1, YResolution()-1, ZResolution()-1);
  R3Vector grid_origin = 0.5 * grid_diagonal;
  RNScalar grid_radius = grid_origin[0];
  if (grid_origin[1] < grid_radius) grid_radius = grid_origin[1];
  if (grid_origin[2] < grid_radius) grid_radius = grid_origin[2];

  // Compute scale
  if (RNIsZero(world_radius)) return;
  if (RNIsZero(grid_radius)) return;
  RNScalar scale = grid_radius / world_radius;

  // Compute rotation
  R3Triad world_triad(world_axis1, world_axis2);
  R3Affine rotation(world_triad.InverseMatrix());

  // Compute world-to-grid transformation
  R3Affine affine(R3identity_affine);
  affine.Translate(grid_origin);
  affine.Transform(rotation);
  affine.Scale(scale);
  affine.Translate(-(world_origin.Vector()));

  // Set transformations
  SetWorldToGridTransformation(affine);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2d8, %rsp            # imm = 0x2D8
cmpl $0x0, 0x24c(%rdi)
je 0x35b5d
movaps %xmm0, %xmm3
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
movl 0x238(%rdi), %eax
decl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movl 0x23c(%rdi), %eax
decl %eax
cvtsi2sd %eax, %xmm1
movl 0x240(%rdi), %eax
decl %eax
cvtsi2sd %eax, %xmm2
leaq 0x58(%rsp), %r13
movq %r13, %rdi
movsd %xmm3, (%rsp)
callq 0x3cfc6
leaq 0x40(%rsp), %rbp
movsd 0x6c65b(%rip), %xmm0    # 0xa2030
movq %rbp, %rdi
movq %r13, %rsi
callq 0x3d962
movsd (%rsp), %xmm3
movsd 0x8(%rbp), %xmm1
movsd 0x10(%rbp), %xmm4
minsd (%rbp), %xmm1
leaq 0xb019d(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm0
movapd 0x6c619(%rip), %xmm2    # 0xa2020
xorpd %xmm0, %xmm2
ucomisd %xmm2, %xmm3
jb 0x35a1b
ucomisd %xmm3, %xmm0
jae 0x35b5d
minsd %xmm1, %xmm4
ucomisd %xmm2, %xmm4
jb 0x35a2f
ucomisd %xmm4, %xmm0
jae 0x35b5d
movsd %xmm4, 0x8(%rsp)
leaq 0x290(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x2ac26
leaq 0x70(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x2ad48
leaq 0x180(%rsp), %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x29fda
leaq 0xac674(%rip), %rax     # 0xe20e8
addq $0x10, %rax
movq %rax, (%r12)
leaq 0x78(%rsp), %r15
leaq 0xb0578(%rip), %r13     # 0xe6000
leaq 0x8(%r13), %rsi
movq %r15, %rdi
callq 0x2c2be
movl $0x88, %esi
addq %rsi, %r12
addq 0xaf53d(%rip), %rsi     # 0xe4fe0
movq %r12, %rdi
callq 0x2c2be
movq 0x108(%r13), %rax
movq %rax, 0x178(%rsp)
leaq 0x40(%rsp), %rsi
movq %r15, %rdi
callq 0x2d3f8
leaq 0x70(%rsp), %rdi
andb $-0x3, 0x108(%rdi)
leaq 0x180(%rsp), %rsi
callq 0x2a196
movsd 0x8(%rsp), %xmm0
divsd (%rsp), %xmm0
movq %r15, %rdi
callq 0x2d5a6
andb $-0x3, 0x178(%rsp)
movsd (%r14), %xmm0
movsd 0x8(%r14), %xmm1
movsd 0x10(%r14), %xmm2
leaq 0x10(%rsp), %rdi
callq 0x3cfc6
leaq 0x28(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x3dc00
leaq 0x28(%rsp), %rsi
movq %r15, %rdi
callq 0x2d3f8
leaq 0x70(%rsp), %rsi
andb $-0x3, 0x108(%rsi)
movq %rbx, %rdi
callq 0x331b6
leaq 0x70(%rsp), %rdi
callq 0x2a028
leaq 0x180(%rsp), %rdi
callq 0x2a028
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x2a6bc
jmp 0x35b8d
jmp 0x35b80
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x2a028
leaq 0x180(%rsp), %rdi
callq 0x2a028
movq %rbx, %rdi
callq 0xe7e0