// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x568, %rsp            # imm = 0x568
movq %rdi, -0x38(%rbp)
movq %rsi, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl $0x1, (%rax)
movq -0x40(%rbp), %rax
movl $0x1, 0x4(%rax)
movq -0x40(%rbp), %rax
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, 0xe8(%rax)
movq -0x40(%rbp), %rax
movabsq $0x3ff921fb54442d18, %rcx # imm = 0x3FF921FB54442D18
movq %rcx, 0xf0(%rax)
leaq -0xb8(%rbp), %rdi
movq %rdi, -0x3c0(%rbp)
movl $0x3, %esi
callq 0xb110
movq -0x3c0(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0xb190
jmp 0xa3b8
movq -0x40(%rbp), %rdi
addq $0xf8, %rdi
leaq -0xa0(%rbp), %rsi
callq 0xb1c0
jmp 0xa3d1
leaq -0xa0(%rbp), %rdi
callq 0x61b0
leaq -0xb8(%rbp), %rdi
callq 0xb1f0
leaq -0x140(%rbp), %rdi
movq %rdi, -0x3c8(%rbp)
movl $0x3, %esi
callq 0xb110
movq -0x3c8(%rbp), %rsi
leaq -0x128(%rbp), %rdi
callq 0xb190
jmp 0xa416
movq -0x40(%rbp), %rdi
addq $0x158, %rdi            # imm = 0x158
leaq -0x128(%rbp), %rsi
callq 0xb1c0
jmp 0xa42f
leaq -0x128(%rbp), %rdi
callq 0x61b0
leaq -0x140(%rbp), %rdi
callq 0xb1f0
movq -0x38(%rbp), %rdi
leaq 0x878c(%rip), %rsi      # 0x12bde
callq 0x32b0
movq %rax, -0x148(%rbp)
cmpq $0x0, -0x148(%rbp)
jne 0xa4fe
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
jmp 0xaaf7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0xa4aa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x61b0
leaq -0xb8(%rbp), %rdi
callq 0xb1f0
jmp 0xab0c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0xa4ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x61b0
leaq -0x140(%rbp), %rdi
callq 0xb1f0
jmp 0xab0c
movq -0x148(%rbp), %rax
movq %rax, -0x470(%rbp)
leaq -0x250(%rbp), %rax
movq %rax, -0x468(%rbp)
movq -0x40(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x460(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x458(%rbp)
leaq -0x350(%rbp), %rax
movq %rax, -0x450(%rbp)
movq -0x40(%rbp), %rdi
addq $0x8, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xb210
movq %rax, -0x448(%rbp)
movq -0x40(%rbp), %rdi
addq $0x8, %rdi
movl $0x1, %esi
callq 0xb210
movq %rax, -0x440(%rbp)
movq -0x40(%rbp), %rdi
addq $0x8, %rdi
movl $0x2, %esi
callq 0xb210
movq %rax, -0x438(%rbp)
movq -0x40(%rbp), %rdi
addq $0x28, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xb210
movq %rax, -0x430(%rbp)
movq -0x40(%rbp), %rdi
addq $0x28, %rdi
movl $0x1, %esi
callq 0xb210
movq %rax, -0x428(%rbp)
movq -0x40(%rbp), %rdi
addq $0x28, %rdi
movl $0x2, %esi
callq 0xb210
movq %rax, -0x420(%rbp)
movq -0x40(%rbp), %rdi
addq $0x48, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xb210
movq %rax, -0x418(%rbp)
movq -0x40(%rbp), %rdi
addq $0x48, %rdi
movl $0x1, %esi
callq 0xb210
movq %rax, -0x410(%rbp)
movq -0x40(%rbp), %rdi
addq $0x48, %rdi
movl $0x2, %esi
callq 0xb210
movq %rax, -0x408(%rbp)
movq -0x40(%rbp), %rdi
addq $0x68, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xb210
movq %rax, -0x400(%rbp)
movq -0x40(%rbp), %rdi
addq $0x68, %rdi
movl $0x1, %esi
callq 0xb210
movq %rax, -0x3f8(%rbp)
movq -0x40(%rbp), %rdi
addq $0x68, %rdi
movl $0x2, %esi
callq 0xb210
movq %rax, -0x3f0(%rbp)
movq -0x40(%rbp), %rdi
addq $0x88, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xb210
movq %rax, -0x3e8(%rbp)
movq -0x40(%rbp), %rdi
addq $0x88, %rdi
movl $0x1, %esi
callq 0xb210
movq %rax, -0x3e0(%rbp)
movq -0x40(%rbp), %rdi
addq $0x88, %rdi
movl $0x2, %esi
callq 0xb210
movq %rax, -0x3d8(%rbp)
movq -0x40(%rbp), %rdi
addq $0xa8, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xb210
movq %rax, %r13
movq -0x40(%rbp), %rdi
addq $0xa8, %rdi
movl $0x1, %esi
callq 0xb210
movq %rax, %r12
movq -0x40(%rbp), %rdi
addq $0xa8, %rdi
movl $0x2, %esi
callq 0xb210
movq %rax, %r15
movq -0x40(%rbp), %rdi
addq $0xc8, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xb210
movq %rax, %r14
movq -0x40(%rbp), %rdi
addq $0xc8, %rdi
movl $0x1, %esi
callq 0xb210
movq %rax, %rbx
movq -0x40(%rbp), %rdi
addq $0xc8, %rdi
movl $0x2, %esi
callq 0xb210
movq -0x470(%rbp), %rdi
movq -0x468(%rbp), %rdx
movq -0x460(%rbp), %rcx
movq -0x458(%rbp), %r8
movq -0x450(%rbp), %r9
movq %rax, %r11
movq -0x448(%rbp), %rax
movq -0x40(%rbp), %r10
addq $0xe8, %r10
movq -0x40(%rbp), %rsi
addq $0xf0, %rsi
movq %rsi, -0x3d0(%rbp)
leaq 0x8163(%rip), %rsi      # 0x128fc
movq %rax, (%rsp)
movq -0x440(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0x438(%rbp), %rax
movq %rax, 0x10(%rsp)
movq -0x430(%rbp), %rax
movq %rax, 0x18(%rsp)
movq -0x428(%rbp), %rax
movq %rax, 0x20(%rsp)
movq -0x420(%rbp), %rax
movq %rax, 0x28(%rsp)
movq -0x418(%rbp), %rax
movq %rax, 0x30(%rsp)
movq -0x410(%rbp), %rax
movq %rax, 0x38(%rsp)
movq -0x408(%rbp), %rax
movq %rax, 0x40(%rsp)
movq -0x400(%rbp), %rax
movq %rax, 0x48(%rsp)
movq -0x3f8(%rbp), %rax
movq %rax, 0x50(%rsp)
movq -0x3f0(%rbp), %rax
movq %rax, 0x58(%rsp)
movq -0x3e8(%rbp), %rax
movq %rax, 0x60(%rsp)
movq -0x3e0(%rbp), %rax
movq %rax, 0x68(%rsp)
movq -0x3d8(%rbp), %rax
movq %rax, 0x70(%rsp)
movq -0x3d0(%rbp), %rax
movq %r13, 0x78(%rsp)
movq %r12, 0x80(%rsp)
movq %r15, 0x88(%rsp)
movq %r14, 0x90(%rsp)
movq %rbx, 0x98(%rsp)
movq %r11, 0xa0(%rsp)
movq %r10, 0xa8(%rsp)
movq %rax, 0xb0(%rsp)
movb $0x0, %al
callq 0x3420
movl %eax, -0x354(%rbp)
cmpl $0x1b, -0x354(%rbp)
je 0xa8ab
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
jmp 0xaaf7
leaq -0x3b8(%rbp), %rdi
movsd 0x774e(%rip), %xmm1     # 0x12008
movsd 0x800e(%rip), %xmm2     # 0x128d0
movaps %xmm1, %xmm0
callq 0xb240
movq -0x40(%rbp), %rdi
addq $0x8, %rdi
movl $0x2, %esi
callq 0x7bf0
movq %rax, -0x478(%rbp)
jmp 0xa8e5
movq -0x478(%rbp), %rax
movsd (%rax), %xmm0
movaps 0x7fe9(%rip), %xmm1     # 0x128e0
pxor %xmm1, %xmm0
movsd %xmm0, -0x488(%rbp)
movq -0x40(%rbp), %rdi
addq $0x8, %rdi
movl $0x2, %esi
callq 0x7bf0
movq %rax, -0x480(%rbp)
jmp 0xa91e
movq -0x480(%rbp), %rax
movsd -0x488(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x40(%rbp), %rdi
addq $0x48, %rdi
movl $0x2, %esi
callq 0x7bf0
movq %rax, -0x490(%rbp)
jmp 0xa94c
movq -0x490(%rbp), %rax
movsd (%rax), %xmm0
movaps 0x7f82(%rip), %xmm1     # 0x128e0
pxor %xmm1, %xmm0
movsd %xmm0, -0x4a0(%rbp)
movq -0x40(%rbp), %rdi
addq $0x48, %rdi
movl $0x2, %esi
callq 0x7bf0
movq %rax, -0x498(%rbp)
jmp 0xa985
movq -0x498(%rbp), %rax
movsd -0x4a0(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x40(%rbp), %rdi
addq $0x28, %rdi
movl $0x2, %esi
callq 0x7bf0
movq %rax, -0x4a8(%rbp)
jmp 0xa9b3
movq -0x4a8(%rbp), %rax
movsd (%rax), %xmm0
movaps 0x7f1b(%rip), %xmm1     # 0x128e0
pxor %xmm1, %xmm0
movsd %xmm0, -0x4b8(%rbp)
movq -0x40(%rbp), %rdi
addq $0x28, %rdi
movl $0x2, %esi
callq 0x7bf0
movq %rax, -0x4b0(%rbp)
jmp 0xa9ec
movq -0x4b0(%rbp), %rax
movsd -0x4b8(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x40(%rbp), %rdi
addq $0x68, %rdi
movl $0x2, %esi
callq 0x7bf0
movq %rax, -0x4c0(%rbp)
jmp 0xaa1a
movq -0x4c0(%rbp), %rax
movsd (%rax), %xmm0
movaps 0x7eb4(%rip), %xmm1     # 0x128e0
pxor %xmm1, %xmm0
movsd %xmm0, -0x4d0(%rbp)
movq -0x40(%rbp), %rdi
addq $0x68, %rdi
movl $0x2, %esi
callq 0x7bf0
movq %rax, -0x4c8(%rbp)
jmp 0xaa53
movq -0x4c8(%rbp), %rax
movsd -0x4d0(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x40(%rbp), %rbx
movq %rbx, -0x4d8(%rbp)
movl (%rbx), %edi
movl 0x4(%rbx), %esi
movq %rbx, %rdx
addq $0x8, %rdx
movq %rbx, %rcx
addq $0x28, %rcx
movq %rbx, %r8
addq $0x48, %r8
movq %rbx, %r9
addq $0x68, %r9
movq %rbx, %r10
addq $0xf8, %r10
movq %rbx, %r11
addq $0x158, %r11            # imm = 0x158
addq $0x1b8, %rbx            # imm = 0x1B8
movq %rsp, %rax
movq %rbx, 0x10(%rax)
movq %r11, 0x8(%rax)
movq %r10, (%rax)
callq 0xcc70
jmp 0xaac2
movl $0x0, -0x2c(%rbp)
leaq -0x3b8(%rbp), %rdi
callq 0x61b0
jmp 0xaaf7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x3b8(%rbp), %rdi
callq 0x61b0
jmp 0xab0c
movl -0x2c(%rbp), %eax
addq $0x568, %rsp            # imm = 0x568
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0xc0(%rbp), %rdi
callq 0x33e0
nopl (%rax,%rax)