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

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

  // Read grid 
  if (!grid->ReadFile(grid_name)) {
    RNFail("Unable to read grid file %s", grid_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());
    const R3Box bbox = grid->WorldBox();
    printf("  World Box = ( %g %g %g ) ( %g %g %g )\n", bbox[0][0], bbox[0][1], bbox[0][2], bbox[1][0], bbox[1][1], bbox[1][2]);
    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());
    fflush(stdout);
  }

  // Return success
  return grid;
}

// Assembly:
subq $0x148, %rsp            # imm = 0x148
movq %rdi, 0x138(%rsp)
leaq 0x128(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
callq 0xd0600
movq 0xb8(%rsp), %rdi
callq 0x13070
movl $0x250, %edi            # imm = 0x250
callq 0xf4c0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0xc0(%rsp)
xorl %ecx, %ecx
movl %ecx, %esi
movl %ecx, %edx
callq 0x54ea0
jmp 0x12766
movq 0xc0(%rsp), %rax
movq %rax, 0x120(%rsp)
cmpq $0x0, 0x120(%rsp)
jne 0x127cb
leaq 0x1208e1(%rip), %rdi    # 0x133069
movb $0x0, %al
callq 0xd4820
movq $0x0, 0x140(%rsp)
jmp 0x12b89
movq 0xc0(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
movl $0x250, %esi            # imm = 0x250
callq 0xf4d0
jmp 0x12b99
movq 0x120(%rsp), %rdi
movq 0x138(%rsp), %rsi
callq 0x62560
cmpl $0x0, %eax
jne 0x1280c
movq 0x138(%rsp), %rsi
leaq 0x12088e(%rip), %rdi    # 0x133082
movb $0x0, %al
callq 0xd4820
movq $0x0, 0x140(%rsp)
jmp 0x12b89
cmpl $0x0, 0x165d65(%rip)    # 0x178578
je 0x12b79
leaq 0x12087e(%rip), %rdi    # 0x13309e
xorl %eax, %eax
movl %eax, 0xac(%rsp)
movb %al, 0x9f(%rsp)
callq 0xf070
leaq 0x128(%rsp), %rdi
callq 0xd06c0
leaq 0x120864(%rip), %rdi    # 0x1330ad
movb $0x1, %al
callq 0xf070
movq 0x120(%rsp), %rdi
callq 0x13090
movl %eax, 0x94(%rsp)
movq 0x120(%rsp), %rdi
callq 0x130b0
movl %eax, 0x98(%rsp)
movq 0x120(%rsp), %rdi
callq 0x130d0
movl 0x94(%rsp), %esi
movl 0x98(%rsp), %edx
movl %eax, %ecx
movb 0x9f(%rsp), %al
leaq 0x120821(%rip), %rdi    # 0x1330c4
callq 0xf070
movq 0x120(%rsp), %rsi
leaq 0xd8(%rsp), %rdi
movq %rdi, 0xa0(%rsp)
callq 0x130f0
movq 0xa0(%rsp), %rdi
movl 0xac(%rsp), %esi
callq 0x131b0
movq %rax, 0xb0(%rsp)
jmp 0x128e3
movq 0xb0(%rsp), %rdi
xorl %esi, %esi
callq 0x131f0
movsd %xmm0, 0x88(%rsp)
jmp 0x128fd
leaq 0xd8(%rsp), %rdi
xorl %esi, %esi
callq 0x131b0
movq %rax, 0x80(%rsp)
jmp 0x12916
movq 0x80(%rsp), %rdi
movl $0x1, %esi
callq 0x131f0
movsd %xmm0, 0x78(%rsp)
jmp 0x12930
leaq 0xd8(%rsp), %rdi
xorl %esi, %esi
callq 0x131b0
movq %rax, 0x70(%rsp)
jmp 0x12946
movq 0x70(%rsp), %rdi
movl $0x2, %esi
callq 0x131f0
movsd %xmm0, 0x68(%rsp)
jmp 0x1295d
leaq 0xd8(%rsp), %rdi
movl $0x1, %esi
callq 0x131b0
movq %rax, 0x60(%rsp)
jmp 0x12976
movq 0x60(%rsp), %rdi
xorl %esi, %esi
callq 0x131f0
movsd %xmm0, 0x58(%rsp)
jmp 0x1298a
leaq 0xd8(%rsp), %rdi
movl $0x1, %esi
callq 0x131b0
movq %rax, 0x50(%rsp)
jmp 0x129a3
movq 0x50(%rsp), %rdi
movl $0x1, %esi
callq 0x131f0
movsd %xmm0, 0x48(%rsp)
jmp 0x129ba
leaq 0xd8(%rsp), %rdi
movl $0x1, %esi
callq 0x131b0
movq %rax, 0x40(%rsp)
jmp 0x129d3
movq 0x40(%rsp), %rdi
movl $0x2, %esi
callq 0x131f0
movsd %xmm0, 0x38(%rsp)
jmp 0x129ea
movsd 0x38(%rsp), %xmm5
movsd 0x48(%rsp), %xmm4
movsd 0x58(%rsp), %xmm3
movsd 0x68(%rsp), %xmm2
movsd 0x78(%rsp), %xmm1
movsd 0x88(%rsp), %xmm0
leaq 0x1206c5(%rip), %rdi    # 0x1330dd
movb $0x6, %al
callq 0xf070
jmp 0x12a21
movq 0x120(%rsp), %rdi
callq 0x13210
movsd %xmm0, 0x30(%rsp)
jmp 0x12a36
movsd 0x30(%rsp), %xmm0
leaq 0x1206c3(%rip), %rdi    # 0x133106
movb $0x1, %al
callq 0xf070
jmp 0x12a4c
movq 0x120(%rsp), %rdi
callq 0x565e0
movl %eax, 0x2c(%rsp)
jmp 0x12a5f
movl 0x2c(%rsp), %esi
leaq 0x1206ac(%rip), %rdi    # 0x133116
xorl %eax, %eax
callq 0xf070
jmp 0x12a73
movq 0x120(%rsp), %rdi
callq 0x13230
movsd %xmm0, 0x20(%rsp)
jmp 0x12a88
movsd 0x20(%rsp), %xmm0
leaq 0x120695(%rip), %rdi    # 0x13312a
movb $0x1, %al
callq 0xf070
jmp 0x12a9e
movq 0x120(%rsp), %rsi
leaq 0xc8(%rsp), %rdi
callq 0x563e0
jmp 0x12ab5
leaq 0xc8(%rsp), %rdi
callq 0x13270
movsd %xmm0, 0x18(%rsp)
jmp 0x12aca
movsd 0x18(%rsp), %xmm0
leaq 0x120662(%rip), %rdi    # 0x133139
movb $0x1, %al
callq 0xf070
jmp 0x12ae0
leaq 0xc8(%rsp), %rdi
callq 0x13280
movsd %xmm0, 0x10(%rsp)
jmp 0x12af5
movsd 0x10(%rsp), %xmm0
leaq 0x120647(%rip), %rdi    # 0x133149
movb $0x1, %al
callq 0xf070
jmp 0x12b0b
movq 0x120(%rsp), %rdi
callq 0x564d0
movsd %xmm0, 0x8(%rsp)
jmp 0x12b20
movsd 0x8(%rsp), %xmm0
leaq 0x12062c(%rip), %rdi    # 0x133159
movb $0x1, %al
callq 0xf070
jmp 0x12b36
movq 0x15c453(%rip), %rax    # 0x16ef90
movq (%rax), %rdi
callq 0xf5d0
jmp 0x12b47
leaq 0xd8(%rsp), %rdi
callq 0x13290
jmp 0x12b79
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x13290
jmp 0x12b99
movq 0x120(%rsp), %rax
movq %rax, 0x140(%rsp)
movq 0x140(%rsp), %rax
addq $0x148, %rsp            # imm = 0x148
retq
movq 0x118(%rsp), %rdi
callq 0xf890
nopw %cs:(%rax,%rax)