// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Grid.cpp
// Function: gaps::R3Grid::Slice(int, int) const
R2Grid *R3Grid::
Slice(int dim, int grid_coordinate) const
{
  // Extract 2D grid along slice at given coordinate in given dimension

  // Compute parameters
  int dim1 = (dim+1)%3;
  int dim2 = (dim+2)%3;
  R3Box world_box = WorldBox();
  R2Box slice_box(world_box[0][dim1], world_box[0][dim2], world_box[1][dim1], world_box[1][dim2]);

  // Allocate 2D grid for slice
  R2Grid *slice = new R2Grid(grid_resolution[dim1], grid_resolution[dim2], slice_box);
  if (!slice) {
    RNFail("Unable to allocate slice\n");
    return NULL;
  }

  // Fill values
  for (int i = 0; i < grid_resolution[dim1]; i++) {
    for (int j = 0; j < grid_resolution[dim2]; j++) {
      RNScalar value = 0.0;
      if (dim == RN_X) value = GridValue(grid_coordinate, i, j);
      else if (dim == RN_Y) value = GridValue(j, grid_coordinate, i);
      else value = GridValue(i, j, grid_coordinate);
      slice->SetGridValue(i, j, value);
    }
  }

  // Return slice
  return slice;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %edx, %ebx
movl %esi, %r14d
movq %rdi, %r15
leal 0x1(%r14), %eax
cltq
imulq $0x55555556, %rax, %rax # imm = 0x55555556
movq %rax, %rcx
shrq $0x3f, %rcx
shrq $0x20, %rax
addl %ecx, %eax
leal (%rax,%rax,2), %eax
negl %eax
addl %r14d, %eax
incl %eax
movl %eax, (%rsp)
leal 0x2(%r14), %eax
cltq
imulq $0x55555556, %rax, %rax # imm = 0x55555556
movq %rax, %rcx
shrq $0x3f, %rcx
shrq $0x20, %rax
addl %ecx, %eax
leal (%rax,%rax,2), %eax
negl %eax
leal (%r14,%rax), %ebp
addl $0x2, %ebp
leaq 0x20(%rsp), %r12
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %r12, %rdi
callq 0x3ca26
movl 0x238(%r15), %eax
decl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movl 0x23c(%r15), %eax
decl %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movl 0x240(%r15), %eax
decl %eax
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
leaq 0xb0(%rsp), %r13
movq %r13, %rdi
callq 0x3ca26
movsd (%r12), %xmm0
movsd 0x8(%r12), %xmm1
movsd 0x10(%r12), %xmm2
leaq 0x98(%rsp), %r12
movq %r12, %rdi
callq 0x3ca26
movq %r12, %rdi
movq %r15, %rsi
callq 0x3d342
movsd (%r13), %xmm0
movsd 0x8(%r13), %xmm1
movsd 0x10(%r13), %xmm2
leaq 0x80(%rsp), %r13
movq %r13, %rdi
callq 0x3ca26
movq %r13, %rdi
movq %r15, 0x10(%rsp)
movq %r15, %rsi
callq 0x3d342
leaq 0x48(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x27542
movslq (%rsp), %r12
movslq %ebp, %r15
movsd 0x50(%rsp,%r12,8), %xmm0
movsd 0x68(%rsp,%r12,8), %xmm2
movsd 0x50(%rsp,%r15,8), %xmm1
movsd 0x68(%rsp,%r15,8), %xmm3
leaq 0x20(%rsp), %rdi
callq 0x6611c
movl $0xd0, %edi
callq 0xe440
movq 0x10(%rsp), %r13
movl 0x238(%r13,%r12,4), %esi
movl 0x238(%r13,%r15,4), %edx
leaq 0x20(%rsp), %rcx
movq %rax, 0x8(%rsp)
movq %rax, %rdi
callq 0x59ce4
movslq 0x238(%r13,%r12,4), %rax
movq %rax, 0x18(%rsp)
testq %rax, %rax
jle 0x30226
movq 0x10(%rsp), %rax
movl 0x238(%rax,%r15,4), %eax
movq %rax, (%rsp)
xorl %edx, %edx
xorl %esi, %esi
cmpl $0x0, (%rsp)
jle 0x30214
movq 0x10(%rsp), %rax
movq 0x230(%rax), %rdi
movl 0x248(%rax), %r12d
movl 0x244(%rax), %r9d
movl %r9d, %eax
imull %ebx, %eax
movl %r9d, %r10d
imull %esi, %r10d
movl %r12d, %r11d
imull %ebx, %r11d
addl %esi, %r11d
movq 0x8(%rsp), %rcx
movslq 0xc8(%rcx), %r13
movl %r12d, %r8d
imull %esi, %r8d
addl %eax, %r8d
movq 0xb8(%rcx), %rax
addq %rdx, %rax
shlq $0x3, %r13
movq (%rsp), %rcx
xorl %r15d, %r15d
movl %r8d, %ebp
cmpl $0x1, %r14d
je 0x301fa
testl %r14d, %r14d
jne 0x301f0
movl %r12d, %ebp
imull %r15d, %ebp
addl %ebx, %ebp
addl %r10d, %ebp
jmp 0x301fa
movl %r9d, %ebp
imull %r15d, %ebp
addl %r11d, %ebp
movslq %ebp, %rbp
movsd (%rdi,%rbp,8), %xmm0
movsd %xmm0, (%rax)
incq %r15
incl %r8d
addq %r13, %rax
decq %rcx
jne 0x301d4
incq %rsi
addq $0x8, %rdx
cmpq 0x18(%rsp), %rsi
jne 0x3016e
leaq 0x20(%rsp), %rdi
callq 0x6699c
leaq 0x48(%rsp), %rdi
callq 0x28348
movq 0x8(%rsp), %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0xd0, %esi
movq 0x8(%rsp), %rdi
callq 0xe450
jmp 0x30268
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x6699c
jmp 0x30277
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x28348
movq %rbx, %rdi
callq 0xe7e0
nop