// File: /workspace/github_cpp_makefile_star2_O3/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 0x82f30
movq %rbp, %rdi
callq 0x8674c
leaq 0x12cee8(%rip), %rax    # 0x1550b8
movsd (%rax), %xmm0
leaq 0x1a8(%rsp), %rdi
movsd 0xc3e8c(%rip), %xmm2    # 0xec070
xorps %xmm1, %xmm1
callq 0x84aea
leaq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x82f30
leaq 0x8(%rsp), %rdi
movsd 0xc3e7a(%rip), %xmm1    # 0xec080
xorps %xmm0, %xmm0
callq 0x86da4
leaq 0x8(%rsp), %rdi
callq 0x8674c
leaq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x86fa2
leaq 0x8(%rsp), %rdi
movsd 0xc3e56(%rip), %xmm0    # 0xec088
movsd 0xc3e36(%rip), %xmm2    # 0xec070
xorps %xmm1, %xmm1
callq 0x84aea
leaq 0x8(%rsp), %rdi
movsd 0xc3e31(%rip), %xmm0    # 0xec080
xorps %xmm1, %xmm1
callq 0x86da4
movl 0x12c743(%rip), %esi    # 0x1549a0
movl 0x12c741(%rip), %edx    # 0x1549a4
leaq 0xd8(%rsp), %rdi
callq 0x824d4
leaq 0x4e8(%rsp), %rdi
movq %r12, %rsi
callq 0x82f30
leaq 0x4e8(%rsp), %rdi
callq 0x8674c
leaq 0x418(%rsp), %rdi
movq %r15, %rsi
callq 0x82f30
leaq 0x418(%rsp), %rdi
callq 0x8674c
leaq 0x348(%rsp), %rdi
movq %r14, %rsi
callq 0x82f30
leaq 0x348(%rsp), %rdi
callq 0x8674c
leaq 0xd8(%rsp), %rdi
leaq 0x4e8(%rsp), %rsi
callq 0x86e10
leaq 0xd8(%rsp), %rdi
leaq 0x418(%rsp), %rsi
callq 0x86e10
leaq 0xd8(%rsp), %rdi
leaq 0x348(%rsp), %rsi
callq 0x86e10
leaq 0xd8(%rsp), %rdi
movsd 0xc3d5a(%rip), %xmm0    # 0xec070
xorps %xmm1, %xmm1
movaps %xmm0, %xmm2
callq 0x84aea
leaq 0x278(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x82f30
leaq 0x278(%rsp), %rdi
movsd 0xc3ced(%rip), %xmm0    # 0xec030
movsd 0xc3d25(%rip), %xmm1    # 0xec070
xorps %xmm2, %xmm2
callq 0x84aea
leaq 0xd8(%rsp), %rdi
leaq 0x278(%rsp), %rsi
callq 0x8709c
movl 0x12c632(%rip), %esi    # 0x1549a0
movl 0x12c630(%rip), %edx    # 0x1549a4
leaq 0x5b8(%rsp), %rdi
callq 0x824d4
leaq 0x5b8(%rsp), %rsi
movq %rbx, %rdi
callq 0x82e46
leaq 0x5b8(%rsp), %rdi
callq 0x83108
leaq 0x1a8(%rsp), %rdi
movsd 0xc3c8a(%rip), %xmm0    # 0xec038
callq 0x86f08
leaq 0x1a8(%rsp), %rsi
movq %rbx, %rdi
callq 0x86e10
leaq 0x8(%rsp), %rdi
movsd 0xc3cc0(%rip), %xmm0    # 0xec090
callq 0x86f08
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x86e10
leaq 0xd8(%rsp), %rdi
movsd 0xc3ca6(%rip), %xmm0    # 0xec098
callq 0x86f08
leaq 0xd8(%rsp), %rsi
movq %rbx, %rdi
callq 0x86e10
leaq 0x278(%rsp), %rdi
callq 0x83108
leaq 0x348(%rsp), %rdi
callq 0x83108
leaq 0x418(%rsp), %rdi
callq 0x83108
leaq 0x4e8(%rsp), %rdi
callq 0x83108
leaq 0xd8(%rsp), %rdi
callq 0x83108
leaq 0x8(%rsp), %rdi
callq 0x83108
leaq 0x1a8(%rsp), %rdi
callq 0x83108
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 0x83108
jmp 0x284b0
jmp 0x284ad
jmp 0x284a3
jmp 0x28489
movq %rax, %rbx
jmp 0x284ca
jmp 0x28490
movq %rax, %rbx
jmp 0x284d7
movq %rax, %rbx
jmp 0x284e4
jmp 0x284a8
jmp 0x2849e
movq %rax, %rbx
jmp 0x284fb
movq %rax, %rbx
jmp 0x284bd
movq %rax, %rbx
jmp 0x284f1
movq %rax, %rbx
leaq 0x278(%rsp), %rdi
callq 0x83108
leaq 0x348(%rsp), %rdi
callq 0x83108
leaq 0x418(%rsp), %rdi
callq 0x83108
leaq 0x4e8(%rsp), %rdi
callq 0x83108
leaq 0xd8(%rsp), %rdi
callq 0x83108
leaq 0x8(%rsp), %rdi
callq 0x83108
leaq 0x1a8(%rsp), %rdi
callq 0x83108
movq %rbx, %rdi
callq 0x230a0