// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/apps/scn2img/scn2img.cpp
// Function: ComputeBoundaryImage(gaps::R2Grid const&, gaps::R2Grid const&, gaps::R2Grid const&, gaps::R2Grid const&, gaps::R2Grid const&, gaps::R2Grid&)
static int
ComputeBoundaryImage(const R2Grid& depth_image, const R2Grid& node_image,
  const R2Grid& xnormal_image, const R2Grid& ynormal_image, const R2Grid& znormal_image,
  R2Grid& result)
{                  
  // Find node boundaries
  R2Grid node_boundaries(node_image);
  node_boundaries.GradientMagnitude();
  node_boundaries.Threshold(RN_EPSILON, 0, 1);

  // Find silhouette boundaries (where depth difference is > 10% of depth)
  R2Grid silhouette_boundaries(depth_image);
  silhouette_boundaries.Substitute(0, R2_GRID_UNKNOWN_VALUE);
  silhouette_boundaries.GradientMagnitude();
  silhouette_boundaries.Divide(depth_image);
  silhouette_boundaries.Threshold(0.1, 0, 1);
  silhouette_boundaries.Substitute(R2_GRID_UNKNOWN_VALUE, 0);

  // Find crease boundaries
  R2Grid crease_boundaries(width, height);
  R2Grid xcrease_boundaries(xnormal_image);
  xcrease_boundaries.GradientMagnitude();
  R2Grid ycrease_boundaries(ynormal_image);
  ycrease_boundaries.GradientMagnitude();
  R2Grid zcrease_boundaries(znormal_image);
  zcrease_boundaries.GradientMagnitude();
  crease_boundaries.Add(xcrease_boundaries);
  crease_boundaries.Add(ycrease_boundaries);
  crease_boundaries.Add(zcrease_boundaries);
  crease_boundaries.Threshold(1, 0, 1);
  R2Grid silhouette_mask(silhouette_boundaries);
  silhouette_mask.Threshold(0.5, 1, 0);
  crease_boundaries.Mask(silhouette_mask);
    
  // Combine boundaries into one image
  result = R2Grid(width, height);
  node_boundaries.Multiply(2);
  result.Add(node_boundaries);
  silhouette_boundaries.Multiply(4);
  result.Add(silhouette_boundaries);
  crease_boundaries.Multiply(8);
  result.Add(crease_boundaries);

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x688, %rsp            # imm = 0x688
movq %r9, %rbx
movq %r8, %r14
movq %rcx, %r15
movq %rdx, %r12
movq %rdi, %r13
leaq 0x1a8(%rsp), %rbp
movq %rbp, %rdi
callq 0x781b8
movq %rbp, %rdi
callq 0x7b5b4
leaq 0x11cc09(%rip), %rax    # 0x1440d8
movsd (%rax), %xmm0
leaq 0x1a8(%rsp), %rdi
movsd 0xadb8d(%rip), %xmm2    # 0xd5070
xorps %xmm1, %xmm1
callq 0x79b94
leaq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x781b8
leaq 0x8(%rsp), %rdi
movsd 0xadb7b(%rip), %xmm1    # 0xd5080
xorps %xmm0, %xmm0
callq 0x7bb6a
leaq 0x8(%rsp), %rdi
callq 0x7b5b4
leaq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x7bd2e
leaq 0x8(%rsp), %rdi
movsd 0xadb57(%rip), %xmm0    # 0xd5088
movsd 0xadb37(%rip), %xmm2    # 0xd5070
xorps %xmm1, %xmm1
callq 0x79b94
leaq 0x8(%rsp), %rdi
movsd 0xadb32(%rip), %xmm0    # 0xd5080
xorps %xmm1, %xmm1
callq 0x7bb6a
movl 0x11c464(%rip), %esi    # 0x1439c0
movl 0x11c462(%rip), %edx    # 0x1439c4
leaq 0xd8(%rsp), %rdi
callq 0x7782c
leaq 0x4e8(%rsp), %rdi
movq %r12, %rsi
callq 0x781b8
leaq 0x4e8(%rsp), %rdi
callq 0x7b5b4
leaq 0x418(%rsp), %rdi
movq %r15, %rsi
callq 0x781b8
leaq 0x418(%rsp), %rdi
callq 0x7b5b4
leaq 0x348(%rsp), %rdi
movq %r14, %rsi
callq 0x781b8
leaq 0x348(%rsp), %rdi
callq 0x7b5b4
leaq 0xd8(%rsp), %rdi
leaq 0x4e8(%rsp), %rsi
callq 0x7bbd6
leaq 0xd8(%rsp), %rdi
leaq 0x418(%rsp), %rsi
callq 0x7bbd6
leaq 0xd8(%rsp), %rdi
leaq 0x348(%rsp), %rsi
callq 0x7bbd6
leaq 0xd8(%rsp), %rdi
movsd 0xada5b(%rip), %xmm0    # 0xd5070
xorps %xmm1, %xmm1
movaps %xmm0, %xmm2
callq 0x79b94
leaq 0x278(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x781b8
leaq 0x278(%rsp), %rdi
movsd 0xad9ee(%rip), %xmm0    # 0xd5030
movsd 0xada26(%rip), %xmm1    # 0xd5070
xorps %xmm2, %xmm2
callq 0x79b94
leaq 0xd8(%rsp), %rdi
leaq 0x278(%rsp), %rsi
callq 0x7be14
movl 0x11c353(%rip), %esi    # 0x1439c0
movl 0x11c351(%rip), %edx    # 0x1439c4
leaq 0x5b8(%rsp), %rdi
callq 0x7782c
leaq 0x5b8(%rsp), %rsi
movq %rbx, %rdi
callq 0x780da
leaq 0x5b8(%rsp), %rdi
callq 0x78370
leaq 0x1a8(%rsp), %rdi
movsd 0xad98b(%rip), %xmm0    # 0xd5038
callq 0x7bc96
leaq 0x1a8(%rsp), %rsi
movq %rbx, %rdi
callq 0x7bbd6
leaq 0x8(%rsp), %rdi
movsd 0xad9c1(%rip), %xmm0    # 0xd5090
callq 0x7bc96
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x7bbd6
leaq 0xd8(%rsp), %rdi
movsd 0xad9a7(%rip), %xmm0    # 0xd5098
callq 0x7bc96
leaq 0xd8(%rsp), %rsi
movq %rbx, %rdi
callq 0x7bbd6
leaq 0x278(%rsp), %rdi
callq 0x78370
leaq 0x348(%rsp), %rdi
callq 0x78370
leaq 0x418(%rsp), %rdi
callq 0x78370
leaq 0x4e8(%rsp), %rdi
callq 0x78370
leaq 0xd8(%rsp), %rdi
callq 0x78370
leaq 0x8(%rsp), %rdi
callq 0x78370
leaq 0x1a8(%rsp), %rdi
callq 0x78370
addq $0x688, %rsp            # imm = 0x688
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x5b8(%rsp), %rdi
callq 0x78370
jmp 0x277af
jmp 0x277ac
jmp 0x277a2
jmp 0x27788
movq %rax, %rbx
jmp 0x277c9
jmp 0x2778f
movq %rax, %rbx
jmp 0x277d6
movq %rax, %rbx
jmp 0x277e3
jmp 0x277a7
jmp 0x2779d
movq %rax, %rbx
jmp 0x277fa
movq %rax, %rbx
jmp 0x277bc
movq %rax, %rbx
jmp 0x277f0
movq %rax, %rbx
leaq 0x278(%rsp), %rdi
callq 0x78370
leaq 0x348(%rsp), %rdi
callq 0x78370
leaq 0x418(%rsp), %rdi
callq 0x78370
leaq 0x4e8(%rsp), %rdi
callq 0x78370
leaq 0xd8(%rsp), %rdi
callq 0x78370
leaq 0x8(%rsp), %rdi
callq 0x78370
leaq 0x1a8(%rsp), %rdi
callq 0x78370
movq %rbx, %rdi
callq 0x230c0