// File: devernay[P]vlpovutils/occlusionmap.cpp
// Function: vlpov_occlusionmap_stereo(VLPovImage<double> const&, VLPovImage<double> const&, double, VLPovImage<unsigned char>&)
void vlpov_occlusionmap_stereo(const VLPovImage<double> &m1x, const VLPovImage<double> &m2x,
                               double t,
                               VLPovImage<unsigned char> &occ1)
{
    int width1 = m1x.width();
    int height1 = m1x.height();
    int width2 = m2x.width();
    int height2 = m2x.height();
    
    occ1.resize(width1, height1);
    
    for(int y1 = 0; y1 < height1; ++y1) {
        for(int x1 = 0; x1 < width1; ++x1) {
            double x2 = x1 + m1x(x1,y1);
            double y2 = y1;
            
            // check for visibility
            if (x2 < -0.5 || x2 > width2-0.5 ||
                y2 < -0.5 || y2 > height2-0.5) {
                occ1(x1,y1) = 0;
                continue;
            }
            
            double x1b = x2 + m2x.linear_at(x2,y2);
            // check for occlusion
            if (std::abs(x1 - x1b) > t) {
                occ1(x1,y1) = 0;
                continue;
            }
            
            // point is visible
            occ1(x1,y1) = 255;
        }
    }
    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6b10
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6b20
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6b10
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6b20
movl %eax, -0x30(%rbp)
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
callq 0x9f60
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x9f51
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x9f41
cvtsi2sdl -0x38(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movl -0x38(%rbp), %esi
movl -0x34(%rbp), %edx
callq 0x7860
movsd -0x58(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
cvtsi2sdl -0x34(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd 0x8901(%rip), %xmm0     # 0x12768
ucomisd -0x40(%rbp), %xmm0
ja 0x9eb5
movsd -0x40(%rbp), %xmm0
cvtsi2sdl -0x2c(%rbp), %xmm1
movsd 0x88f0(%rip), %xmm2     # 0x12770
subsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
ja 0x9eb5
movsd 0x88d6(%rip), %xmm0     # 0x12768
ucomisd -0x48(%rbp), %xmm0
ja 0x9eb5
movsd -0x48(%rbp), %xmm0
cvtsi2sdl -0x30(%rbp), %xmm1
movsd 0x88c5(%rip), %xmm2     # 0x12770
subsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x9ec9
movq -0x20(%rbp), %rdi
movl -0x38(%rbp), %esi
movl -0x34(%rbp), %edx
callq 0x9ff0
movb $0x0, (%rax)
jmp 0x9f33
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movsd -0x40(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
callq 0xa020
movaps %xmm0, %xmm1
movsd -0x60(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
cvtsi2sdl -0x38(%rbp), %xmm0
subsd -0x50(%rbp), %xmm0
callq 0xa270
ucomisd -0x18(%rbp), %xmm0
jbe 0x9f21
movq -0x20(%rbp), %rdi
movl -0x38(%rbp), %esi
movl -0x34(%rbp), %edx
callq 0x9ff0
movb $0x0, (%rax)
jmp 0x9f33
movq -0x20(%rbp), %rdi
movl -0x38(%rbp), %esi
movl -0x34(%rbp), %edx
callq 0x9ff0
movb $-0x1, (%rax)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x9e22
jmp 0x9f43
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x9e0f
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)