// File: /workspace/github_cpp_makefile_star2_O1/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 0x142b17(%rip), %rdi    # 0x16d948
leaq 0x1461b8(%rip), %rsi    # 0x170ff0
callq 0x88db4
movl %eax, %ecx
movl $0x1, %eax
testl %ecx, %ecx
jne 0x2af98
leaq 0x38(%rbx), %r14
leaq 0x1460a9(%rip), %rdx    # 0x170f00
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x876e6
leaq 0x142ada(%rip), %rsi    # 0x16d948
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r15, %rdx
callq 0x88f50
leaq 0xd4e73(%rip), %rdx     # 0xffcf8
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x8766e
movq %r12, %rdi
movq %r15, %rsi
callq 0x89a1e
leaq 0x13e281(%rip), %rax    # 0x169128
movsd (%rax), %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
jae 0x2af98
movsd %xmm0, (%rsp)
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0xa25d4
movq (%rbx), %rax
leaq 0x142a75(%rip), %rsi    # 0x16d948
movq %rbx, %rdi
movq %r14, %rdx
callq *0xb0(%rax)
testl %eax, %eax
je 0x2af87
cmpl $0x4, 0x24(%rbx)
jl 0x2af93
movq 0x18(%rbx), %rax
cmpq $0x0, 0x18(%rax)
je 0x2af93
movsd 0xd1110(%rip), %xmm0    # 0xfc018
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %esi
testl %esi, %esi
js 0x2af8b
addsd 0x10(%rsp), %xmm0
cvttsd2si %xmm0, %edx
cmpl %esi, 0x28(%rbx)
setl %al
testl %edx, %edx
sets %dil
xorl %ecx, %ecx
orb %al, %dil
movl $0x0, %eax
jne 0x2af8f
xorl %ecx, %ecx
cmpl %edx, 0x2c(%rbx)
jl 0x2af8f
movq %rbx, %rdi
callq 0x2afb6
xorl %ecx, %ecx
ucomisd 0xd1143(%rip), %xmm0    # 0xfc098
movl $0x1, %eax
jne 0x2af5e
jnp 0x2af8f
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2af6a
jnp 0x2af8f
movsd 0xd10e6(%rip), %xmm1    # 0xfc058
movsd (%rsp), %xmm2
mulsd %xmm2, %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
jbe 0x2afa4
xorl %ecx, %ecx
jmp 0x2af8f
xorl %eax, %eax
jmp 0x2af98
xorl %ecx, %ecx
xorl %eax, %eax
testb %cl, %cl
je 0x2af98
movl $0x1, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
mulsd 0xd10a4(%rip), %xmm2    # 0xfc050
ucomisd %xmm2, %xmm0
setbe %cl
jmp 0x2af8f
nop