// File: /workspace/github_cpp_makefile_star2_O3/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, %r12d
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %rbx
callq 0x65c28
leaq 0x58(%rbx), %rdi
movq %rdi, 0x20(%rsp)
movq %rbx, 0x10(%rsp)
callq 0x65c28
movq $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 0x5947f
movl $0x0, 0xc0(%rbx)
xorl %ebp, %ebp
cmpl $-0x2, %r13d
jg 0x59492
movl $0x0, 0xc4(%rbx)
xorl %r12d, %r12d
movl %ebp, 0xc8(%rbx)
movl %r12d, %eax
imull %ebp, %eax
movl %eax, 0xcc(%rbx)
testl %eax, %eax
movq %r15, 0x18(%rsp)
je 0x594ba
movl %eax, %edi
shlq $0x3, %rdi
callq 0xe030
jmp 0x594bc
xorl %eax, %eax
movq %rax, 0xb8(%rbx)
testl %r12d, %r12d
je 0x59567
movq 0x18(%rsp), %r11
movslq 0xc0(%r11), %rcx
movslq 0xc4(%r11), %rdx
movslq 0xc8(%r11), %rsi
movslq 0x8(%rsp), %rbx
movslq 0xc(%rsp), %r8
movl %r12d, %r9d
movq %rsi, %rdi
imulq %r8, %rdi
leaq (,%rbx,8), %r10
leaq (%r10,%rdi,8), %r10
addq 0xb8(%r11), %r10
movl %ebp, %r11d
shlq $0x3, %rsi
leaq (,%r11,8), %r14
xorl %r13d, %r13d
testl %ebp, %ebp
je 0x59559
leaq (%r8,%r13), %r12
xorl %r15d, %r15d
movq %rbx, %rdi
addq %r15, %rdi
xorpd %xmm0, %xmm0
js 0x5954b
cmpq %rcx, %rdi
jge 0x5954b
testq %r12, %r12
js 0x5954b
cmpq %rdx, %r12
jge 0x5954b
movsd (%r10,%r15,8), %xmm0
movsd %xmm0, (%rax,%r15,8)
incq %r15
cmpq %r15, %r11
jne 0x5952a
incq %r13
addq %rsi, %r10
addq %r14, %rax
cmpq %r9, %r13
jne 0x5951f
movq 0x10(%rsp), %rbx
leaq 0x60(%rbx), %r13
movq 0x18(%rsp), %r14
leaq 0x60(%r14), %rsi
movq %r13, %rdi
callq 0x66bbc
movl 0xa8(%r14), %eax
movl 0x8(%rsp), %ecx
negl %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movl %eax, 0xa8(%rbx)
movl 0xc(%rsp), %eax
negl %eax
cvtsi2sd %eax, %xmm1
leaq 0x28(%rsp), %rdi
callq 0x683d2
leaq 0x28(%rsp), %rsi
movq %r13, %rdi
callq 0x6687e
movsd 0xb0(%r14), %xmm0
movsd %xmm0, 0xb0(%rbx)
leaq 0x80(%rsp), %rdi
movq %r13, %rsi
callq 0x6654c
movl 0xa8(%rbx), %edx
leaq 0x28(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x65c5e
leaq 0x8(%rbx), %rdi
leaq 0x30(%rsp), %rsi
callq 0x66bbc
leaq 0x28(%rsp), %rdi
movl 0x50(%rdi), %eax
movl %eax, 0x50(%rbx)
callq 0x65f5c
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
leaq 0x28(%rsp), %rdi
callq 0x65f5c
jmp 0x59640
movq %rax, %r15
jmp 0x5964a
jmp 0x5963d
jmp 0x5963d
movq %rax, %r15
movq 0x20(%rsp), %rdi
callq 0x65f5c
movq 0x10(%rsp), %rdi
callq 0x65f5c
movq %r15, %rdi
callq 0xe7e0