// File: tomfunkhouser[P]gaps/apps/sflprocess/sflprocess.cpp
// Function: ReadGrid(char const*)
static R2Grid *
ReadGrid(const char *filename)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();

  // Allocate a grid
  R2Grid *grid = new R2Grid();
  if (!grid) {
    RNFail("Unable to allocate grid");
    return NULL;
  }

  // Read grid
  int status = grid->Read(filename);
  if (!status) {
    RNFail("Unable to read grid file %s", filename);
    return NULL;
  }

  // Print statistics
  if (print_verbose) {
    printf("Read grid from %s\n", filename);
    printf("  Time = %.2f seconds\n", start_time.Elapsed());
    printf("  Resolution = %d %d\n", grid->XResolution(), grid->YResolution());
    printf("  Spacing = %g\n", grid->GridToWorldScaleFactor());
    printf("  Cardinality = %d\n", grid->Cardinality());
    RNInterval grid_range = grid->Range();
    printf("  Minimum = %g\n", grid_range.Min());
    printf("  Maximum = %g\n", grid_range.Max());
    printf("  L1Norm = %g\n", grid->L1Norm());
    printf("  L2Norm = %g\n", grid->L2Norm());
    fflush(stdout);
  }

  // Return success
  return grid;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
leaq 0x48(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x16dd30
movq 0x10(%rsp), %rdi
callq 0x263f0
movl $0xd0, %edi
callq 0x16740
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x18(%rsp)
xorl %edx, %edx
movl %edx, %esi
callq 0x13fa60
jmp 0x1a6d2
movq 0x18(%rsp), %rax
movq %rax, 0x40(%rsp)
cmpq $0x0, 0x40(%rsp)
jne 0x1a722
leaq 0x1dde4d(%rip), %rdi    # 0x1f8538
movb $0x0, %al
callq 0x172cb0
movq $0x0, 0x60(%rsp)
jmp 0x1a87b
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x38(%rsp)
movl %eax, 0x34(%rsp)
movl $0xd0, %esi
callq 0x16750
jmp 0x1a885
movq 0x40(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x264e0
movl %eax, 0x30(%rsp)
cmpl $0x0, 0x30(%rsp)
jne 0x1a75d
movq 0x58(%rsp), %rsi
leaq 0x1dde08(%rip), %rdi    # 0x1f8550
movb $0x0, %al
callq 0x172cb0
movq $0x0, 0x60(%rsp)
jmp 0x1a87b
cmpl $0x0, 0x24a05c(%rip)    # 0x2647c0
je 0x1a871
movq 0x58(%rsp), %rsi
leaq 0x1dddf6(%rip), %rdi    # 0x1f856c
movb $0x0, %al
callq 0x16090
leaq 0x48(%rsp), %rdi
callq 0x16ddf0
leaq 0x1dddf1(%rip), %rdi    # 0x1f857f
movb $0x1, %al
callq 0x16090
movq 0x40(%rsp), %rdi
callq 0x26510
movl %eax, 0xc(%rsp)
movq 0x40(%rsp), %rdi
callq 0x26530
movl 0xc(%rsp), %esi
movl %eax, %edx
leaq 0x1ddddc(%rip), %rdi    # 0x1f8596
movb $0x0, %al
callq 0x16090
movq 0x40(%rsp), %rdi
callq 0x26550
leaq 0x1dddda(%rip), %rdi    # 0x1f85ac
movb $0x1, %al
callq 0x16090
movq 0x40(%rsp), %rdi
callq 0x141360
movl %eax, %esi
leaq 0x1dddd0(%rip), %rdi    # 0x1f85bc
movb $0x0, %al
callq 0x16090
movq 0x40(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x140f70
leaq 0x20(%rsp), %rdi
callq 0x265b0
leaq 0x1dddbd(%rip), %rdi    # 0x1f85d0
movb $0x1, %al
callq 0x16090
leaq 0x20(%rsp), %rdi
callq 0x265c0
leaq 0x1dddb5(%rip), %rdi    # 0x1f85e0
movb $0x1, %al
callq 0x16090
movq 0x40(%rsp), %rdi
callq 0x141200
leaq 0x1dddad(%rip), %rdi    # 0x1f85f0
movb $0x1, %al
callq 0x16090
movq 0x40(%rsp), %rdi
callq 0x1412a0
leaq 0x1ddda4(%rip), %rdi    # 0x1f85ff
movb $0x1, %al
callq 0x16090
movq 0x240727(%rip), %rax    # 0x25af90
movq (%rax), %rdi
callq 0x168c0
movq 0x40(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
addq $0x68, %rsp
retq
movq 0x38(%rsp), %rdi
callq 0x16ca0
nop