// File: /workspace/github_cpp_makefile_star2_O3/devernay[P]vlpovutils/vlpov_project.cpp
// Function: main
int main(int argc, char *argv[])
{
    if (argc != 2 && argc != 3) {
        fprintf(stderr, USAGE, argv[0]);
        exit(2);
    }
    bool do_motion = (argc == 3);
    const char *frame1 = argv[1];
    const char *frame2 = do_motion ? argv[2] : NULL;
    
    {
        VLPovCamera cam1;
        VLPovCamera cam2;
        int retval;
        
        retval = vlpov_povread(frame1, cam1);
        if(retval != 0) {
            fprintf(stderr,"Error %d while reading %s.txt\n", retval, frame1);
            exit(1);
        }
        
        //cout << "Intrinsic matrix 1(new): " << endl << cam1.K << endl;
        //cout << "Extrinsic 1(new): " << endl << cam1.R << endl << cam1.t << endl;
      
        if (do_motion) {
            retval = vlpov_povread(frame2, cam2);
            if(retval != 0) {
                fprintf(stderr,"Error %d while reading %s.txt\n", retval, frame2);
                exit(1);
            }
        }
        
        vector3 P; // position in the global reference frame
        while(scanf("%lg %lg %lg", &P(0), &P(1), &P(2)) == 3) {
              
            // reconstruct in camera 1 reference frame
            vector3 P1 = prod(cam1.R,P)+cam1.t;
            // project
            vector3 p1 = prod(cam1.K , P1);
            // compute coordinates
            double x1 = p1(0)/p1(2);
            double y1 = p1(1)/p1(2);
            if (!do_motion) {
                printf("%g %g %g\n", x1, y1, P1(2));
            } else {
                // reconstruct in camera 2 reference frame
                vector3 P2 = prod(cam2.R,P)+cam2.t;
                // project
                vector3 p2 = prod(cam2.K , P2);
                // compute coordinates
                double x2 = p2(0)/p2(2);
                double y2 = p2(1)/p2(2);
                printf("%g %g %g %g %g\n", x1, y1, P1(2), x2-x1, y2-y1);
            }
        }
    }
    
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4b8, %rsp            # imm = 0x4B8
movl %edi, %r14d
leal -0x4(%r14), %eax
cmpl $-0x3, %eax
jbe 0x28af
movq 0x8(%rsi), %r15
cmpl $0x3, %r14d
jne 0x248d
movq 0x10(%rsi), %rbx
jmp 0x248f
xorl %ebx, %ebx
movl $0x3, %eax
leaq 0x2e0(%rsp), %rsi
movq %rax, 0x8(%rsi)
movq %rax, 0x28(%rsi)
movq %rax, 0x48(%rsi)
movq %rax, 0x68(%rsi)
movq %rax, 0x88(%rsi)
movq %rax, 0xa8(%rsi)
movq %rax, 0xc8(%rsi)
movq %rax, 0xf8(%rsi)
movq %rax, 0x100(%rsi)
movl $0x9, %ecx
movq %rcx, 0x108(%rsi)
movq %rax, 0x158(%rsi)
movq %rax, 0x160(%rsi)
movq %rcx, 0x168(%rsi)
movq %rax, 0x1b8(%rsi)
movq %rax, 0xd0(%rsp)
movq %rax, 0xf0(%rsp)
movq %rax, 0x110(%rsp)
movq %rax, 0x130(%rsp)
movq %rax, 0x150(%rsp)
movq %rax, 0x170(%rsp)
movq %rax, 0x190(%rsp)
movq %rax, 0x1c0(%rsp)
movq %rax, 0x1c8(%rsp)
movq %rcx, 0x1d0(%rsp)
movq %rax, 0x220(%rsp)
movq %rax, 0x228(%rsp)
movq %rcx, 0x230(%rsp)
movq %rax, 0x280(%rsp)
movq %r15, %rdi
movq %rsi, %r13
callq 0x360c
testl %eax, %eax
jne 0x28b7
cmpl $0x3, %r14d
jne 0x2598
leaq 0xc8(%rsp), %rsi
movq %rbx, %rdi
callq 0x360c
testl %eax, %eax
jne 0x28c1
leaq 0x2c0(%rsp), %r15
movq $0x3, (%r15)
movq %r15, %rdi
xorl %esi, %esi
callq 0x2a5a
movq %rax, %rbx
movl $0x1, %esi
movq %r15, %rdi
callq 0x2a5a
movq %rax, %r12
movl $0x2, %esi
movq %r15, %rdi
callq 0x2a5a
leaq 0x5c42(%rip), %rdi      # 0x821a
movq %rbx, %rsi
movq %r12, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2140
cmpl $0x3, %eax
jne 0x289b
movl $0xf8, %ecx
leaq (%rcx,%r13), %rax
movq %rax, 0x40(%rsp)
movl $0x158, %edx            # imm = 0x158
leaq (%rdx,%r13), %rax
movq %rax, 0x38(%rsp)
movl $0x1b8, %eax            # imm = 0x1B8
addq %rax, %r13
movq %r13, 0x48(%rsp)
leaq 0xc8(%rsp), %rsi
addq %rsi, %rcx
movq %rcx, 0x30(%rsp)
addq %rsi, %rdx
movq %rdx, 0x28(%rsp)
addq %rax, %rsi
movq %rsi, 0x20(%rsp)
leaq 0x2a0(%rsp), %r12
leaq 0xa8(%rsp), %r13
leaq 0x88(%rsp), %rbp
leaq 0x68(%rsp), %rbx
movq %r14, 0x50(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq %r15, 0xb0(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x2bfc
movq 0x40(%rsp), %rax
movq %rax, 0x88(%rsp)
movq %r12, 0x90(%rsp)
movq 0x3d8(%rsp), %rsi
movq %r13, %rdi
callq 0x2930
movq %r13, %rdi
movq %rbp, %rsi
callq 0x3587
movq %r13, %rdi
xorl %esi, %esi
callq 0x2a5a
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movl $0x2, %esi
movq %r13, %rdi
callq 0x2a5a
movsd 0x8(%rsp), %xmm0
divsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movl $0x1, %esi
movq %r13, %rdi
callq 0x2a5a
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movl $0x2, %esi
movq %r13, %rdi
callq 0x2a5a
movsd (%rsp), %xmm0
divsd (%rax), %xmm0
movsd %xmm0, (%rsp)
cmpl $0x3, %r14d
jne 0x281a
movq 0x28(%rsp), %rax
movq %rax, 0x68(%rsp)
movq %r15, 0x70(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x78(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x2bfc
movq 0x30(%rsp), %rax
movq %rax, 0x58(%rsp)
movq %rbp, 0x60(%rsp)
movq 0x1c0(%rsp), %rsi
movq %rbx, %rdi
callq 0x2930
movq %rbx, %rdi
leaq 0x58(%rsp), %rsi
callq 0x3587
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2a5a
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movl $0x2, %esi
movq %rbx, %rdi
callq 0x2a5a
movsd 0x18(%rsp), %xmm0
divsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movl $0x1, %esi
movq %rbx, %rdi
callq 0x2a5a
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movl $0x2, %esi
movq %rbx, %rdi
callq 0x2a5a
movsd 0x10(%rsp), %xmm0
divsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movl $0x2, %esi
movq %r12, %rdi
callq 0x2a5a
movsd (%rax), %xmm2
movsd 0x8(%rsp), %xmm0
movsd 0x18(%rsp), %xmm3
subsd %xmm0, %xmm3
movsd (%rsp), %xmm1
movsd 0x10(%rsp), %xmm4
subsd %xmm1, %xmm4
leaq 0x5a15(%rip), %rdi      # 0x8226
movb $0x5, %al
callq 0x2060
jmp 0x2844
movl $0x2, %esi
movq %r12, %rdi
callq 0x2a5a
movsd (%rax), %xmm2
leaq 0x59fa(%rip), %rdi      # 0x822c
movsd 0x8(%rsp), %xmm0
movsd (%rsp), %xmm1
movb $0x3, %al
callq 0x2060
movq %r15, %rdi
xorl %esi, %esi
callq 0x2a5a
movq %rax, %rbp
movl $0x1, %esi
movq %r15, %rdi
callq 0x2a5a
movq %rax, %r14
movl $0x2, %esi
movq %r15, %rdi
callq 0x2a5a
leaq 0x59a5(%rip), %rdi      # 0x821a
movq %rbp, %rsi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2140
cmpl $0x3, %eax
movq 0x50(%rsp), %r14
leaq 0x88(%rsp), %rbp
je 0x265c
xorl %eax, %eax
addq $0x4b8, %rsp            # imm = 0x4B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %rdi
callq 0x22cc
movl %eax, %edi
movq %r15, %rsi
callq 0x2280
movl %eax, %edi
movq %rbx, %rsi
callq 0x22a6
nop