// File: /workspace/github_cpp_makefile_star2_O3/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 0x515f(%rip), %xmm0     # 0xb900
movups %xmm0, 0xe8(%rsi)
movl $0x3, %eax
leaq 0x1e0(%rsp), %rsi
movq %rax, (%rsi)
movq %rax, 0x8(%rsi)
movq %rax, 0x10(%rsi)
leaq 0xe0(%rsp), %r15
movq %r15, %rdi
callq 0x76fc
leaq 0xf8(%rbx), %r12
movaps 0xe0(%rsp), %xmm0
movups %xmm0, 0xf8(%rbx)
cmpq %r15, %r12
je 0x6824
leaq 0x108(%rbx), %rdi
movq 0xf0(%rsp), %rsi
callq 0x7212
movq 0xf0(%rsp), %rdx
testq %rdx, %rdx
je 0x6824
leaq 0xf8(%rsp), %rsi
shlq $0x3, %rdx
leaq 0x110(%rbx), %rdi
callq 0x2100
movl $0x3, %eax
leaq 0x1e0(%rsp), %rsi
movq %rax, (%rsi)
movq %rax, 0x8(%rsi)
movq %rax, 0x10(%rsi)
leaq 0xe0(%rsp), %r15
movq %r15, %rdi
callq 0x76fc
leaq 0x158(%rbx), %r13
movaps 0xe0(%rsp), %xmm0
movups %xmm0, 0x158(%rbx)
cmpq %r15, %r13
je 0x68a0
leaq 0x168(%rbx), %rdi
movq 0xf0(%rsp), %rsi
callq 0x7212
movq 0xf0(%rsp), %rdx
testq %rdx, %rdx
je 0x68a0
leaq 0xf8(%rsp), %rsi
shlq $0x3, %rdx
leaq 0x170(%rbx), %rdi
callq 0x2100
leaq 0x53a7(%rip), %rsi      # 0xbc4e
movq %r14, %rdi
callq 0x21c0
testq %rax, %rax
je 0x6c9c
movq %r13, 0x38(%rsp)
movq %r12, 0x40(%rsp)
leaq 0x4(%rbx), %rcx
movq %rcx, 0xb0(%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 0x5324
movq %rax, (%rsp)
movl $0x1, %esi
movq %r14, %rdi
callq 0x5324
movq %rax, 0xd8(%rsp)
movl $0x2, %esi
movq %r14, 0x30(%rsp)
movq %r14, %rdi
callq 0x5324
movq %rax, 0xd0(%rsp)
leaq 0x28(%rbx), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x5324
movq %rax, 0xc8(%rsp)
movl $0x1, %esi
movq %r14, %rdi
callq 0x5324
movq %rax, 0xa8(%rsp)
movl $0x2, %esi
movq %r14, 0x28(%rsp)
movq %r14, %rdi
callq 0x5324
movq %rax, 0x98(%rsp)
leaq 0x48(%rbx), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x5324
movq %rax, 0x90(%rsp)
movl $0x1, %esi
movq %r14, %rdi
callq 0x5324
movq %rax, 0x88(%rsp)
movl $0x2, %esi
movq %r14, 0x20(%rsp)
movq %r14, %rdi
callq 0x5324
movq %rax, 0x80(%rsp)
leaq 0x68(%rbx), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x5324
movq %rax, 0x78(%rsp)
movl $0x1, %esi
movq %r14, %rdi
callq 0x5324
movq %rax, 0x70(%rsp)
movl $0x2, %esi
movq %r14, 0x18(%rsp)
movq %r14, %rdi
callq 0x5324
movq %rax, 0x68(%rsp)
leaq 0x88(%rbx), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x5324
movq %rax, 0x60(%rsp)
movl $0x1, %esi
movq %r14, %rdi
callq 0x5324
movq %rax, 0x58(%rsp)
movl $0x2, %esi
movq %r14, %rdi
callq 0x5324
movq %rax, 0x50(%rsp)
leaq 0xa8(%rbx), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x5324
movq %rax, 0x48(%rsp)
movl $0x1, %esi
movq %r15, %rdi
callq 0x5324
movq %rax, %r14
movl $0x2, %esi
movq %r15, %rdi
callq 0x5324
movq %rax, %r13
leaq 0xc8(%rbx), %rbp
movq %rbp, %rdi
xorl %esi, %esi
callq 0x5324
movq %rax, %r15
movl $0x1, %esi
movq %rbp, %rdi
callq 0x5324
movq %rax, %r12
movl $0x2, %esi
movq %rbp, %rdi
callq 0x5324
movq %rax, %r10
subq $0x8, %rsp
leaq 0x4e7a(%rip), %rsi      # 0xb924
leaq 0xe8(%rsp), %rdx
leaq 0x1e8(%rsp), %r9
movq 0xa8(%rsp), %rdi
movq 0xb8(%rsp), %rcx
movq %rbx, %r8
movl $0x0, %eax
pushq 0xc0(%rsp)
pushq 0xd0(%rsp)
pushq %r10
pushq %r12
pushq %r15
pushq %r13
pushq %r14
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 0x140(%rsp)
pushq 0x168(%rsp)
pushq 0x178(%rsp)
pushq 0x188(%rsp)
pushq 0xb8(%rsp)
callq 0x22a0
addq $0xc0, %rsp
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x1b, %ecx
jne 0x6ca1
leaq 0x2e8(%rsp), %rdi
movsd 0x4482(%rip), %xmm0     # 0xb008
movsd 0x4d82(%rip), %xmm2     # 0xb910
movaps %xmm0, %xmm1
callq 0x7081
movl $0x2, %esi
movq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x5324
movsd (%rax), %xmm0
movaps %xmm0, (%rsp)
movl $0x2, %esi
movq %r14, %rdi
callq 0x5324
movaps (%rsp), %xmm0
xorps 0x4908(%rip), %xmm0     # 0xb4d0
movlps %xmm0, (%rax)
movl $0x2, %esi
movq 0x20(%rsp), %r12
movq %r12, %rdi
callq 0x5324
movsd (%rax), %xmm0
movaps %xmm0, (%rsp)
movl $0x2, %esi
movq %r12, %rdi
callq 0x5324
movaps (%rsp), %xmm0
xorps 0x48d3(%rip), %xmm0     # 0xb4d0
movlps %xmm0, (%rax)
movl $0x2, %esi
movq 0x28(%rsp), %r15
movq %r15, %rdi
callq 0x5324
movsd (%rax), %xmm0
movaps %xmm0, (%rsp)
movl $0x2, %esi
movq %r15, %rdi
callq 0x5324
movaps (%rsp), %xmm0
xorps 0x489e(%rip), %xmm0     # 0xb4d0
movlps %xmm0, (%rax)
movl $0x2, %esi
movq 0x18(%rsp), %r13
movq %r13, %rdi
callq 0x5324
movsd (%rax), %xmm0
movaps %xmm0, (%rsp)
movl $0x2, %esi
movq %r13, %rdi
callq 0x5324
movaps (%rsp), %xmm0
xorps 0x4869(%rip), %xmm0     # 0xb4d0
movlps %xmm0, (%rax)
movl (%rbx), %edi
movl 0x4(%rbx), %esi
addq $0x1b8, %rbx            # imm = 0x1B8
subq $0x8, %rsp
movq %r14, %rdx
movq %r15, %rcx
movq %r12, %r8
movq %r13, %r9
pushq %rbx
pushq 0x48(%rsp)
pushq 0x58(%rsp)
callq 0x7fbc
addq $0x20, %rsp
xorl %eax, %eax
jmp 0x6ca1
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x348, %rsp            # imm = 0x348
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6cb9
jmp 0x6cb9
jmp 0x6cb9
movq %rax, %rdi
callq 0x2280