// File: /workspace/github_cpp_makefile_star2_O1/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 0x84054
movq %rbp, %rdi
callq 0x878de
leaq 0x12eef8(%rip), %rax    # 0x1570c8
movsd (%rax), %xmm0
leaq 0x1a8(%rsp), %rdi
movsd 0xc5e8c(%rip), %xmm2    # 0xee070
xorps %xmm1, %xmm1
callq 0x85c40
leaq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x84054
leaq 0x8(%rsp), %rdi
movsd 0xc5e7a(%rip), %xmm1    # 0xee080
xorps %xmm0, %xmm0
callq 0x87f8e
leaq 0x8(%rsp), %rdi
callq 0x878de
leaq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x8818c
leaq 0x8(%rsp), %rdi
movsd 0xc5e56(%rip), %xmm0    # 0xee088
movsd 0xc5e36(%rip), %xmm2    # 0xee070
xorps %xmm1, %xmm1
callq 0x85c40
leaq 0x8(%rsp), %rdi
movsd 0xc5e31(%rip), %xmm0    # 0xee080
xorps %xmm1, %xmm1
callq 0x87f8e
movl 0x12e753(%rip), %esi    # 0x1569b0
movl 0x12e751(%rip), %edx    # 0x1569b4
leaq 0xd8(%rsp), %rdi
callq 0x8360c
leaq 0x4e8(%rsp), %rdi
movq %r12, %rsi
callq 0x84054
leaq 0x4e8(%rsp), %rdi
callq 0x878de
leaq 0x418(%rsp), %rdi
movq %r15, %rsi
callq 0x84054
leaq 0x418(%rsp), %rdi
callq 0x878de
leaq 0x348(%rsp), %rdi
movq %r14, %rsi
callq 0x84054
leaq 0x348(%rsp), %rdi
callq 0x878de
leaq 0xd8(%rsp), %rdi
leaq 0x4e8(%rsp), %rsi
callq 0x87ffa
leaq 0xd8(%rsp), %rdi
leaq 0x418(%rsp), %rsi
callq 0x87ffa
leaq 0xd8(%rsp), %rdi
leaq 0x348(%rsp), %rsi
callq 0x87ffa
leaq 0xd8(%rsp), %rdi
movsd 0xc5d5a(%rip), %xmm0    # 0xee070
xorps %xmm1, %xmm1
movaps %xmm0, %xmm2
callq 0x85c40
leaq 0x278(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x84054
leaq 0x278(%rsp), %rdi
movsd 0xc5ced(%rip), %xmm0    # 0xee030
movsd 0xc5d25(%rip), %xmm1    # 0xee070
xorps %xmm2, %xmm2
callq 0x85c40
leaq 0xd8(%rsp), %rdi
leaq 0x278(%rsp), %rsi
callq 0x88284
movl 0x12e642(%rip), %esi    # 0x1569b0
movl 0x12e640(%rip), %edx    # 0x1569b4
leaq 0x5b8(%rsp), %rdi
callq 0x8360c
leaq 0x5b8(%rsp), %rsi
movq %rbx, %rdi
callq 0x83f78
leaq 0x5b8(%rsp), %rdi
callq 0x8422c
leaq 0x1a8(%rsp), %rdi
movsd 0xc5c8a(%rip), %xmm0    # 0xee038
callq 0x880f2
leaq 0x1a8(%rsp), %rsi
movq %rbx, %rdi
callq 0x87ffa
leaq 0x8(%rsp), %rdi
movsd 0xc5cc0(%rip), %xmm0    # 0xee090
callq 0x880f2
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x87ffa
leaq 0xd8(%rsp), %rdi
movsd 0xc5ca6(%rip), %xmm0    # 0xee098
callq 0x880f2
leaq 0xd8(%rsp), %rsi
movq %rbx, %rdi
callq 0x87ffa
leaq 0x278(%rsp), %rdi
callq 0x8422c
leaq 0x348(%rsp), %rdi
callq 0x8422c
leaq 0x418(%rsp), %rdi
callq 0x8422c
leaq 0x4e8(%rsp), %rdi
callq 0x8422c
leaq 0xd8(%rsp), %rdi
callq 0x8422c
leaq 0x8(%rsp), %rdi
callq 0x8422c
leaq 0x1a8(%rsp), %rdi
callq 0x8422c
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 0x8422c
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 0x8422c
leaq 0x348(%rsp), %rdi
callq 0x8422c
leaq 0x418(%rsp), %rdi
callq 0x8422c
leaq 0x4e8(%rsp), %rdi
callq 0x8422c
leaq 0xd8(%rsp), %rdi
callq 0x8422c
leaq 0x8(%rsp), %rdi
callq 0x8422c
leaq 0x1a8(%rsp), %rdi
callq 0x8422c
movq %rbx, %rdi
callq 0x230b0