// File: /workspace/github_cpp_makefile_star2_O1/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 $0xc8, %rsp
movl %r9d, %r13d
movl %r8d, %r14d
movl %ecx, %ebp
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, %rbx
callq 0x669b0
leaq 0x58(%rbx), %rdi
movq %rdi, 0x20(%rsp)
movq %rbx, 0x10(%rsp)
callq 0x669b0
movq $0x0, 0xb8(%rbx)
subl %r12d, %r14d
leal 0x1(%r14), %eax
movl %eax, 0xc0(%rbx)
subl %ebp, %r13d
leal 0x1(%r13), %eax
movl %eax, 0xc4(%rbx)
cmpl $-0x2, %r14d
jg 0x5a171
movl $0x0, 0xc0(%rbx)
cmpl $-0x2, %r13d
jg 0x5a181
movl $0x0, 0xc4(%rbx)
movslq 0xc0(%rbx), %r14
movl %r14d, 0xc8(%rbx)
movl 0xc4(%rbx), %r13d
movl %r13d, %eax
imull %r14d, %eax
movl %eax, 0xcc(%rbx)
testl %eax, %eax
movq %r15, 0x18(%rsp)
movl %ebp, 0xc(%rsp)
movl %r12d, 0x8(%rsp)
jle 0x5a1c2
movl %eax, %edi
shlq $0x3, %rdi
callq 0xe030
jmp 0x5a1c4
xorl %eax, %eax
movq %rax, 0xb8(%rbx)
testl %r13d, %r13d
jle 0x5a26c
movl %r14d, %ecx
movq 0x18(%rsp), %r10
movslq 0xc0(%r10), %rdx
movslq 0xc8(%r10), %rsi
movslq 0x8(%rsp), %rbx
movslq 0xc(%rsp), %r8
movq %rsi, %rdi
imulq %r8, %rdi
leaq (,%rbx,8), %r9
leaq (%r9,%rdi,8), %r9
addq 0xb8(%r10), %r9
movslq 0xc4(%r10), %r10
shlq $0x3, %rsi
leaq (,%r14,8), %r11
xorl %ebp, %ebp
testl %r14d, %r14d
jle 0x5a25e
leaq (%r8,%rbp), %r12
xorl %r15d, %r15d
movq %rbx, %rdi
addq %r15, %rdi
xorpd %xmm0, %xmm0
js 0x5a250
cmpq %rdx, %rdi
jge 0x5a250
testq %r12, %r12
js 0x5a250
cmpq %r10, %r12
jge 0x5a250
movsd (%r9,%r15,8), %xmm0
movsd %xmm0, (%rax,%r15,8)
incq %r15
cmpq %r15, %rcx
jne 0x5a22f
incq %rbp
addq %rsi, %r9
addq %r11, %rax
cmpq %r13, %rbp
jne 0x5a223
movq 0x10(%rsp), %rbx
leaq 0x60(%rbx), %r13
movq 0x18(%rsp), %r14
leaq 0x60(%r14), %rsi
movq %r13, %rdi
callq 0x67944
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %edx
movl 0xa8(%r14), %eax
negl %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movl %eax, 0xa8(%rbx)
negl %ecx
cvtsi2sd %ecx, %xmm1
leaq 0x28(%rsp), %rdi
callq 0x6915a
leaq 0x28(%rsp), %rsi
movq %r13, %rdi
callq 0x67606
movsd 0xb0(%r14), %xmm0
movsd %xmm0, 0xb0(%rbx)
leaq 0x80(%rsp), %rdi
movq %r13, %rsi
callq 0x672d4
movl 0xa8(%rbx), %edx
leaq 0x28(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x669e6
leaq 0x8(%rbx), %rdi
leaq 0x30(%rsp), %rsi
callq 0x67944
leaq 0x28(%rsp), %rdi
movl 0x50(%rdi), %eax
movl %eax, 0x50(%rbx)
callq 0x66ce4
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
leaq 0x28(%rsp), %rdi
callq 0x66ce4
jmp 0x5a345
movq %rax, %r15
jmp 0x5a34f
jmp 0x5a342
jmp 0x5a342
movq %rax, %r15
movq 0x20(%rsp), %rdi
callq 0x66ce4
movq 0x10(%rsp), %rdi
callq 0x66ce4
movq %r15, %rdi
callq 0xe7e0
nop