#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ mat3d_from_mat4d(double *, double const *);
int /*<<< orphan*/ mat4d_from_mat3d(double *, double *);
int /*<<< orphan*/ mat4d_getColumn(double *, double *, int);
int /*<<< orphan*/ mat4d_getRow(double *, double const *, int);
int /*<<< orphan*/ mat4d_invert(double *);
int /*<<< orphan*/ mat4d_mult_mat4d_new(double *, double *, double const *);
int /*<<< orphan*/ vec3d_copy(double *, double *);
int /*<<< orphan*/ vec3d_scalarMult_new(double *, double *, int);
int /*<<< orphan*/ vec3d_sub_new(double *, double *, double *);
void mat4d_viewmat_to_lookatVec(const double viewmat[16], double eye[3],
                                double center[3], double up[3]) {
  double rotation3[9], rotation4[16];
  mat3d_from_mat4d(rotation3, viewmat);
  mat4d_from_mat3d(rotation4, rotation3);
  mat4d_invert(rotation4);
  double transOnly[16];
  mat4d_mult_mat4d_new(transOnly, rotation4, viewmat);
  double transVec[4];
  mat4d_getColumn(transVec, transOnly, 3);
  vec3d_scalarMult_new(eye, transVec, -1);
  double upVec[4];
  mat4d_getRow(upVec, viewmat, 1);
  vec3d_copy(up, upVec);
  double lookVec[4];
  mat4d_getRow(lookVec, viewmat, 2);
  vec3d_sub_new(center, eye, lookVec);
}


