// File: /workspace/github_cpp_makefile_star2_O2/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, 0x18(%rsp)
movl %r8d, %ebp
movl %ecx, (%rsp)
movl %edx, %r14d
movl %esi, %ebx
movq %rdi, %r13
cmpl %esi, 0x238(%rdi)
jl 0x2fac5
cmpl %r14d, 0x23c(%r13)
jl 0x2fac5
movl (%rsp), %eax
cmpl %eax, 0x240(%r13)
jge 0x2fc94
leaq 0x38(%rsp), %rdi
movq %r13, %rsi
callq 0x2bbaa
movl %ebx, 0x238(%r13)
movl %r14d, 0x23c(%r13)
movl (%rsp), %eax
movl %eax, 0x240(%r13)
movl %ebx, 0x244(%r13)
movl %r14d, %r15d
imull %ebx, %r15d
movl %r15d, 0x248(%r13)
imull %eax, %r15d
movl %r15d, 0x24c(%r13)
movq 0x230(%r13), %rdi
testq %rdi, %rdi
je 0x2fb22
callq 0xe5d0
movl 0x24c(%r13), %r15d
xorl %r12d, %r12d
testl %r15d, %r15d
je 0x2fb42
movslq %r15d, %rax
shlq $0x3, %rax
testl %r15d, %r15d
pushq $-0x1
popq %rdi
cmovnsq %rax, %rdi
callq 0xe030
jmp 0x2fb44
xorl %eax, %eax
movq %rax, 0x230(%r13)
testl %r15d, %r15d
cmovlel %r12d, %r15d
cmpq %r12, %r15
je 0x2fb61
andq $0x0, (%rax,%r12,8)
incq %r12
jmp 0x2fb52
movl 0x278(%rsp), %ecx
movl 0x274(%rsp), %esi
movl 0x270(%rsp), %edx
movq 0x268(%rsp), %r8
movl 0x280(%rsp), %edi
movl %edi, 0x10(%rsp)
movl 0x27c(%rsp), %r10d
movl 0x244(%r13), %r11d
xorl %edi, %edi
testl %edx, %edx
cmovlel %edi, %edx
movq %rdx, 0x30(%rsp)
movl 0x248(%r13), %edx
testl %esi, %esi
cmovlel %edi, %esi
movslq %ebp, %r9
testl %ecx, %ecx
movl $0x0, 0x8(%rsp)
cmovlel %edi, %ecx
movl %ecx, 0x14(%rsp)
movslq %ebx, %rcx
movl %edx, 0xc(%rsp)
movl 0x2c0(%rsp), %edi
imull %edi, %edx
movq %r9, 0x28(%rsp)
addl %r9d, %edx
movl %r11d, %edi
imull 0x18(%rsp), %edi
addl %edx, %edi
movl %edi, 0x4(%rsp)
xorl %edi, %edi
cmpl 0x14(%rsp), %edi
je 0x2fc8a
movl 0x2c0(%rsp), %edx
movq %rdi, 0x20(%rsp)
addl %edi, %edx
cmpl (%rsp), %edx
jge 0x2fc66
xorl %edx, %edx
movl 0x4(%rsp), %r9d
movl 0x8(%rsp), %edi
cmpl %esi, %edx
je 0x2fc66
movq 0x18(%rsp), %rbx
leal (%rdx,%rbx), %ebp
cmpl %r14d, %ebp
jge 0x2fc5c
movq 0x28(%rsp), %r15
movl %r9d, %ebp
movl %edi, %r12d
movq 0x30(%rsp), %r13
subq $0x1, %r13
jb 0x2fc5c
cmpq %rcx, %r15
jge 0x2fc52
movslq %r12d, %rbx
movsd (%r8,%rbx,8), %xmm0
movslq %ebp, %rbx
movsd %xmm0, (%rax,%rbx,8)
incl %r12d
incl %ebp
incq %r15
jmp 0x2fc36
incl %edx
addl %r10d, %edi
addl %r11d, %r9d
jmp 0x2fc15
movq 0x20(%rsp), %rdi
incl %edi
movl 0x8(%rsp), %edx
addl 0x10(%rsp), %edx
movl %edx, 0x8(%rsp)
movl 0x4(%rsp), %edx
addl 0xc(%rsp), %edx
movl %edx, 0x4(%rsp)
jmp 0x2fbed
leaq 0x38(%rsp), %rdi
callq 0x2bc02
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 0x2bc02
movq %rbx, %rdi
callq 0xe810
nop