// File: 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 %rbp
movq %rsp, %rbp
subq $0x680, %rsp            # imm = 0x680
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x8(%rbp)
je 0x3738
movq 0x138ba(%rip), %rax     # 0x16fd0
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0xc8dd(%rip), %rsi      # 0x10004
movb $0x0, %al
callq 0x3310
movl $0x2, %edi
callq 0x32b0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x36a0
movq %rax, -0x28(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x4050
leaq -0x210(%rbp), %rdi
callq 0x4080
jmp 0x3774
leaq -0x3f8(%rbp), %rdi
callq 0x4080
jmp 0x3782
movq -0x18(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x210(%rbp), %rdx
callq 0x8f80
movl %eax, -0x5c8(%rbp)
jmp 0x379e
movl -0x5c8(%rbp), %eax
movl %eax, -0x3fc(%rbp)
cmpl $0x0, -0x3fc(%rbp)
je 0x3824
movq 0x13816(%rip), %rax     # 0x16fd0
movq (%rax), %rdi
movl -0x3fc(%rbp), %edx
movq -0x18(%rbp), %rcx
leaq 0xcab4(%rip), %rsi      # 0x10282
movb $0x0, %al
callq 0x3310
movl $0x1, %edi
callq 0x32b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x4033
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x4027
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x401b
movq 0x1379d(%rip), %rdi     # 0x16fc8
leaq 0xca7b(%rip), %rsi      # 0x102ad
callq 0x31c0
movq %rax, -0x5d0(%rbp)
jmp 0x3840
movq -0x5d0(%rbp), %rdi
movq 0x13752(%rip), %rsi     # 0x16fa0
callq 0x3200
movq %rax, -0x5d8(%rbp)
jmp 0x385c
movq -0x5d8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x4240
movq %rax, -0x5e0(%rbp)
jmp 0x3878
movq -0x5e0(%rbp), %rdi
movq 0x1371a(%rip), %rsi     # 0x16fa0
callq 0x3200
jmp 0x388d
movq 0x13734(%rip), %rdi     # 0x16fc8
leaq 0xca2c(%rip), %rsi      # 0x102c7
callq 0x31c0
movq %rax, -0x5e8(%rbp)
jmp 0x38a9
movq -0x5e8(%rbp), %rdi
movq 0x136e9(%rip), %rsi     # 0x16fa0
callq 0x3200
movq %rax, -0x5f0(%rbp)
jmp 0x38c5
movq -0x5f0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x4240
movq %rax, -0x5f8(%rbp)
jmp 0x38e1
movq -0x5f8(%rbp), %rdi
movq 0x136b1(%rip), %rsi     # 0x16fa0
callq 0x3200
movq %rax, -0x600(%rbp)
jmp 0x38fd
movq -0x600(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x4760
movq %rax, -0x608(%rbp)
jmp 0x3916
movq -0x608(%rbp), %rdi
movq 0x1367c(%rip), %rsi     # 0x16fa0
callq 0x3200
jmp 0x392b
movq -0x18(%rbp), %rax
movq %rax, -0x618(%rbp)
leaq -0x441(%rbp), %rdi
movq %rdi, -0x610(%rbp)
callq 0x3410
movq -0x618(%rbp), %rsi
movq -0x610(%rbp), %rdx
leaq -0x440(%rbp), %rdi
callq 0x4bd0
jmp 0x3965
leaq 0xc96e(%rip), %rdx      # 0x102da
leaq -0x420(%rbp), %rdi
leaq -0x440(%rbp), %rsi
callq 0x4b80
jmp 0x3981
leaq -0x420(%rbp), %rdi
callq 0x30d0
movq %rax, %rsi
leaq -0x38(%rbp), %rdi
callq 0x4aa0
jmp 0x399b
leaq -0x420(%rbp), %rdi
callq 0x3120
leaq -0x440(%rbp), %rdi
callq 0x3120
leaq -0x441(%rbp), %rdi
callq 0x3220
movq -0x20(%rbp), %rdi
leaq -0x3f8(%rbp), %rsi
callq 0x86f0
movl %eax, -0x61c(%rbp)
jmp 0x39d7
movl -0x61c(%rbp), %eax
movl %eax, -0x3fc(%rbp)
cmpl $0x0, -0x3fc(%rbp)
je 0x3a7f
movq 0x135d9(%rip), %rax     # 0x16fd0
movq (%rax), %rdi
movl -0x3fc(%rbp), %edx
movq -0x20(%rbp), %rcx
leaq 0xc8d5(%rip), %rsi      # 0x102e0
movb $0x0, %al
callq 0x3310
movl $0x1, %edi
callq 0x32b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x3a6e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x3a62
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
leaq -0x420(%rbp), %rdi
callq 0x3120
leaq -0x440(%rbp), %rdi
callq 0x3120
leaq -0x441(%rbp), %rdi
callq 0x3220
jmp 0x401b
leaq -0x458(%rbp), %rdi
callq 0x4050
jmp 0x3a8d
leaq -0x468(%rbp), %rdi
callq 0x4050
jmp 0x3a9b
leaq -0x210(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x3f8(%rbp), %rdx
leaq -0x458(%rbp), %rcx
leaq -0x468(%rbp), %r8
callq 0x6420
jmp 0x3ac2
movq -0x18(%rbp), %rax
movq %rax, -0x630(%rbp)
leaq -0x4e9(%rbp), %rdi
movq %rdi, -0x628(%rbp)
callq 0x3410
movq -0x630(%rbp), %rsi
movq -0x628(%rbp), %rdx
leaq -0x4e8(%rbp), %rdi
callq 0x4bd0
jmp 0x3afc
leaq 0xcedb(%rip), %rdx      # 0x109de
leaq -0x4c8(%rbp), %rdi
leaq -0x4e8(%rbp), %rsi
callq 0x4b80
jmp 0x3b18
movq -0x28(%rbp), %rax
movq %rax, -0x640(%rbp)
leaq -0x511(%rbp), %rdi
movq %rdi, -0x638(%rbp)
callq 0x3410
movq -0x640(%rbp), %rsi
movq -0x638(%rbp), %rdx
leaq -0x510(%rbp), %rdi
callq 0x4bd0
jmp 0x3b52
leaq -0x4a8(%rbp), %rdi
leaq -0x4c8(%rbp), %rsi
leaq -0x510(%rbp), %rdx
callq 0x4c80
jmp 0x3b6e
leaq 0xc78a(%rip), %rdx      # 0x102ff
leaq -0x488(%rbp), %rdi
leaq -0x4a8(%rbp), %rsi
callq 0x4b80
jmp 0x3b8a
leaq -0x4a8(%rbp), %rdi
callq 0x3120
leaq -0x510(%rbp), %rdi
callq 0x3120
leaq -0x511(%rbp), %rdi
callq 0x3220
leaq -0x4c8(%rbp), %rdi
callq 0x3120
leaq -0x4e8(%rbp), %rdi
callq 0x3120
leaq -0x4e9(%rbp), %rdi
callq 0x3220
movq -0x18(%rbp), %rax
movq %rax, -0x650(%rbp)
leaq -0x599(%rbp), %rdi
movq %rdi, -0x648(%rbp)
callq 0x3410
movq -0x650(%rbp), %rsi
movq -0x648(%rbp), %rdx
leaq -0x598(%rbp), %rdi
callq 0x4bd0
jmp 0x3c0c
leaq 0xcdcb(%rip), %rdx      # 0x109de
leaq -0x578(%rbp), %rdi
leaq -0x598(%rbp), %rsi
callq 0x4b80
jmp 0x3c28
movq -0x28(%rbp), %rax
movq %rax, -0x660(%rbp)
leaq -0x5c1(%rbp), %rdi
movq %rdi, -0x658(%rbp)
callq 0x3410
movq -0x660(%rbp), %rsi
movq -0x658(%rbp), %rdx
leaq -0x5c0(%rbp), %rdi
callq 0x4bd0
jmp 0x3c62
leaq -0x558(%rbp), %rdi
leaq -0x578(%rbp), %rsi
leaq -0x5c0(%rbp), %rdx
callq 0x4c80
jmp 0x3c7e
leaq 0xc67e(%rip), %rdx      # 0x10303
leaq -0x538(%rbp), %rdi
leaq -0x558(%rbp), %rsi
callq 0x4b80
jmp 0x3c9a
leaq -0x558(%rbp), %rdi
callq 0x3120
leaq -0x5c0(%rbp), %rdi
callq 0x3120
leaq -0x5c1(%rbp), %rdi
callq 0x3220
leaq -0x578(%rbp), %rdi
callq 0x3120
leaq -0x598(%rbp), %rdi
callq 0x3120
leaq -0x599(%rbp), %rdi
callq 0x3220
leaq -0x488(%rbp), %rdi
callq 0x30d0
movq %rax, %rsi
leaq -0x458(%rbp), %rdi
callq 0x4aa0
movl %eax, -0x664(%rbp)
jmp 0x3d05
movl -0x664(%rbp), %eax
movl %eax, -0x3fc(%rbp)
cmpl $0x0, -0x3fc(%rbp)
je 0x3f24
movq 0x132ab(%rip), %rax     # 0x16fd0
movq (%rax), %rax
movq %rax, -0x670(%rbp)
movl -0x3fc(%rbp), %eax
movl %eax, -0x668(%rbp)
leaq -0x488(%rbp), %rdi
callq 0x30d0
movq -0x670(%rbp), %rdi
movl -0x668(%rbp), %edx
movq %rax, %rcx
leaq 0xc5a9(%rip), %rsi      # 0x10307
movb $0x0, %al
callq 0x3310
movl $0x1, %edi
callq 0x32b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x400f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x4003
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x3e3e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x3e32
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x3e1a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x3e0e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
leaq -0x4a8(%rbp), %rdi
callq 0x3120
leaq -0x510(%rbp), %rdi
callq 0x3120
leaq -0x511(%rbp), %rdi
callq 0x3220
leaq -0x4c8(%rbp), %rdi
callq 0x3120
leaq -0x4e8(%rbp), %rdi
callq 0x3120
leaq -0x4e9(%rbp), %rdi
callq 0x3220
jmp 0x4003
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x3ef0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x3ee4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x3ecc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x3ec0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
leaq -0x558(%rbp), %rdi
callq 0x3120
leaq -0x5c0(%rbp), %rdi
callq 0x3120
leaq -0x5c1(%rbp), %rdi
callq 0x3220
leaq -0x578(%rbp), %rdi
callq 0x3120
leaq -0x598(%rbp), %rdi
callq 0x3120
leaq -0x599(%rbp), %rdi
callq 0x3220
jmp 0x3ff7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
leaq -0x538(%rbp), %rdi
callq 0x3120
jmp 0x3ff7
leaq -0x538(%rbp), %rdi
callq 0x30d0
movq %rax, %rsi
leaq -0x468(%rbp), %rdi
callq 0x4aa0
jmp 0x3f41
cmpl $0x0, -0x3fc(%rbp)
je 0x3f9b
movq 0x1307f(%rip), %rax     # 0x16fd0
movq (%rax), %rax
movq %rax, -0x680(%rbp)
movl -0x3fc(%rbp), %eax
movl %eax, -0x674(%rbp)
leaq -0x538(%rbp), %rdi
callq 0x30d0
movq -0x680(%rbp), %rdi
movl -0x674(%rbp), %edx
movq %rax, %rcx
leaq 0xc37d(%rip), %rsi      # 0x10307
movb $0x0, %al
callq 0x3310
movl $0x1, %edi
callq 0x32b0
leaq -0x538(%rbp), %rdi
callq 0x3120
leaq -0x488(%rbp), %rdi
callq 0x3120
leaq -0x468(%rbp), %rdi
callq 0x4d50
leaq -0x458(%rbp), %rdi
callq 0x4d50
leaq -0x3f8(%rbp), %rdi
callq 0x4d80
leaq -0x210(%rbp), %rdi
callq 0x4d80
leaq -0x38(%rbp), %rdi
callq 0x4d50
xorl %eax, %eax
addq $0x680, %rsp            # imm = 0x680
popq %rbp
retq
leaq -0x488(%rbp), %rdi
callq 0x3120
leaq -0x468(%rbp), %rdi
callq 0x4d50
leaq -0x458(%rbp), %rdi
callq 0x4d50
leaq -0x3f8(%rbp), %rdi
callq 0x4d80
leaq -0x210(%rbp), %rdi
callq 0x4d80
leaq -0x38(%rbp), %rdi
callq 0x4d50
movq -0x218(%rbp), %rdi
callq 0x33f0
nopl (%rax,%rax)