// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Grid.cpp
// Function: gaps::R2Grid::R2Grid(gaps::R2Grid const&, int, int, int, int)
R2Grid::
R2Grid(const R2Grid& grid, int x1, int y1, int x2, int y2)
  : grid_values(NULL)
{
  // Determine grid resolution
  grid_resolution[0] = x2 - x1 + 1;
  grid_resolution[1] = y2 - y1 + 1;
  if (grid_resolution[0] < 0) grid_resolution[0] = 0;
  if (grid_resolution[1] < 0) grid_resolution[1] = 0;
  grid_row_size = grid_resolution[0];
  grid_size = grid_row_size * grid_resolution[1];

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

  // Copy grid values
  for (int j = 0; j < grid_resolution[1]; j++) {
    int iy = y1 + j;
    for (int i = 0; i < grid_resolution[0]; i++) {
      int ix = x1 + i;
      RNScalar value = 0;
      if ((ix >= 0) && (ix < grid.XResolution())) {
        if ((iy >= 0) && (iy < grid.YResolution())) {
          value = grid.GridValue(ix, iy);
        }
      }
      SetGridValue(i, j, value);
    }
  }

  // Determine transforms
  world_to_grid_transform = grid.world_to_grid_transform;
  world_to_grid_transform.Translate(R2Vector(-x1, -y1));
  world_to_grid_scale_factor = grid.world_to_grid_scale_factor;
  grid_to_world_transform = world_to_grid_transform.Inverse();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r9d, %r13d
movl %r8d, %r14d
movl %ecx, %r12d
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %rbx
callq 0x5d2fe
leaq 0x58(%rbx), %rdi
movq %rdi, 0x10(%rsp)
callq 0x5d2fe
andq $0x0, 0xb8(%rbx)
movl %ebp, 0x8(%rsp)
subl %ebp, %r14d
leal 0x1(%r14), %ebp
movl %ebp, 0xc0(%rbx)
movl %r12d, 0xc(%rsp)
subl %r12d, %r13d
leal 0x1(%r13), %r12d
movl %r12d, 0xc4(%rbx)
cmpl $-0x2, %r14d
jg 0x51b43
andl $0x0, 0xc0(%rbx)
xorl %ebp, %ebp
cmpl $-0x2, %r13d
jg 0x51b53
andl $0x0, 0xc4(%rbx)
xorl %r12d, %r12d
movl %ebp, 0xc8(%rbx)
movl %r12d, %eax
imull %ebp, %eax
movl %eax, 0xcc(%rbx)
testl %eax, %eax
je 0x51b76
movl %eax, %edi
shlq $0x3, %rdi
callq 0xe030
jmp 0x51b78
xorl %eax, %eax
movq %rax, 0xb8(%rbx)
movslq 0xc0(%r15), %rcx
movslq 0xc4(%r15), %rdx
movslq 0xc8(%r15), %rsi
movq %r15, %r13
movslq 0x8(%rsp), %r15
movslq 0xc(%rsp), %r8
movl %ebp, %r9d
movl %r12d, %r10d
leaq (,%r9,8), %r11
movq %rsi, %rdi
imulq %r8, %rdi
leaq (,%r15,8), %r14
leaq (%r14,%rdi,8), %r14
movq %r13, 0x18(%rsp)
addq 0xb8(%r13), %r14
shlq $0x3, %rsi
xorl %r13d, %r13d
cmpq %r10, %r13
je 0x51c1a
leaq (%r8,%r13), %r12
xorl %ebp, %ebp
cmpq %rbp, %r9
je 0x51c0f
movq %r15, %rdi
addq %rbp, %rdi
xorps %xmm0, %xmm0
js 0x51c05
cmpq %rcx, %rdi
jge 0x51c05
testq %r12, %r12
js 0x51c05
cmpq %rdx, %r12
jge 0x51c05
movsd (%r14,%rbp,8), %xmm0
movsd %xmm0, (%rax,%rbp,8)
incq %rbp
jmp 0x51be0
incq %r13
addq %r11, %rax
addq %rsi, %r14
jmp 0x51bd5
movq 0x18(%rsp), %r14
leaq 0x58(%r14), %rsi
movq 0x10(%rsp), %rdi
callq 0x5ac32
movl 0x8(%rsp), %eax
negl %eax
cvtsi2sd %eax, %xmm0
movl 0xc(%rsp), %eax
negl %eax
cvtsi2sd %eax, %xmm1
leaq 0x20(%rsp), %rdi
callq 0x5f8b4
leaq 0x60(%rbx), %rdi
leaq 0x20(%rsp), %rsi
callq 0x5de7a
movsd 0xb0(%r14), %xmm0
movsd %xmm0, 0xb0(%rbx)
leaq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x5ac5c
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x5ac32
leaq 0x20(%rsp), %rdi
callq 0x5d61e
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
leaq 0x20(%rsp), %rdi
callq 0x5d61e
jmp 0x51cba
jmp 0x51cb7
movq %rax, %r15
jmp 0x51cc4
jmp 0x51cb7
movq %rax, %r15
movq 0x10(%rsp), %rdi
callq 0x5d61e
movq %rbx, %rdi
callq 0x5d61e
movq %r15, %rdi
callq 0xe810