// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Grid.cpp
// Function: gaps::R3Grid::PadWithZero(int, int, int, int, int, int)
void R3Grid::
PadWithZero(int xresolution, int yresolution, int zresolution,
            int xoffset, int yoffset, int zoffset)
{
  // Add zeros to achieve desired resolution
  if ((XResolution() >= xresolution) && (YResolution() >= yresolution) && (ZResolution() >= zresolution)) return;

  // Copy this grid
  R3Grid copy(*this);

  // Set grid resolution
  grid_resolution[0] = xresolution;
  grid_resolution[1] = yresolution;
  grid_resolution[2] = zresolution;
  grid_row_size = xresolution;
  grid_sheet_size = grid_row_size * yresolution;
  grid_size = grid_sheet_size * zresolution;

  // Allocate grid values
  if (grid_values) delete [] grid_values;
  if (grid_size == 0) grid_values = NULL;
  else grid_values = new RNScalar [ grid_size ];
  assert(!grid_size || grid_values);

  // Set all values to zero
  for (int i = 0; i < grid_size; i++) grid_values[i] = 0;

  // Copy original values
  for (int iz = 0; iz < copy.ZResolution(); iz++) {
    if (iz + zoffset >= zresolution) continue; 
    for (int iy = 0; iy < copy.YResolution(); iy++) {
      if (iy + yoffset >= yresolution) continue; 
      for (int ix = 0; ix < copy.XResolution(); ix++) {
        if (ix + xoffset >= xresolution) continue; 
        RNScalar value = copy.GridValue(ix, iy, iz);
       SetGridValue(ix + xoffset, iy + yoffset, iz + zoffset, value);
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
movq %r9, 0x20(%rsp)
movl %r8d, %r14d
movl %ecx, 0x4(%rsp)
movl %edx, %ebx
movl %esi, %r13d
movq %rdi, %r12
cmpl %esi, 0x238(%rdi)
jl 0x338ab
cmpl %ebx, 0x23c(%r12)
jl 0x338ab
movl 0x4(%rsp), %eax
cmpl %eax, 0x240(%r12)
jge 0x33a8e
leaq 0x38(%rsp), %rdi
movq %r12, %rsi
callq 0x2ee42
movl %r13d, 0x238(%r12)
movl %ebx, 0x23c(%r12)
movl 0x4(%rsp), %eax
movl %eax, 0x240(%r12)
movl %r13d, 0x244(%r12)
movl %ebx, %ebp
imull %r13d, %ebp
movl %ebp, 0x248(%r12)
imull %eax, %ebp
movl %ebp, 0x24c(%r12)
movq 0x230(%r12), %rdi
testq %rdi, %rdi
je 0x3390f
callq 0xe5b0
movl 0x24c(%r12), %ebp
testl %ebp, %ebp
movl %ebx, 0x1c(%rsp)
je 0x33951
movslq %ebp, %rax
shlq $0x3, %rax
testl %ebp, %ebp
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0xe030
movq %rax, %r15
movq %rax, 0x230(%r12)
testl %ebp, %ebp
jle 0x33960
movl %ebp, %edx
shlq $0x3, %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0xe260
jmp 0x33960
movq $0x0, 0x230(%r12)
xorl %r15d, %r15d
movl 0x278(%rsp), %eax
movl %eax, 0x18(%rsp)
testl %eax, %eax
jle 0x33a84
movl 0x2c0(%rsp), %ecx
movl 0x274(%rsp), %edx
movl 0x270(%rsp), %r11d
movq 0x268(%rsp), %rdi
movl 0x280(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x27c(%rsp), %r9d
movl 0x244(%r12), %r10d
movl 0x248(%r12), %eax
movslq %r14d, %rsi
movslq %r13d, %r13
movl %eax, 0x10(%rsp)
imull %ecx, %eax
movq %rsi, 0x30(%rsp)
addl %esi, %eax
movl %r10d, %ecx
imull 0x20(%rsp), %ecx
addl %eax, %ecx
movl %ecx, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
xorl %esi, %esi
testl %edx, %edx
setle %al
movl 0x2c0(%rsp), %ecx
movq %rsi, 0x28(%rsp)
addl %esi, %ecx
cmpl 0x4(%rsp), %ecx
setge %cl
orb %al, %cl
jne 0x33a5b
xorl %r8d, %r8d
movl 0x8(%rsp), %r12d
movl 0xc(%rsp), %ebx
movq 0x20(%rsp), %rax
addl %r8d, %eax
cmpl 0x1c(%rsp), %eax
jge 0x33a4d
testl %r11d, %r11d
jle 0x33a4d
movq %r11, %rsi
movl %r12d, %ebp
movq 0x30(%rsp), %rax
movl %ebx, %ecx
cmpq %r13, %rax
jge 0x33a41
movslq %ebp, %r14
movsd (%rdi,%r14,8), %xmm0
movslq %ecx, %r14
movsd %xmm0, (%r15,%r14,8)
incl %ecx
incq %rax
incl %ebp
decq %rsi
jne 0x33a2a
incl %r8d
addl %r10d, %ebx
addl %r9d, %r12d
cmpl %edx, %r8d
jne 0x33a0a
movq 0x28(%rsp), %rsi
incl %esi
movl 0xc(%rsp), %eax
addl 0x10(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0x8(%rsp), %eax
addl 0x14(%rsp), %eax
movl %eax, 0x8(%rsp)
cmpl 0x18(%rsp), %esi
jne 0x339e0
leaq 0x38(%rsp), %rdi
callq 0x2ee9e
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x2ee9e
movq %rbx, %rdi
callq 0xe7e0
nop