// File: /workspace/github_cpp_makefile_star2_O1/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 0x35d4d
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 0x3d4be
leaq 0x40(%rsp), %rbp
movsd 0x6c46b(%rip), %xmm0    # 0xa2030
movq %rbp, %rdi
movq %r13, %rsi
callq 0x3de8e
movsd (%rsp), %xmm3
movsd 0x8(%rbp), %xmm1
movsd 0x10(%rbp), %xmm4
minsd (%rbp), %xmm1
leaq 0xaffad(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm0
movapd 0x6c429(%rip), %xmm2    # 0xa2020
xorpd %xmm0, %xmm2
ucomisd %xmm2, %xmm3
jb 0x35c0b
ucomisd %xmm3, %xmm0
jae 0x35d4d
minsd %xmm1, %xmm4
ucomisd %xmm2, %xmm4
jb 0x35c1f
ucomisd %xmm4, %xmm0
jae 0x35d4d
movsd %xmm4, 0x8(%rsp)
leaq 0x290(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x2ae6e
leaq 0x70(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x2af90
leaq 0x180(%rsp), %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x2a22e
leaq 0xac484(%rip), %rax     # 0xe20e8
addq $0x10, %rax
movq %rax, (%r12)
leaq 0x78(%rsp), %r15
leaq 0xb0388(%rip), %r13     # 0xe6000
leaq 0x8(%r13), %rsi
movq %r15, %rdi
callq 0x2c5ba
movl $0x88, %esi
addq %rsi, %r12
addq 0xaf34d(%rip), %rsi     # 0xe4fe0
movq %r12, %rdi
callq 0x2c5ba
movq 0x108(%r13), %rax
movq %rax, 0x178(%rsp)
leaq 0x40(%rsp), %rsi
movq %r15, %rdi
callq 0x2d6f4
leaq 0x70(%rsp), %rdi
andb $-0x3, 0x108(%rdi)
leaq 0x180(%rsp), %rsi
callq 0x2a3ea
movsd 0x8(%rsp), %xmm0
divsd (%rsp), %xmm0
movq %r15, %rdi
callq 0x2d8a2
andb $-0x3, 0x178(%rsp)
movsd (%r14), %xmm0
movsd 0x8(%r14), %xmm1
movsd 0x10(%r14), %xmm2
leaq 0x10(%rsp), %rdi
callq 0x3d4be
leaq 0x28(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x3e154
leaq 0x28(%rsp), %rsi
movq %r15, %rdi
callq 0x2d6f4
leaq 0x70(%rsp), %rsi
andb $-0x3, 0x108(%rsi)
movq %rbx, %rdi
callq 0x3336c
leaq 0x70(%rsp), %rdi
callq 0x2a27c
leaq 0x180(%rsp), %rdi
callq 0x2a27c
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 0x2a904
jmp 0x35d7d
jmp 0x35d70
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x2a27c
leaq 0x180(%rsp), %rdi
callq 0x2a27c
movq %rbx, %rdi
callq 0xe7e0