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

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

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

  // Print statistics
  if (print_verbose) {
    printf("Read grid ...\n");
    printf("  Time = %.2f seconds\n", start_time.Elapsed());
    printf("  Resolution = %d %d %d\n", grid->XResolution(), grid->YResolution(), grid->ZResolution());
    printf("  Spacing = %g\n", grid->GridToWorldScaleFactor());
    printf("  Cardinality = %d\n", grid->Cardinality());
    printf("  Volume = %g\n", grid->Volume());
    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 0xd1630
movq 0x10(%rsp), %rdi
callq 0x140a0
movl $0x250, %edi            # imm = 0x250
callq 0xf4c0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x18(%rsp)
xorl %ecx, %ecx
movl %ecx, %esi
movl %ecx, %edx
callq 0x141e0
jmp 0x135c4
movq 0x18(%rsp), %rax
movq %rax, 0x40(%rsp)
cmpq $0x0, 0x40(%rsp)
jne 0x13614
leaq 0x120c53(%rip), %rdi    # 0x134230
movb $0x0, %al
callq 0xd5850
movq $0x0, 0x60(%rsp)
jmp 0x13792
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x38(%rsp)
movl %eax, 0x34(%rsp)
movl $0x250, %esi            # imm = 0x250
callq 0xf4d0
jmp 0x1379c
movq 0x40(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x218a0
movl %eax, 0x30(%rsp)
cmpl $0x0, 0x30(%rsp)
jne 0x1364f
movq 0x58(%rsp), %rsi
leaq 0x120c0e(%rip), %rdi    # 0x134248
movb $0x0, %al
callq 0xd5850
movq $0x0, 0x60(%rsp)
jmp 0x13792
cmpl $0x0, 0x166b9a(%rip)    # 0x17a1f0
je 0x13788
leaq 0x120c01(%rip), %rdi    # 0x134264
movb $0x0, %al
callq 0xf070
leaq 0x48(%rsp), %rdi
callq 0xd16f0
leaq 0x120bf8(%rip), %rdi    # 0x134273
movb $0x1, %al
callq 0xf070
movq 0x40(%rsp), %rdi
callq 0x140c0
movl %eax, 0x8(%rsp)
movq 0x40(%rsp), %rdi
callq 0x140e0
movl %eax, 0xc(%rsp)
movq 0x40(%rsp), %rdi
callq 0x14100
movl 0x8(%rsp), %esi
movl 0xc(%rsp), %edx
movl %eax, %ecx
leaq 0x120bd1(%rip), %rdi    # 0x13428a
movb $0x0, %al
callq 0xf070
movq 0x40(%rsp), %rdi
callq 0x14120
leaq 0x120bd2(%rip), %rdi    # 0x1342a3
movb $0x1, %al
callq 0xf070
movq 0x40(%rsp), %rdi
callq 0x15920
movl %eax, %esi
leaq 0x120bc8(%rip), %rdi    # 0x1342b3
movb $0x0, %al
callq 0xf070
movq 0x40(%rsp), %rdi
callq 0x14140
leaq 0x120bc4(%rip), %rdi    # 0x1342c7
movb $0x1, %al
callq 0xf070
movq 0x40(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x15720
leaq 0x20(%rsp), %rdi
callq 0x14180
leaq 0x120bac(%rip), %rdi    # 0x1342d6
movb $0x1, %al
callq 0xf070
leaq 0x20(%rsp), %rdi
callq 0x14190
leaq 0x120ba4(%rip), %rdi    # 0x1342e6
movb $0x1, %al
callq 0xf070
movq 0x40(%rsp), %rdi
callq 0x15810
leaq 0x120b9c(%rip), %rdi    # 0x1342f6
movb $0x1, %al
callq 0xf070
movq 0x40(%rsp), %rdi
callq 0x141a0
leaq 0x120b93(%rip), %rdi    # 0x134305
movb $0x1, %al
callq 0xf070
movq 0x15c810(%rip), %rax    # 0x16ff90
movq (%rax), %rdi
callq 0xf5d0
movq 0x40(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
addq $0x68, %rsp
retq
movq 0x38(%rsp), %rdi
callq 0xf890
nopw %cs:(%rax,%rax)