// File: /workspace/github_cpp_makefile_star2_O2/devernay[P]vlpovutils/povread.cpp
// Function: vlpov_get_cam(char const*, VLPovCamera&)
int vlpov_get_cam(const char* info_file, VLPovCamera &cam)
{
    cam.width  = 1 ;
    cam.height = 1 ;
    cam.focal  = 1. ;
    cam.angle  = M_PI/2 ;
    cam.K      = identity_matrix<double>(3) ;
    cam.R      = identity_matrix<double>(3) ;
    
    // f = fopen(info_file, 'r') ;
    FILE *f = fopen(info_file, "r");
    if (f == NULL) {
        return -1;
    }
    
    char output_name[256];
    char cam_type[256];
    
    // the scanning format comes from the vlpov povray patch
    int count = fscanf(f,
                       "output_name   = '%256s ;\n"
                       "screen_height = %d ;\n"
                       "screen_width  = %d ;\n"
                       "cam_type      = '%256s ;\n"
                       "cam_pos       = [%lf %lf %lf]' ;\n"
                       "cam_dir       = [%lf %lf %lf]' ;\n"
                       "cam_up        = [%lf %lf %lf]' ;\n"
                       "cam_right     = [%lf %lf %lf]' ;\n"
                       "cam_sky       = [%lf %lf %lf]' ;\n"
                       "cam_lookat    = [%lf %lf %lf]' ;\n"
                       "cam_fpoint    = [%lf %lf %lf]' ;\n"
                       "cam_focal     = %lf ;\n"
                       "cam_angle     = %lf ;\n",
                       output_name,
                       &cam.height,
                       &cam.width,
                       cam_type,
                       &cam.pos[0], 
                       &cam.pos[1], 
                       &cam.pos[2],
                       &cam.dir[0], 
                       &cam.dir[1], 
                       &cam.dir[2],
                       &cam.up[0], 
                       &cam.up[1], 
                       &cam.up[2],
                       &cam.right[0], 
                       &cam.right[1], 
                       &cam.right[2],
                       &cam.sky[0], 
                       &cam.sky[1], 
                       &cam.sky[2],
                       &cam.lookat[0],
                       &cam.lookat[1],
                       &cam.lookat[2],
                       &cam.fpoint[0],
                       &cam.fpoint[1],
                       &cam.fpoint[2],
                       &cam.focal,
                       &cam.angle) ;
    if (count != 27) {
        return -1;
    }
    
    // % pov uses a left-handed system: convert.
    // e=diag([1 1 -1]) ;
    matrix33 e = diagonal(1.,1.,-1.);
    // cam_pos  = e*cam_pos ;
    cam.pos(2) = -cam.pos(2);
    // cam_up   = e*cam_up ;
    cam.up(2) = -cam.up(2);
    // cam_dir  = e*cam_dir ;
    cam.dir(2) = -cam.dir(2);
    // camright = e*cam_right ; <= bug in vlpov, but only its norm is used anyway
    cam.right(2) = -cam.right(2);

    // % After sourcing the script we are left with (at least)
    // %
    // % cam_pos
    // % cam_dir
    // % cam_up
    // % cam_right
    // %
    // % We compute: K, R, t

    vlpov_vec2camera(cam.width, cam.height, cam.pos, cam.dir, cam.up, cam.right, cam.K, cam.R, cam.t);
    
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x348, %rsp            # imm = 0x348
movq %rsi, %rbx
movq %rdi, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, (%rsi)
movaps 0x3727(%rip), %xmm0     # 0x8960
movups %xmm0, 0xe8(%rsi)
pushq $0x3
popq %r15
leaq 0x1e0(%rsp), %rsi
movq %r15, (%rsi)
movq %r15, 0x8(%rsi)
movq %r15, 0x10(%rsi)
leaq 0xe0(%rsp), %rdi
callq 0x5cf2
leaq 0xf8(%rbx), %r12
leaq 0xe0(%rsp), %rsi
movq %r12, %rdi
callq 0x5a92
leaq 0x1e0(%rsp), %rsi
movq %r15, (%rsi)
movq %r15, 0x8(%rsi)
movq %r15, 0x10(%rsi)
leaq 0xe0(%rsp), %rdi
callq 0x5cf2
leaq 0x158(%rbx), %r15
leaq 0xe0(%rsp), %rsi
movq %r15, %rdi
callq 0x5a92
leaq 0x39ad(%rip), %rsi      # 0x8c66
movq %r14, %rdi
callq 0x21a0
testq %rax, %rax
je 0x568a
movq %r15, 0x30(%rsp)
movq %r12, 0x38(%rsp)
leaq 0x4(%rbx), %rcx
movq %rcx, 0xa8(%rsp)
movq %rax, 0xa0(%rsp)
leaq 0xe8(%rbx), %rax
movq %rax, 0xc0(%rsp)
leaq 0xf0(%rbx), %rax
movq %rax, 0xb8(%rsp)
leaq 0x8(%rbx), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x4108
movq %rax, (%rsp)
pushq $0x1
popq %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x4108
movq %rax, 0xd8(%rsp)
pushq $0x2
popq %rbp
movq %r14, 0x28(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x4108
movq %rax, 0xd0(%rsp)
leaq 0x28(%rbx), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x4108
movq %rax, 0xc8(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x4108
movq %rax, 0xb0(%rsp)
movq %r14, 0x20(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x4108
movq %rax, 0x98(%rsp)
leaq 0x48(%rbx), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x4108
movq %rax, 0x90(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x4108
movq %rax, 0x88(%rsp)
movq %r14, 0x18(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x4108
movq %rax, 0x80(%rsp)
leaq 0x68(%rbx), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x4108
movq %rax, 0x78(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x4108
movq %rax, 0x70(%rsp)
movq %r14, 0x10(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x4108
movq %rax, 0x68(%rsp)
leaq 0x88(%rbx), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x4108
movq %rax, 0x60(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x4108
movq %rax, 0x58(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x4108
movq %rax, 0x50(%rsp)
leaq 0xa8(%rbx), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x4108
movq %rax, 0x48(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x4108
movq %rax, 0x40(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x4108
movq %rax, %r12
leaq 0xc8(%rbx), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x4108
movq %rax, %r14
movq %r15, %rdi
movq %r13, %rsi
callq 0x4108
movq %rax, %r13
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4108
movq %rax, %r10
subq $0x8, %rsp
leaq 0x34db(%rip), %rsi      # 0x8984
leaq 0xe8(%rsp), %rdx
leaq 0x1e8(%rsp), %r9
movq 0xa8(%rsp), %rdi
movq 0xb0(%rsp), %rcx
movq %rbx, %r8
movl $0x0, %eax
pushq 0xc0(%rsp)
pushq 0xd0(%rsp)
pushq %r10
pushq %r13
pushq %r14
pushq %r12
pushq 0x78(%rsp)
pushq 0x88(%rsp)
pushq 0x98(%rsp)
pushq 0xa8(%rsp)
pushq 0xb8(%rsp)
pushq 0xc8(%rsp)
pushq 0xd8(%rsp)
pushq 0xe8(%rsp)
pushq 0xf8(%rsp)
pushq 0x108(%rsp)
pushq 0x118(%rsp)
pushq 0x128(%rsp)
pushq 0x148(%rsp)
pushq 0x168(%rsp)
pushq 0x178(%rsp)
pushq 0x188(%rsp)
pushq 0xb8(%rsp)
callq 0x22a0
addq $0xc0, %rsp
cmpl $0x1b, %eax
jne 0x568a
leaq 0x2e8(%rsp), %rdi
movsd 0x2a88(%rip), %xmm0     # 0x8008
movsd 0x33e8(%rip), %xmm2     # 0x8970
movaps %xmm0, %xmm1
callq 0x59ac
pushq $0x2
popq %r14
movq 0x28(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x4108
movsd (%rax), %xmm0
movaps %xmm0, (%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x4108
movaps (%rsp), %xmm0
xorps 0x301e(%rip), %xmm0     # 0x85e0
movlps %xmm0, (%rax)
movq 0x18(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x4108
movsd (%rax), %xmm0
movaps %xmm0, (%rsp)
movq %r13, %rdi
movq %r14, %rsi
callq 0x4108
movaps (%rsp), %xmm0
xorps 0x2fed(%rip), %xmm0     # 0x85e0
movlps %xmm0, (%rax)
movq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x4108
movsd (%rax), %xmm0
movaps %xmm0, (%rsp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x4108
movaps (%rsp), %xmm0
xorps 0x2fbc(%rip), %xmm0     # 0x85e0
movlps %xmm0, (%rax)
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
callq 0x4108
movsd (%rax), %xmm0
movaps %xmm0, (%rsp)
movq %rbp, %rdi
movq %r14, %rsi
callq 0x4108
movaps (%rsp), %xmm0
xorps 0x2f8b(%rip), %xmm0     # 0x85e0
movlps %xmm0, (%rax)
movl (%rbx), %edi
movl 0x4(%rbx), %esi
addq $0x1b8, %rbx            # imm = 0x1B8
subq $0x8, %rsp
movq %r15, %rdx
movq %r12, %rcx
movq %r13, %r8
movq %rbp, %r9
pushq %rbx
pushq 0x40(%rsp)
pushq 0x50(%rsp)
callq 0x6360
addq $0x20, %rsp
xorl %eax, %eax
jmp 0x568d
pushq $-0x1
popq %rax
addq $0x348, %rsp            # imm = 0x348
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x56a5
jmp 0x56a5
jmp 0x56a5
movq %rax, %rdi
callq 0x2280