// File: tomfunkhouser[P]gaps/apps/msh2prp/msh2prp.cpp
// Function: ComputeBoundaryProperties(gaps::R3Mesh*)
static R3MeshPropertySet *
ComputeBoundaryProperties(R3Mesh *mesh)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();
  if (print_verbose) {
    printf("Computing boundary properties ...\n");
    fflush(stdout);
  }

  // Allocate property set
  R3MeshPropertySet *properties = new R3MeshPropertySet(mesh);
  if (!properties) {
    RNFail("Unable to allocate property set.\n");
    return NULL;
  }

  // Create array of boundary vertices
  RNArray<R3MeshVertex *> boundary_vertices;
  for (int i = 0; i < mesh->NVertices(); i++) {
    R3MeshVertex *vertex = mesh->Vertex(i);
    if (!mesh->IsVertexOnBoundary(vertex)) continue;
    boundary_vertices.Insert(vertex);
  }

  // Compute dijkstra distances to closest boundary vertex
  RNScalar *distances = mesh->DijkstraDistances(boundary_vertices);
  if (!distances) return 0;

  // Fill property
  R3MeshProperty *property = new R3MeshProperty(mesh, "BoundaryDijkstraDistance");
  for (int i = 0; i < mesh->NVertices(); i++) {
    R3MeshVertex *vertex = mesh->Vertex(i);
    if (mesh->VertexValence(vertex) == 0) continue;
    property->SetVertexValue(i, distances[i]);
  }

  // Insert property
  InsertProperty(properties, property);

  // Delete distances
  delete [] distances;

  // Print statistics
  if (print_verbose) {
    printf("  Time = %.2f seconds\n", start_time.Elapsed());
    printf("  # Properties = %d\n", properties->NProperties());
    fflush(stdout);
  }

  // Return property set
  return properties;
}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0xc8(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0xe98e0
leaq 0xb8(%rsp), %rdi
callq 0x1f280
cmpl $0x0, 0x1b1060(%rip)    # 0x1ca740
je 0x196ff
leaq 0x15ad73(%rip), %rdi    # 0x17445c
movb $0x0, %al
callq 0x11090
movq 0x1a7899(%rip), %rax    # 0x1c0f90
movq (%rax), %rdi
callq 0x117f0
movl $0x18, %edi
callq 0x11680
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x50(%rsp)
movq 0xc8(%rsp), %rsi
callq 0x24ce0
jmp 0x19723
movq 0x50(%rsp), %rax
movq %rax, 0xb0(%rsp)
cmpq $0x0, 0xb0(%rsp)
jne 0x19782
leaq 0x15ab14(%rip), %rdi    # 0x174256
movb $0x0, %al
callq 0xedb00
movq $0x0, 0xd0(%rsp)
jmp 0x19a67
movq 0x50(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
movl $0x18, %esi
callq 0x11690
jmp 0x19a77
leaq 0x90(%rsp), %rdi
callq 0x1ff00
movl $0x0, 0x8c(%rsp)
movl 0x8c(%rsp), %eax
movl %eax, 0x4c(%rsp)
movq 0xc8(%rsp), %rdi
callq 0x1f2e0
movl %eax, %ecx
movl 0x4c(%rsp), %eax
cmpl %ecx, %eax
jge 0x19856
movq 0xc8(%rsp), %rdi
movl 0x8c(%rsp), %esi
callq 0x1f380
movq %rax, 0x40(%rsp)
jmp 0x197db
movq 0x40(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0xc8(%rsp), %rdi
movq 0x80(%rsp), %rsi
callq 0x327b0
movl %eax, 0x3c(%rsp)
jmp 0x19803
movl 0x3c(%rsp), %eax
cmpl $0x0, %eax
jne 0x19827
jmp 0x19840
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
jmp 0x19a58
movq 0x80(%rsp), %rsi
leaq 0x90(%rsp), %rdi
callq 0x1ff10
jmp 0x1983e
jmp 0x19840
movl 0x8c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8c(%rsp)
jmp 0x1979a
movq 0xc8(%rsp), %rdi
xorl %eax, %eax
movl %eax, %edx
leaq 0x90(%rsp), %rsi
xorps %xmm0, %xmm0
callq 0x42820
movq %rax, 0x30(%rsp)
jmp 0x19879
movq 0x30(%rsp), %rax
movq %rax, 0x78(%rsp)
cmpq $0x0, 0x78(%rsp)
jne 0x198a4
movq $0x0, 0xd0(%rsp)
movl $0x1, 0x74(%rsp)
jmp 0x19a49
movl $0x448, %edi            # imm = 0x448
callq 0x11680
movq %rax, 0x28(%rsp)
jmp 0x198b5
movq 0x28(%rsp), %rdi
movq 0xc8(%rsp), %rsi
leaq 0x15abb6(%rip), %rdx    # 0x17447f
xorl %eax, %eax
movl %eax, %ecx
callq 0x27ef0
jmp 0x198d4
movq 0x28(%rsp), %rax
movq %rax, 0x68(%rsp)
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
movl %eax, 0x24(%rsp)
movq 0xc8(%rsp), %rdi
callq 0x1f2e0
movl %eax, %ecx
movl 0x24(%rsp), %eax
cmpl %ecx, %eax
jge 0x1999b
movq 0xc8(%rsp), %rdi
movl 0x64(%rsp), %esi
callq 0x1f380
movq %rax, 0x18(%rsp)
jmp 0x19921
movq 0x18(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0xc8(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x1f3d0
cmpl $0x0, %eax
jne 0x1996c
jmp 0x1998b
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
movl $0x448, %esi            # imm = 0x448
callq 0x11690
jmp 0x19a58
movq 0x68(%rsp), %rdi
movslq 0x64(%rsp), %rcx
movl %ecx, %esi
movq 0x78(%rsp), %rax
movsd (%rax,%rcx,8), %xmm0
callq 0x2ae50
jmp 0x19989
jmp 0x1998b
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x198e6
movq 0xb0(%rsp), %rdi
movq 0x68(%rsp), %rsi
xorl %edx, %edx
callq 0x148a0
jmp 0x199b1
movq 0x78(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x199cb
movq 0x10(%rsp), %rdi
callq 0x118b0
cmpl $0x0, 0x1b0d6e(%rip)    # 0x1ca740
je 0x19a31
leaq 0xb8(%rsp), %rdi
callq 0xe99a0
movsd %xmm0, 0x8(%rsp)
jmp 0x199e9
movsd 0x8(%rsp), %xmm0
leaq 0x15a816(%rip), %rdi    # 0x17420c
movb $0x1, %al
callq 0x11090
jmp 0x199ff
movq 0xb0(%rsp), %rdi
callq 0x1f400
movl %eax, %esi
leaq 0x15a8a2(%rip), %rdi    # 0x1742b7
xorl %eax, %eax
callq 0x11090
jmp 0x19a1e
movq 0x1a756b(%rip), %rax    # 0x1c0f90
movq (%rax), %rdi
callq 0x117f0
jmp 0x19a2f
jmp 0x19a31
movq 0xb0(%rsp), %rax
movq %rax, 0xd0(%rsp)
movl $0x1, 0x74(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x1ff40
jmp 0x19a67
leaq 0x90(%rsp), %rdi
callq 0x1ff40
jmp 0x19a77
movq 0xd0(%rsp), %rax
addq $0xd8, %rsp
retq
movq 0xa8(%rsp), %rdi
callq 0x11bb0
nopw %cs:(%rax,%rax)