// File: /workspace/github_cpp_makefile_star2_O2/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, %r15d
leal -0x4(%r15), %eax
cmpl $-0x3, %eax
jbe 0x26f7
movq 0x8(%rsi), %r14
cmpl $0x3, %r15d
jne 0x23ed
movq 0x10(%rsi), %rbx
jmp 0x23ef
xorl %ebx, %ebx
leaq 0x2e0(%rsp), %r12
movq %r12, %rdi
callq 0x2754
leaq 0x108(%rsp), %rdi
movq %rdi, %rbp
callq 0x2754
movq %r14, %rdi
movq %r12, %r13
movq %r12, %rsi
callq 0x33ec
testl %eax, %eax
jne 0x2716
cmpl $0x3, %r15d
jne 0x2443
leaq 0x108(%rsp), %rsi
movq %rbx, %rdi
callq 0x33ec
testl %eax, %eax
jne 0x272e
movq %r15, 0x50(%rsp)
leaq 0xe8(%rsp), %r12
movq $0x3, (%r12)
movl $0x158, %ecx            # imm = 0x158
leaq (%rcx,%r13), %rax
movq %rax, 0x40(%rsp)
movl $0x1b8, %edx            # imm = 0x1B8
leaq (%rdx,%r13), %rax
movq %rax, 0x38(%rsp)
movl $0xf8, %eax
addq %rax, %r13
movq %r13, 0x48(%rsp)
addq %rbp, %rcx
movq %rcx, 0x28(%rsp)
addq %rbp, %rdx
movq %rdx, 0x20(%rsp)
addq %rax, %rbp
movq %rbp, 0x30(%rsp)
pushq $0x1
popq %r15
leaq 0x88(%rsp), %rbx
movq %r12, %rdi
xorl %esi, %esi
callq 0x2ac0
movq %rax, %r13
movq %r12, %rdi
movq %r15, %rsi
callq 0x2ac0
movq %r15, %r14
movq %rax, %r15
movq %r12, %rdi
pushq $0x2
popq %rsi
callq 0x2ac0
leaq 0x4d45(%rip), %rdi      # 0x721a
movq %r13, %rsi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2110
cmpl $0x3, %eax
jne 0x26e3
movq 0x40(%rsp), %rax
movq %rax, 0x88(%rsp)
movq %r12, 0x90(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x98(%rsp)
leaq 0xc8(%rsp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2c1e
movq 0x48(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq %r13, 0xb0(%rsp)
movq %rbx, %rdi
movq %r12, %rbp
leaq 0xa8(%rsp), %r12
movq %r12, %rsi
callq 0x334c
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2ac0
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
pushq $0x2
popq %r15
movq %r15, %rsi
callq 0x2ac0
movsd 0x8(%rsp), %xmm0
divsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2ac0
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2ac0
movsd (%rsp), %xmm0
divsd (%rax), %xmm0
movsd %xmm0, (%rsp)
cmpl $0x3, 0x50(%rsp)
movq %r14, %r15
jne 0x26b3
movq 0x28(%rsp), %rax
movq %rax, 0x68(%rsp)
movq %rbp, 0x70(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x78(%rsp)
movq %r12, %rdi
movq %rbx, %r13
leaq 0x68(%rsp), %rbx
movq %rbx, %rsi
callq 0x2c1e
movq 0x30(%rsp), %rax
movq %rax, 0x58(%rsp)
movq %r12, 0x60(%rsp)
movq %rbx, %rdi
leaq 0x58(%rsp), %rsi
callq 0x334c
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2ac0
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
pushq $0x2
popq %r14
movq %r14, %rsi
callq 0x2ac0
movsd 0x18(%rsp), %xmm0
divsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2ac0
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movq %r13, %rbx
movq %r14, %rsi
callq 0x2ac0
movsd 0x10(%rsp), %xmm0
divsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0xc8(%rsp), %rdi
movq %r14, %rsi
callq 0x2ac0
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 0x4b82(%rip), %rdi      # 0x7226
movb $0x5, %al
callq 0x2050
movq %rbp, %r12
jmp 0x24a5
movq %r13, %rdi
pushq $0x2
popq %rsi
callq 0x2ac0
movsd (%rax), %xmm2
leaq 0x4b63(%rip), %rdi      # 0x722c
movsd 0x8(%rsp), %xmm0
movsd (%rsp), %xmm1
movb $0x3, %al
callq 0x2050
movq %rbp, %r12
jmp 0x24a5
xorl %eax, %eax
addq $0x4b8, %rsp            # imm = 0x4B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x88ba(%rip), %rax      # 0xafb8
movq (%rax), %rdi
movq (%rsi), %rdx
leaq 0x48f9(%rip), %rsi      # 0x7004
xorl %eax, %eax
callq 0x2170
pushq $0x2
jmp 0x274d
movq 0x889b(%rip), %rcx      # 0xafb8
movq (%rcx), %rdi
leaq 0x4ad4(%rip), %rsi      # 0x71fb
movl %eax, %edx
movq %r14, %rcx
jmp 0x2744
movq 0x8883(%rip), %rcx      # 0xafb8
movq (%rcx), %rdi
leaq 0x4abc(%rip), %rsi      # 0x71fb
movl %eax, %edx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2170
pushq $0x1
popq %rdi
callq 0x2140
nop