// File: tomfunkhouser[P]gaps/apps/msh2df/msh2df.cpp
// Function: TruncateDistance(gaps::R3Grid*, double)
static int
TruncateDistance(R3Grid *grid, RNLength truncation_distance)
{
  // Check truncation distance
  if (truncation_distance >= RN_INFINITY) return 1;

  // Start statistics
  RNTime start_time;
  start_time.Read();

  // Truncate distances
  grid->Threshold(-truncation_distance, -truncation_distance, R3_GRID_KEEP_VALUE);
  grid->Threshold(truncation_distance, R3_GRID_KEEP_VALUE, truncation_distance);

  // Print statistics
  if (print_verbose) {
    printf("Truncated distances ...\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());
    printf("  Threshold = %g\n", truncation_distance);
    fflush(stdout);
  }

  // Return success
  return 1;
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movsd %xmm0, 0x30(%rsp)
movsd 0x30(%rsp), %xmm0
leaq 0x170964(%rip), %rax    # 0x186500
ucomisd (%rax), %xmm0
jb 0x15baf
movl $0x1, 0x44(%rsp)
jmp 0x15d90
leaq 0x20(%rsp), %rdi
callq 0xddf30
leaq 0x20(%rsp), %rdi
callq 0x17860
movq 0x38(%rsp), %rdi
movsd 0x30(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0x30(%rsp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
leaq 0x12b767(%rip), %rax    # 0x141370
movss (%rax), %xmm2
cvtss2sd %xmm2, %xmm2
callq 0x7dd80
movq 0x38(%rsp), %rdi
movsd 0x30(%rsp), %xmm0
leaq 0x12b748(%rip), %rax    # 0x141370
movss (%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x30(%rsp), %xmm2
callq 0x7dd80
cmpl $0x0, 0x1709b6(%rip)    # 0x1865f8
je 0x15d88
leaq 0x12a8b9(%rip), %rdi    # 0x140508
movb $0x0, %al
callq 0xf070
leaq 0x20(%rsp), %rdi
callq 0xddff0
leaq 0x12a5bc(%rip), %rdi    # 0x140223
movb $0x1, %al
callq 0xf070
movq 0x38(%rsp), %rdi
callq 0x17b40
movl %eax, 0x8(%rsp)
movq 0x38(%rsp), %rdi
callq 0x17b60
movl %eax, 0xc(%rsp)
movq 0x38(%rsp), %rdi
callq 0x17b80
movl 0x8(%rsp), %esi
movl 0xc(%rsp), %edx
movl %eax, %ecx
leaq 0x12a5eb(%rip), %rdi    # 0x140290
movb $0x0, %al
callq 0xf070
movq 0x38(%rsp), %rdi
callq 0x17b20
leaq 0x12a5ec(%rip), %rdi    # 0x1402a9
movb $0x1, %al
callq 0xf070
movq 0x38(%rsp), %rdi
callq 0x7b1f0
movl %eax, %esi
leaq 0x12a5e2(%rip), %rdi    # 0x1402b9
movb $0x0, %al
callq 0xf070
movq 0x38(%rsp), %rdi
callq 0x17ba0
leaq 0x12a5de(%rip), %rdi    # 0x1402cd
movb $0x1, %al
callq 0xf070
movq 0x38(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x7aff0
leaq 0x10(%rsp), %rdi
callq 0x17be0
leaq 0x12a5c6(%rip), %rdi    # 0x1402dc
movb $0x1, %al
callq 0xf070
leaq 0x10(%rsp), %rdi
callq 0x17bf0
leaq 0x12a5be(%rip), %rdi    # 0x1402ec
movb $0x1, %al
callq 0xf070
movq 0x38(%rsp), %rdi
callq 0x7b0e0
leaq 0x12a5b6(%rip), %rdi    # 0x1402fc
movb $0x1, %al
callq 0xf070
movq 0x38(%rsp), %rdi
callq 0x17c00
leaq 0x12a5ad(%rip), %rdi    # 0x14030b
movb $0x1, %al
callq 0xf070
movsd 0x30(%rsp), %xmm0
leaq 0x12a7af(%rip), %rdi    # 0x140521
movb $0x1, %al
callq 0xf070
movq 0x167210(%rip), %rax    # 0x17cf90
movq (%rax), %rdi
callq 0xf5d0
movl $0x1, 0x44(%rsp)
movl 0x44(%rsp), %eax
addq $0x48, %rsp
retq
nopl (%rax)