// File: tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Grid.cpp
// Function: gaps::R2Grid::PadWithZero(int, int)
void R2Grid::
PadWithZero(int xresolution, int yresolution)
{
  // Add zeros to achieve desired resolution
  if ((XResolution() >= xresolution) && (YResolution() >= yresolution)) return;

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

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

  // 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 iy = 0; iy < copy.YResolution(); iy++) {
    for (int ix = 0; ix < copy.XResolution(); ix++) {
      RNScalar value = copy.GridValue(ix, iy);
      SetGridValue(ix, iy, value);
    }
  }
}

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movq %rdi, 0x130(%rsp)
movl %esi, 0x12c(%rsp)
movl %edx, 0x128(%rsp)
movq 0x130(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0xb9260
cmpl 0x12c(%rsp), %eax
jl 0xafee0
movq 0x30(%rsp), %rdi
callq 0xb9280
cmpl 0x128(%rsp), %eax
jl 0xafee0
jmp 0xb00e0
movq 0x30(%rsp), %rsi
leaq 0x58(%rsp), %rdi
callq 0xa73a0
movq 0x30(%rsp), %rax
movl 0x12c(%rsp), %ecx
movl %ecx, 0xc0(%rax)
movl 0x128(%rsp), %ecx
movl %ecx, 0xc4(%rax)
movl 0x12c(%rsp), %ecx
movl %ecx, 0xc8(%rax)
movl 0xc8(%rax), %ecx
imull 0x128(%rsp), %ecx
movl %ecx, 0xcc(%rax)
cmpq $0x0, 0xb8(%rax)
je 0xaff5c
movq 0x30(%rsp), %rax
movq 0xb8(%rax), %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, %rax
je 0xaff5a
movq 0x28(%rsp), %rdi
callq 0xf670
jmp 0xaff5c
movq 0x30(%rsp), %rax
cmpl $0x0, 0xcc(%rax)
jne 0xaff7c
movq 0x30(%rsp), %rax
movq $0x0, 0xb8(%rax)
jmp 0xaffda
movq 0x30(%rsp), %rax
movslq 0xcc(%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0xf030
movq %rax, 0x20(%rsp)
jmp 0xaffaa
movq 0x30(%rsp), %rax
movq 0x20(%rsp), %rcx
movq %rcx, 0xb8(%rax)
jmp 0xaffda
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x50(%rsp)
movl %eax, 0x4c(%rsp)
leaq 0x58(%rsp), %rdi
callq 0xa7690
jmp 0xb00e8
movl $0x0, 0x48(%rsp)
movq 0x30(%rsp), %rcx
movl 0x48(%rsp), %eax
cmpl 0xcc(%rcx), %eax
jge 0xb0019
movq 0x30(%rsp), %rax
movq 0xb8(%rax), %rax
movslq 0x48(%rsp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
jmp 0xaffe2
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
movl %eax, 0x18(%rsp)
leaq 0x58(%rsp), %rdi
callq 0xb9280
movl %eax, 0x1c(%rsp)
jmp 0xb0039
movl 0x18(%rsp), %eax
movl 0x1c(%rsp), %ecx
cmpl %ecx, %eax
jge 0xb00d6
movl $0x0, 0x40(%rsp)
movl 0x40(%rsp), %eax
movl %eax, 0x10(%rsp)
leaq 0x58(%rsp), %rdi
callq 0xb9260
movl %eax, 0x14(%rsp)
jmp 0xb0069
movl 0x10(%rsp), %eax
movl 0x14(%rsp), %ecx
cmpl %ecx, %eax
jge 0xb00c4
movl 0x40(%rsp), %esi
movl 0x44(%rsp), %edx
leaq 0x58(%rsp), %rdi
callq 0xb92a0
movsd %xmm0, 0x8(%rsp)
jmp 0xb008f
movq 0x30(%rsp), %rdi
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movl 0x40(%rsp), %esi
movl 0x44(%rsp), %edx
movsd 0x38(%rsp), %xmm0
callq 0x6bc00
jmp 0xb00b5
jmp 0xb00b7
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0xb0051
jmp 0xb00c6
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0xb0021
leaq 0x58(%rsp), %rdi
callq 0xa7690
addq $0x138, %rsp            # imm = 0x138
retq
movq 0x50(%rsp), %rdi
callq 0xf890
nopw %cs:(%rax,%rax)