// File: tomfunkhouser[P]gaps/apps/grd2pts/grd2pts.cpp
// Function: CreateGrid(gaps::RNArray<gaps::R3Grid*> const&, double)
static R3Grid *
CreateGrid(const RNArray<R3Grid *>& grids, RNLength sigma)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();

  // Build a single grid representing all grids
  R3Grid *grid = new R3Grid(*(grids[0]));
  for (int i = 1; i < grids.NEntries(); i++) grid->Add(*(grids[i]));

  // Blur grid
  RNScalar grid_sigma = sigma * grid->WorldToGridScaleFactor();
  if (grid_sigma > 0) grid->Blur(grid_sigma);

  // Print statistics
  if (print_verbose) {
    printf("Created combined 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());
    printf("  Sigma = %g\n", sigma);
    fflush(stdout);
  }

  // Return grid
  return grid;
}

// Assembly:
subq $0x168, %rsp            # imm = 0x168
movq %rdi, 0x160(%rsp)
movsd %xmm0, 0x158(%rsp)
leaq 0x148(%rsp), %rdi
movq %rdi, 0xc8(%rsp)
callq 0xd1830
movq 0xc8(%rsp), %rdi
callq 0x13fe0
movl $0x250, %edi            # imm = 0x250
callq 0xf4c0
movq %rax, 0xd0(%rsp)
movq 0x160(%rsp), %rdi
xorl %esi, %esi
callq 0x142a0
movq %rax, 0xd8(%rsp)
jmp 0x12ed5
movq 0xd8(%rsp), %rsi
movq 0xd0(%rsp), %rdi
callq 0x25010
jmp 0x12eec
movq 0xd0(%rsp), %rax
movq %rax, 0x140(%rsp)
movl $0x1, 0x130(%rsp)
movl 0x130(%rsp), %eax
movl %eax, 0xc4(%rsp)
movq 0x160(%rsp), %rdi
callq 0x14000
movl %eax, %ecx
movl 0xc4(%rsp), %eax
cmpl %ecx, %eax
jge 0x12fa1
movq 0x140(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0x160(%rsp), %rdi
movl 0x130(%rsp), %esi
callq 0x142a0
movq 0xb8(%rsp), %rdi
movq %rax, %rsi
callq 0x2af90
movl 0x130(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x130(%rsp)
jmp 0x12f07
movq 0xd0(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
movl $0x250, %esi            # imm = 0x250
callq 0xf4d0
jmp 0x1338f
movsd 0x158(%rsp), %xmm0
movsd %xmm0, 0xb0(%rsp)
movq 0x140(%rsp), %rdi
callq 0x142c0
movaps %xmm0, %xmm1
movsd 0xb0(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x128(%rsp)
movsd 0x128(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x13001
movq 0x140(%rsp), %rdi
movsd 0x128(%rsp), %xmm0
callq 0x281d0
cmpl $0x0, 0x166554(%rip)    # 0x17955c
je 0x1337f
leaq 0x121209(%rip), %rdi    # 0x13421e
xorl %eax, %eax
movl %eax, 0xa4(%rsp)
movb %al, 0x97(%rsp)
callq 0xf070
leaq 0x148(%rsp), %rdi
callq 0xd18f0
leaq 0x121046(%rip), %rdi    # 0x134084
movb $0x1, %al
callq 0xf070
movq 0x140(%rsp), %rdi
callq 0x14220
movl %eax, 0x8c(%rsp)
movq 0x140(%rsp), %rdi
callq 0x14240
movl %eax, 0x90(%rsp)
movq 0x140(%rsp), %rdi
callq 0x14260
movl 0x8c(%rsp), %esi
movl 0x90(%rsp), %edx
movl %eax, %ecx
movb 0x97(%rsp), %al
leaq 0x1211a1(%rip), %rdi    # 0x134239
callq 0xf070
movq 0x140(%rsp), %rsi
leaq 0xf0(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x142e0
movq 0x98(%rsp), %rdi
movl 0xa4(%rsp), %esi
callq 0x143a0
movq %rax, 0xa8(%rsp)
jmp 0x130d8
movq 0xa8(%rsp), %rdi
xorl %esi, %esi
callq 0x143e0
movsd %xmm0, 0x80(%rsp)
jmp 0x130f2
leaq 0xf0(%rsp), %rdi
xorl %esi, %esi
callq 0x143a0
movq %rax, 0x78(%rsp)
jmp 0x13108
movq 0x78(%rsp), %rdi
movl $0x1, %esi
callq 0x143e0
movsd %xmm0, 0x70(%rsp)
jmp 0x1311f
leaq 0xf0(%rsp), %rdi
xorl %esi, %esi
callq 0x143a0
movq %rax, 0x68(%rsp)
jmp 0x13135
movq 0x68(%rsp), %rdi
movl $0x2, %esi
callq 0x143e0
movsd %xmm0, 0x60(%rsp)
jmp 0x1314c
leaq 0xf0(%rsp), %rdi
movl $0x1, %esi
callq 0x143a0
movq %rax, 0x58(%rsp)
jmp 0x13165
movq 0x58(%rsp), %rdi
xorl %esi, %esi
callq 0x143e0
movsd %xmm0, 0x50(%rsp)
jmp 0x13179
leaq 0xf0(%rsp), %rdi
movl $0x1, %esi
callq 0x143a0
movq %rax, 0x48(%rsp)
jmp 0x13192
movq 0x48(%rsp), %rdi
movl $0x1, %esi
callq 0x143e0
movsd %xmm0, 0x40(%rsp)
jmp 0x131a9
leaq 0xf0(%rsp), %rdi
movl $0x1, %esi
callq 0x143a0
movq %rax, 0x38(%rsp)
jmp 0x131c2
movq 0x38(%rsp), %rdi
movl $0x2, %esi
callq 0x143e0
movsd %xmm0, 0x30(%rsp)
jmp 0x131d9
movsd 0x30(%rsp), %xmm5
movsd 0x40(%rsp), %xmm4
movsd 0x50(%rsp), %xmm3
movsd 0x60(%rsp), %xmm2
movsd 0x70(%rsp), %xmm1
movsd 0x80(%rsp), %xmm0
leaq 0x12104b(%rip), %rdi    # 0x134252
movb $0x6, %al
callq 0xf070
jmp 0x13210
movq 0x140(%rsp), %rdi
callq 0x14400
movsd %xmm0, 0x28(%rsp)
jmp 0x13225
movsd 0x28(%rsp), %xmm0
leaq 0x121049(%rip), %rdi    # 0x13427b
movb $0x1, %al
callq 0xf070
jmp 0x1323b
movq 0x140(%rsp), %rdi
callq 0x25510
movl %eax, 0x24(%rsp)
jmp 0x1324e
movl 0x24(%rsp), %esi
leaq 0x121032(%rip), %rdi    # 0x13428b
xorl %eax, %eax
callq 0xf070
jmp 0x13262
movq 0x140(%rsp), %rdi
callq 0x14420
movsd %xmm0, 0x18(%rsp)
jmp 0x13277
movsd 0x18(%rsp), %xmm0
leaq 0x12101b(%rip), %rdi    # 0x13429f
movb $0x1, %al
callq 0xf070
jmp 0x1328d
movq 0x140(%rsp), %rsi
leaq 0xe0(%rsp), %rdi
callq 0x25310
jmp 0x132a4
leaq 0xe0(%rsp), %rdi
callq 0x14460
movsd %xmm0, 0x10(%rsp)
jmp 0x132b9
movsd 0x10(%rsp), %xmm0
leaq 0x120fe8(%rip), %rdi    # 0x1342ae
movb $0x1, %al
callq 0xf070
jmp 0x132cf
leaq 0xe0(%rsp), %rdi
callq 0x14470
movsd %xmm0, 0x8(%rsp)
jmp 0x132e4
movsd 0x8(%rsp), %xmm0
leaq 0x120fcd(%rip), %rdi    # 0x1342be
movb $0x1, %al
callq 0xf070
jmp 0x132fa
movq 0x140(%rsp), %rdi
callq 0x25400
movsd %xmm0, (%rsp)
jmp 0x1330e
movsd (%rsp), %xmm0
leaq 0x120fb4(%rip), %rdi    # 0x1342ce
movb $0x1, %al
callq 0xf070
jmp 0x13323
movsd 0x158(%rsp), %xmm0
leaq 0x120faa(%rip), %rdi    # 0x1342dd
movb $0x1, %al
callq 0xf070
jmp 0x1333c
movq 0x15cc4d(%rip), %rax    # 0x16ff90
movq (%rax), %rdi
callq 0xf5d0
jmp 0x1334d
leaq 0xf0(%rsp), %rdi
callq 0x14480
jmp 0x1337f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x14480
jmp 0x1338f
movq 0x140(%rsp), %rax
addq $0x168, %rsp            # imm = 0x168
retq
movq 0x138(%rsp), %rdi
callq 0xf890
nopl (%rax)