// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/apps/confview/confview.cpp
// Function: CheckVisibility(gaps::RGBDImage*, gaps::R3Point const&)
static int
CheckVisibility(RGBDImage *image, const R3Point& world_position)
{
  // Check world position
  if (world_position == R3unknown_point) return 1;

  // Get/check point depth
  R3Vector vector = world_position - image->WorldViewpoint();
  RNScalar point_depth = vector.Dot(image->WorldTowards());
  if (RNIsNegativeOrZero(point_depth)) return 0;

  // Get/check projection into image
  R2Point image_position;
  if (!image->TransformWorldToImage(world_position, image_position)) return 0;

  // Get/check image depth channel
  R2Grid *depth_channel = image->DepthChannel();
  if (depth_channel) {
    // Get/check image depth
    int image_ix = image_position.X() + 0.5;
    int image_iy = image_position.Y() + 0.5;
    if ((image_ix < 0) || (image_ix > image->NPixels(RN_X))) return 0;
    if ((image_iy < 0) || (image_iy > image->NPixels(RN_Y))) return 0;
    RNScalar image_depth = image->PixelDepth(image_ix, image_iy);
    if ((image_depth == R2_GRID_UNKNOWN_VALUE) || (image_depth == 0)) return 1;

    // If depth is not within 10% of image depth, then probably not 
    if (image_depth < 0.9 * point_depth) return 0;
    if (image_depth > 1.1 * point_depth) return 0;
  }

  // Passed all tests
  return 1;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
leaq 0x140d7a(%rip), %rdi    # 0x16b948
leaq 0x14441b(%rip), %rsi    # 0x16eff0
callq 0x879dc
movl %eax, %ecx
movl $0x1, %eax
testl %ecx, %ecx
jne 0x2ad29
leaq 0x38(%rbx), %r14
leaq 0x14430c(%rip), %rdx    # 0x16ef00
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x8630e
leaq 0x140d3d(%rip), %rsi    # 0x16b948
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r15, %rdx
callq 0x87b72
leaq 0xd30c6(%rip), %rdx     # 0xfdce8
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x86296
movq %r12, %rdi
movq %r15, %rsi
callq 0x88636
leaq 0x13c4e4(%rip), %rax    # 0x167128
movsd (%rax), %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
jae 0x2ad29
movsd %xmm0, (%rsp)
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0xa1034
movq (%rbx), %rax
leaq 0x140cd8(%rip), %rsi    # 0x16b948
movq %rbx, %rdi
movq %r14, %rdx
callq *0xb0(%rax)
testl %eax, %eax
je 0x2acd1
cmpl $0x4, 0x24(%rbx)
jl 0x2ad24
movq 0x18(%rbx), %rax
cmpq $0x0, 0x18(%rax)
je 0x2ad24
movsd 0xcf377(%rip), %xmm0    # 0xfa018
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %esi
testl %esi, %esi
js 0x2acd1
addsd 0x10(%rsp), %xmm0
cvttsd2si %xmm0, %edx
cmpl %esi, 0x28(%rbx)
setl %al
testl %edx, %edx
sets %cl
orb %al, %cl
jne 0x2acd1
cmpl %edx, 0x2c(%rbx)
jge 0x2acd5
xorl %eax, %eax
jmp 0x2ad29
movq %rbx, %rdi
callq 0x2ad36
ucomisd 0xcf3b3(%rip), %xmm0    # 0xfa098
movl $0x1, %eax
jne 0x2acee
jnp 0x2ad29
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2acfa
jnp 0x2ad29
movsd 0xcf34e(%rip), %xmm1    # 0xfa050
movsd (%rsp), %xmm2
mulsd %xmm2, %xmm1
ucomisd %xmm0, %xmm1
ja 0x2acd1
mulsd 0xcf33f(%rip), %xmm2    # 0xfa058
ucomisd %xmm2, %xmm0
movl $0x0, %eax
ja 0x2ad29
movl $0x1, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop