// File: /workspace/github_cpp_makefile_star2_O1/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, %ebx
movl %ecx, 0x4(%rsp)
movl %edx, %ebp
movl %esi, %r14d
movq %rdi, %r12
cmpl %esi, 0x238(%rdi)
jl 0x33a6d
cmpl %ebp, 0x23c(%r12)
jl 0x33a6d
movl 0x4(%rsp), %eax
cmpl %eax, 0x240(%r12)
jge 0x33c4e
leaq 0x38(%rsp), %rdi
movq %r12, %rsi
callq 0x2f120
movl %r14d, 0x238(%r12)
movl %ebp, 0x23c(%r12)
movl 0x4(%rsp), %ecx
movl %ecx, 0x240(%r12)
movl %r14d, 0x244(%r12)
movl %ebp, %eax
imull %r14d, %eax
movl %eax, 0x248(%r12)
imull %ecx, %eax
movl %eax, 0x24c(%r12)
movq 0x230(%r12), %rdi
testq %rdi, %rdi
je 0x33ac9
callq 0xe5b0
movslq 0x24c(%r12), %r13
testq %r13, %r13
je 0x33af6
leaq (,%r13,8), %rax
testl %r13d, %r13d
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0xe030
movq %rax, %r15
jmp 0x33af9
xorl %r15d, %r15d
movq %r15, 0x230(%r12)
testl %r13d, %r13d
jle 0x33b17
shlq $0x3, %r13
movq %r15, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0xe260
movl 0x278(%rsp), %eax
movl %eax, 0x18(%rsp)
testl %eax, %eax
jle 0x33c44
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), %eax
movl %eax, 0x1c(%rsp)
movl 0x244(%r12), %r10d
movl 0x248(%r12), %eax
movslq %ebx, %rsi
movslq %r14d, %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 0x33c1b
xorl %r8d, %r8d
movl 0x8(%rsp), %r12d
movl 0xc(%rsp), %ebx
movq 0x20(%rsp), %rax
addl %r8d, %eax
movl %ebp, %r9d
cmpl %ebp, %eax
jge 0x33c08
testl %r11d, %r11d
jle 0x33c08
movq %r11, %rsi
movl %r12d, %ebp
movq 0x30(%rsp), %rax
movl %ebx, %ecx
cmpq %r13, %rax
jge 0x33bfc
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 0x33be5
incl %r8d
addl %r10d, %ebx
addl 0x1c(%rsp), %r12d
cmpl %edx, %r8d
movl %r9d, %ebp
jne 0x33bc4
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 0x33b9a
leaq 0x38(%rsp), %rdi
callq 0x2f17c
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 0x2f17c
movq %rbx, %rdi
callq 0xe7e0
nop