// File: /workspace/github_cpp_makefile_star2_O2/devernay[P]vlpovutils/vlpov_motionfield.cpp
// Function: main
int main(int argc, char *argv[])
{
    if (argc != 3) {
        fprintf(stderr, USAGE, argv[0]);
        exit(2);
    }
    const char *frame1 = argv[1];
    const char *frame2 = argv[2];
    const char *frame2_basename = mybasename(frame2);

#ifdef VLPOV_OLD
#warning "compiling in comparison with old vlpovutils"
    {
        VLPovImage<double> z1;
        VLPovCameraOld cam1;
        VLPovCameraOld cam2;
        int retval;
    
        retval = vlpov_povread_old(frame1, z1, cam1);
        if(retval != 0) {
            fprintf(stderr,"Error %d while reading %s.{png,depth,txt}\n", retval, frame1);
            exit(1);
        }
        matrix33 K1, R1;
        vector3 t1;
        cam1.intrinsicMatrix(K1);
        //cam1.extrinsicParameters(R1, t1);
        cout << "Intrinsic matrix 1 (old): " << endl << K1 << endl;
        cout << "Extrinsic 1 (old): " << endl << cam1.R << endl << cam1.T << endl;
        z1.save((std::string(frame1)+".zold").c_str());
                
        retval = vlpov_povread_old(frame2, cam2);
        if(retval != 0) {
            fprintf(stderr,"Error %d while reading %s.txt\n", retval, frame2);
            exit(1);
        }
        
        VLPovImage<double> m1x, m1y;
        vlpov_motionfield_old(cam1, z1, cam2, m1x, m1y);
        std::string m1x_name = std::string(frame1)+"."+std::string(frame2_basename)+".mxold";
        std::string m1y_name = std::string(frame1)+"."+std::string(frame2_basename)+".myold";
        retval = m1x.save(m1x_name.c_str());
        if(retval != 0) {
            fprintf(stderr,"Error %d while saving %s\n", retval, m1x_name.c_str());
            exit(1);
        }
    
        m1y.save(m1y_name.c_str());
        if(retval != 0) {
            fprintf(stderr,"Error %d while saving %s\n", retval, m1y_name.c_str());
            exit(1);
        }
    }
#endif // VLPOV_OLD
    
    {
        VLPovImage<double> z1;
        VLPovCamera cam1;
        VLPovCamera cam2;
        int retval;
        
        retval = vlpov_povread(frame1, z1, cam1);
        if(retval != 0) {
            fprintf(stderr,"Error %d while reading %s.{png,depth,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;
        z1.save((std::string(frame1)+".znew").c_str());
        
        retval = vlpov_povread(frame2, cam2);
        if(retval != 0) {
            fprintf(stderr,"Error %d while reading %s.txt\n", retval, frame2);
            exit(1);
        }
        
        VLPovImage<double> m1x, m1y;
        vlpov_motionfield(cam1, z1, cam2, m1x, m1y);
        std::string m1x_name = std::string(frame1)+"."+std::string(frame2_basename)+".mx";
        std::string m1y_name = std::string(frame1)+"."+std::string(frame2_basename)+".my";
        retval = m1x.save(m1x_name.c_str());
        if(retval != 0) {
            fprintf(stderr,"Error %d while saving %s\n", retval, m1x_name.c_str());
            exit(1);
        }
        
        m1y.save(m1y_name.c_str());
        if(retval != 0) {
            fprintf(stderr,"Error %d while saving %s\n", retval, m1y_name.c_str());
            exit(1);
        }
    }
    
    return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x4b0, %rsp            # imm = 0x4B0
cmpl $0x3, %edi
jne 0x2832
movq 0x8(%rsi), %r14
movq 0x10(%rsi), %r15
movq %r15, %rdi
callq 0x24dc
movq %rax, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x299e
leaq 0x2d8(%rsp), %rdi
callq 0x299e
leaq 0x10(%rsp), %rsi
leaq 0x100(%rsp), %rdx
movq %r14, %rdi
callq 0x47cd
testl %eax, %eax
jne 0x2851
movq 0x8a47(%rip), %rdi      # 0xafb0
leaq 0x4d3d(%rip), %rsi      # 0x72ad
callq 0x2120
movq %rax, %rdi
callq 0x2090
leaq 0x1f8(%rsp), %rsi
movq %rax, %rdi
callq 0x29f5
movq %rax, %rdi
callq 0x2090
movq 0x8a14(%rip), %rdi      # 0xafb0
leaq 0x4d24(%rip), %rsi      # 0x72c7
callq 0x2120
movq %rax, %rdi
callq 0x2090
leaq 0x258(%rsp), %rsi
movq %rax, %rdi
callq 0x29f5
movq %rax, %rdi
callq 0x2090
leaq 0x2b8(%rsp), %rsi
movq %rax, %rdi
callq 0x2c74
movq %rax, %rdi
callq 0x2090
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rdx
movq %r14, %rsi
callq 0x2ec2
leaq 0x4ce1(%rip), %rdx      # 0x72da
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x2ea3
movq 0x60(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x2e20
leaq 0x60(%rsp), %rdi
callq 0x2080
leaq 0x20(%rsp), %rdi
callq 0x2080
leaq 0x2d8(%rsp), %rsi
movq %r15, %rdi
callq 0x42c8
testl %eax, %eax
jne 0x2869
xorps %xmm0, %xmm0
leaq 0x90(%rsp), %rcx
movaps %xmm0, (%rcx)
leaq 0x80(%rsp), %r8
movaps %xmm0, (%r8)
leaq 0x100(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x2d8(%rsp), %rdx
callq 0x3720
leaq 0xc0(%rsp), %rdi
leaq 0xe0(%rsp), %rdx
movq %r14, %rsi
callq 0x2ec2
leaq 0x5358(%rip), %rdx      # 0x79ee
leaq 0x40(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x2ea3
leaq 0xa0(%rsp), %rdi
leaq 0xe(%rsp), %rdx
movq %rbx, %rsi
callq 0x2ec2
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
callq 0x2efd
leaq 0x4c24(%rip), %rdx      # 0x72ff
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x2ea3
leaq 0x20(%rsp), %rdi
callq 0x2080
leaq 0xa0(%rsp), %rdi
callq 0x2080
leaq 0x40(%rsp), %rdi
callq 0x2080
leaq 0xc0(%rsp), %rdi
callq 0x2080
leaq 0xa0(%rsp), %rdi
leaq 0xe(%rsp), %rdx
movq %r14, %rsi
callq 0x2ec2
leaq 0x52ba(%rip), %rdx      # 0x79ee
leaq 0xc0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x2ea3
leaq 0xe0(%rsp), %rdi
leaq 0xf(%rsp), %rdx
movq %rbx, %rsi
callq 0x2ec2
leaq 0x40(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
leaq 0xe0(%rsp), %rdx
callq 0x2efd
leaq 0x4b84(%rip), %rdx      # 0x7303
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x2ea3
leaq 0x40(%rsp), %rdi
callq 0x2080
leaq 0xe0(%rsp), %rdi
callq 0x2080
leaq 0xc0(%rsp), %rdi
callq 0x2080
leaq 0xa0(%rsp), %rdi
callq 0x2080
movq 0x60(%rsp), %rsi
leaq 0x90(%rsp), %rdi
callq 0x2e20
testl %eax, %eax
jne 0x2881
movq 0x20(%rsp), %rsi
leaq 0x80(%rsp), %rdi
callq 0x2e20
leaq 0x20(%rsp), %rdi
callq 0x2080
leaq 0x60(%rsp), %rdi
callq 0x2080
leaq 0x80(%rsp), %rdi
callq 0x2f64
leaq 0x90(%rsp), %rdi
callq 0x2f64
leaq 0x10(%rsp), %rdi
callq 0x2f64
xorl %eax, %eax
addq $0x4b0, %rsp            # imm = 0x4B0
popq %rbx
popq %r14
popq %r15
retq
movq 0x877f(%rip), %rax      # 0xafb8
movq (%rax), %rdi
movq (%rsi), %rdx
leaq 0x47be(%rip), %rsi      # 0x7004
xorl %eax, %eax
callq 0x2200
pushq $0x2
jmp 0x28a2
movq 0x8760(%rip), %rcx      # 0xafb8
movq (%rcx), %rdi
leaq 0x4a20(%rip), %rsi      # 0x7282
movl %eax, %edx
movq %r14, %rcx
jmp 0x2899
movq 0x8748(%rip), %rcx      # 0xafb8
movq (%rcx), %rdi
leaq 0x4a66(%rip), %rsi      # 0x72e0
movl %eax, %edx
movq %r15, %rcx
jmp 0x2899
movq 0x8730(%rip), %rcx      # 0xafb8
movq (%rcx), %rdi
movq 0x60(%rsp), %rcx
leaq 0x4a70(%rip), %rsi      # 0x7307
movl %eax, %edx
xorl %eax, %eax
callq 0x2200
pushq $0x1
popq %rdi
callq 0x21a0
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x2080
jmp 0x28ba
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x2080
jmp 0x28cc
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x2080
jmp 0x28de
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
jmp 0x295d
movq %rax, %rbx
jmp 0x2962
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2080
jmp 0x28ff
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x2080
jmp 0x2911
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x2080
jmp 0x2920
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
jmp 0x2967
jmp 0x292c
movq %rax, %rbx
jmp 0x296c
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x2080
jmp 0x2943
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2080
jmp 0x298b
jmp 0x2988
jmp 0x2988
jmp 0x2988
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2080
leaq 0x60(%rsp), %rdi
callq 0x2080
leaq 0x80(%rsp), %rdi
callq 0x2f64
leaq 0x90(%rsp), %rdi
callq 0x2f64
jmp 0x298b
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2f64
movq %rbx, %rdi
callq 0x22b0
nop