x86 assembly (clang, -O0):
<mat4d_viewmat_to_lookatVec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1d0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10a0 <mat3d_from_mat4d@plt>
lea    -0xf0(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1050 <mat4d_from_mat3d@plt>
lea    -0xf0(%rbp),%rdi
call   10b0 <mat4d_invert@plt>
lea    -0x170(%rbp),%rdi
lea    -0xf0(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1060 <mat4d_mult_mat4d_new@plt>
lea    -0x190(%rbp),%rdi
lea    -0x170(%rbp),%rsi
mov    $0x3,%edx
call   1040 <mat4d_getColumn@plt>
mov    -0x10(%rbp),%rdi
lea    -0x190(%rbp),%rsi
mov    $0xffffffff,%edx
call   1070 <vec3d_scalarMult_new@plt>
lea    -0x1b0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x1,%edx
call   1030 <mat4d_getRow@plt>
mov    -0x20(%rbp),%rdi
lea    -0x1b0(%rbp),%rsi
call   1080 <vec3d_copy@plt>
lea    -0x1d0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x2,%edx
call   1030 <mat4d_getRow@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x1d0(%rbp),%rdx
call   1090 <vec3d_sub_new@plt>
add    $0x1d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mat4d_viewmat_to_lookatVec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1b8,%rsp
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x60(%rsp),%r13
mov    %r13,%rdi
mov    %rbx,%rsi
call   10a0 <mat3d_from_mat4d@plt>
lea    0x130(%rsp),%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
call   1050 <mat4d_from_mat3d@plt>
mov    %rbp,%rdi
call   10b0 <mat4d_invert@plt>
lea    0xb0(%rsp),%r13
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1060 <mat4d_mult_mat4d_new@plt>
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
mov    $0x3,%edx
call   1040 <mat4d_getColumn@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    $0xffffffff,%edx
call   1070 <vec3d_scalarMult_new@plt>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <mat4d_getRow@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
call   1080 <vec3d_copy@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1030 <mat4d_getRow@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1090 <vec3d_sub_new@plt>
add    $0x1b8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @mat4d_viewmat_to_lookatVec(double* %0, double* %1, double* %2, double* %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca [9 x double]
%10 = alloca [16 x double]
%11 = alloca [16 x double]
%12 = alloca [4 x double]
%13 = alloca [4 x double]
%14 = alloca [4 x double]
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %8
%15 = getelementptr inbounds [9 x double], [9 x double]* %9, i64 0, i64 0
%16 = load double*, double** %5
%17 = call i32 @mat3d_from_mat4d(double* %15, double* %16)
%18 = getelementptr inbounds [16 x double], [16 x double]* %10, i64 0, i64 0
%19 = getelementptr inbounds [9 x double], [9 x double]* %9, i64 0, i64 0
%20 = call i32 @mat4d_from_mat3d(double* %18, double* %19)
%21 = getelementptr inbounds [16 x double], [16 x double]* %10, i64 0, i64 0
%22 = call i32 @mat4d_invert(double* %21)
%23 = getelementptr inbounds [16 x double], [16 x double]* %11, i64 0, i64 0
%24 = getelementptr inbounds [16 x double], [16 x double]* %10, i64 0, i64 0
%25 = load double*, double** %5
%26 = call i32 @mat4d_mult_mat4d_new(double* %23, double* %24, double* %25)
%27 = getelementptr inbounds [4 x double], [4 x double]* %12, i64 0, i64 0
%28 = getelementptr inbounds [16 x double], [16 x double]* %11, i64 0, i64 0
%29 = call i32 @mat4d_getColumn(double* %27, double* %28, i32 3)
%30 = load double*, double** %6
%31 = getelementptr inbounds [4 x double], [4 x double]* %12, i64 0, i64 0
%32 = call i32 @vec3d_scalarMult_new(double* %30, double* %31, i32 -1)
%33 = getelementptr inbounds [4 x double], [4 x double]* %13, i64 0, i64 0
%34 = load double*, double** %5
%35 = call i32 @mat4d_getRow(double* %33, double* %34, i32 1)
%36 = load double*, double** %8
%37 = getelementptr inbounds [4 x double], [4 x double]* %13, i64 0, i64 0
%38 = call i32 @vec3d_copy(double* %36, double* %37)
%39 = getelementptr inbounds [4 x double], [4 x double]* %14, i64 0, i64 0
%40 = load double*, double** %5
%41 = call i32 @mat4d_getRow(double* %39, double* %40, i32 2)
%42 = load double*, double** %7
%43 = load double*, double** %6
%44 = getelementptr inbounds [4 x double], [4 x double]* %14, i64 0, i64 0
%45 = call i32 @vec3d_sub_new(double* %42, double* %43, double* %44)
ret void
}

LLVM IR (-O2):
define void @mat4d_viewmat_to_lookatVec(double* %0, double* %1, double* %2, double* %3) {
%5 = alloca [9 x double]
%6 = alloca [16 x double]
%7 = alloca [16 x double]
%8 = alloca [4 x double]
%9 = alloca [4 x double]
%10 = alloca [4 x double]
%11 = bitcast [9 x double]* %5 to i8*
%12 = bitcast [16 x double]* %6 to i8*
%13 = getelementptr inbounds [9 x double], [9 x double]* %5, i64 0, i64 0
%14 = call i32 @mat3d_from_mat4d(double* %13, double* %0)
%15 = getelementptr inbounds [16 x double], [16 x double]* %6, i64 0, i64 0
%16 = call i32 @mat4d_from_mat3d(double* %15, double* %13)
%17 = call i32 @mat4d_invert(double* %15)
%18 = bitcast [16 x double]* %7 to i8*
%19 = getelementptr inbounds [16 x double], [16 x double]* %7, i64 0, i64 0
%20 = call i32 @mat4d_mult_mat4d_new(double* %19, double* %15, double* %0)
%21 = bitcast [4 x double]* %8 to i8*
%22 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 0
%23 = call i32 @mat4d_getColumn(double* %22, double* %19, i32 3)
%24 = call i32 @vec3d_scalarMult_new(double* %1, double* %22, i32 -1)
%25 = bitcast [4 x double]* %9 to i8*
%26 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%27 = call i32 @mat4d_getRow(double* %26, double* %0, i32 1)
%28 = call i32 @vec3d_copy(double* %3, double* %26)
%29 = bitcast [4 x double]* %10 to i8*
%30 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 0
%31 = call i32 @mat4d_getRow(double* %30, double* %0, i32 2)
%32 = call i32 @vec3d_sub_new(double* %2, double* %1, double* %30)
ret void
}