#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*/ finn_mat4_identity(float *);
int /*<<< orphan*/ finn_vec3_cross(float *, float *, float *);
float finn_vec3_dot(float *, float *);
int /*<<< orphan*/ finn_vec3_normalize(float *, float *);
int /*<<< orphan*/ finn_vec3_sub_vec3(float *, float *, float *);
void finn_mat4_look_at(float *result, float *eye, float *at, float *up) {
  float temp[3];
  float f[3];
  finn_vec3_sub_vec3(temp, at, eye);
  finn_vec3_normalize(f, temp);
  float s[3];
  finn_vec3_cross(temp, f, up);
  finn_vec3_normalize(s, temp);
  float u[3];
  finn_vec3_cross(u, s, f);
  float s_eye_dot = finn_vec3_dot(s, eye);
  float u_eye_dot = finn_vec3_dot(u, eye);
  float f_eye_dot = finn_vec3_dot(f, eye);
  finn_mat4_identity(result);
  result[0] = s[0];
  result[1] = s[1];
  result[2] = s[2];
  result[4] = u[0];
  result[5] = u[1];
  result[6] = u[2];
  result[8] = -f[0];
  result[9] = -f[1];
  result[10] = -f[2];
  result[12] = s_eye_dot;
  result[13] = u_eye_dot;
  result[14] = f_eye_dot;
  result[15] = 1.0f;
}


x86 assembly (clang, -O0):
<finn_mat4_look_at>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x2c(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <finn_vec3_sub_vec3@plt>
lea    -0x38(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1030 <finn_vec3_normalize@plt>
lea    -0x2c(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <finn_vec3_cross@plt>
lea    -0x44(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1030 <finn_vec3_normalize@plt>
lea    -0x50(%rbp),%rdi
lea    -0x44(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1060 <finn_vec3_cross@plt>
lea    -0x44(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <finn_vec3_dot@plt>
movss  %xmm0,-0x54(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <finn_vec3_dot@plt>
movss  %xmm0,-0x58(%rbp)
lea    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <finn_vec3_dot@plt>
movss  %xmm0,-0x5c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <finn_mat4_identity@plt>
movss  -0x44(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x40(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x4(%rax)
movss  -0x3c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x8(%rax)
movss  -0x50(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x10(%rax)
movss  -0x4c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x14(%rax)
movss  -0x48(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x18(%rax)
movss  -0x38(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x20(%rax)
movss  -0x34(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x24(%rax)
movss  -0x30(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x28(%rax)
movss  -0x54(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x30(%rax)
movss  -0x58(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x34(%rax)
movss  -0x5c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x38(%rax)
mov    -0x8(%rbp),%rax
movss  0xd32(%rip),%xmm0
movss  %xmm0,0x3c(%rax)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<finn_mat4_look_at>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rcx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x34(%rsp),%r13
mov    %r13,%rdi
mov    %rdx,%rsi
mov    %r14,%rdx
call   1040 <finn_vec3_sub_vec3@plt>
lea    0x28(%rsp),%r15
mov    %r15,%rdi
mov    %r13,%rsi
call   1030 <finn_vec3_normalize@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1060 <finn_vec3_cross@plt>
lea    0x1c(%rsp),%r12
mov    %r12,%rdi
mov    %r13,%rsi
call   1030 <finn_vec3_normalize@plt>
lea    0x10(%rsp),%r13
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1060 <finn_vec3_cross@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <finn_vec3_dot@plt>
movss  %xmm0,0xc(%rsp)
mov    %r13,%rdi
mov    %r14,%rsi
call   1070 <finn_vec3_dot@plt>
movss  %xmm0,0x8(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <finn_vec3_dot@plt>
movss  %xmm0,0x4(%rsp)
mov    %rbx,%rdi
call   1050 <finn_mat4_identity@plt>
movss  0x1c(%rsp),%xmm0
movss  %xmm0,(%rbx)
movss  0x20(%rsp),%xmm0
movss  %xmm0,0x4(%rbx)
movss  0x24(%rsp),%xmm0
movss  %xmm0,0x8(%rbx)
movss  0x10(%rsp),%xmm0
movss  %xmm0,0x10(%rbx)
movss  0x14(%rsp),%xmm0
movss  %xmm0,0x14(%rbx)
movss  0x18(%rsp),%xmm0
movss  %xmm0,0x18(%rbx)
movss  0x28(%rsp),%xmm0
movaps 0xdbd(%rip),%xmm1
xorps  %xmm1,%xmm0
movss  %xmm0,0x20(%rbx)
movss  0x2c(%rsp),%xmm0
xorps  %xmm1,%xmm0
movss  %xmm0,0x24(%rbx)
movss  0x30(%rsp),%xmm0
xorps  %xmm1,%xmm0
movss  %xmm0,0x28(%rbx)
movss  0xc(%rsp),%xmm0
movss  %xmm0,0x30(%rbx)
movss  0x8(%rsp),%xmm0
movss  %xmm0,0x34(%rbx)
movss  0x4(%rsp),%xmm0
movss  %xmm0,0x38(%rbx)
movl   $0x3f800000,0x3c(%rbx)
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @finn_mat4_look_at(float* %0, float* %1, float* %2, float* %3) {
%5 = alloca float*
%6 = alloca float*
%7 = alloca float*
%8 = alloca float*
%9 = alloca [3 x float]
%10 = alloca [3 x float]
%11 = alloca [3 x float]
%12 = alloca [3 x float]
%13 = alloca float
%14 = alloca float
%15 = alloca float
store float* %0, float** %5
store float* %1, float** %6
store float* %2, float** %7
store float* %3, float** %8
%16 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%17 = load float*, float** %7
%18 = load float*, float** %6
%19 = call i32 @finn_vec3_sub_vec3(float* %16, float* %17, float* %18)
%20 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%21 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%22 = call i32 @finn_vec3_normalize(float* %20, float* %21)
%23 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%24 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%25 = load float*, float** %8
%26 = call i32 @finn_vec3_cross(float* %23, float* %24, float* %25)
%27 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%28 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%29 = call i32 @finn_vec3_normalize(float* %27, float* %28)
%30 = getelementptr inbounds [3 x float], [3 x float]* %12, i64 0, i64 0
%31 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%32 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%33 = call i32 @finn_vec3_cross(float* %30, float* %31, float* %32)
%34 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%35 = load float*, float** %6
%36 = call float @finn_vec3_dot(float* %34, float* %35)
store float %36, float* %13
%37 = getelementptr inbounds [3 x float], [3 x float]* %12, i64 0, i64 0
%38 = load float*, float** %6
%39 = call float @finn_vec3_dot(float* %37, float* %38)
store float %39, float* %14
%40 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%41 = load float*, float** %6
%42 = call float @finn_vec3_dot(float* %40, float* %41)
store float %42, float* %15
%43 = load float*, float** %5
%44 = call i32 @finn_mat4_identity(float* %43)
%45 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%46 = load float, float* %45
%47 = load float*, float** %5
%48 = getelementptr inbounds float, float* %47, i64 0
store float %46, float* %48
%49 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 1
%50 = load float, float* %49
%51 = load float*, float** %5
%52 = getelementptr inbounds float, float* %51, i64 1
store float %50, float* %52
%53 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 2
%54 = load float, float* %53
%55 = load float*, float** %5
%56 = getelementptr inbounds float, float* %55, i64 2
store float %54, float* %56
%57 = getelementptr inbounds [3 x float], [3 x float]* %12, i64 0, i64 0
%58 = load float, float* %57
%59 = load float*, float** %5
%60 = getelementptr inbounds float, float* %59, i64 4
store float %58, float* %60
%61 = getelementptr inbounds [3 x float], [3 x float]* %12, i64 0, i64 1
%62 = load float, float* %61
%63 = load float*, float** %5
%64 = getelementptr inbounds float, float* %63, i64 5
store float %62, float* %64
%65 = getelementptr inbounds [3 x float], [3 x float]* %12, i64 0, i64 2
%66 = load float, float* %65
%67 = load float*, float** %5
%68 = getelementptr inbounds float, float* %67, i64 6
store float %66, float* %68
%69 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%70 = load float, float* %69
%71 = fneg float %70
%72 = load float*, float** %5
%73 = getelementptr inbounds float, float* %72, i64 8
store float %71, float* %73
%74 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 1
%75 = load float, float* %74
%76 = fneg float %75
%77 = load float*, float** %5
%78 = getelementptr inbounds float, float* %77, i64 9
store float %76, float* %78
%79 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 2
%80 = load float, float* %79
%81 = fneg float %80
%82 = load float*, float** %5
%83 = getelementptr inbounds float, float* %82, i64 10
store float %81, float* %83
%84 = load float, float* %13
%85 = load float*, float** %5
%86 = getelementptr inbounds float, float* %85, i64 12
store float %84, float* %86
%87 = load float, float* %14
%88 = load float*, float** %5
%89 = getelementptr inbounds float, float* %88, i64 13
store float %87, float* %89
%90 = load float, float* %15
%91 = load float*, float** %5
%92 = getelementptr inbounds float, float* %91, i64 14
store float %90, float* %92
%93 = load float*, float** %5
%94 = getelementptr inbounds float, float* %93, i64 15
store float 1.000000e+00, float* %94
ret void
}

LLVM IR (-O2):
define void @finn_mat4_look_at(float* %0, float* %1, float* %2, float* %3) {
%5 = alloca [3 x float]
%6 = alloca [3 x float]
%7 = alloca [3 x float]
%8 = alloca [3 x float]
%9 = bitcast [3 x float]* %5 to i8*
%10 = bitcast [3 x float]* %6 to i8*
%11 = getelementptr inbounds [3 x float], [3 x float]* %5, i64 0, i64 0
%12 = call i32 @finn_vec3_sub_vec3(float* %11, float* %2, float* %1)
%13 = getelementptr inbounds [3 x float], [3 x float]* %6, i64 0, i64 0
%14 = call i32 @finn_vec3_normalize(float* %13, float* %11)
%15 = bitcast [3 x float]* %7 to i8*
%16 = call i32 @finn_vec3_cross(float* %11, float* %13, float* %3)
%17 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 0
%18 = call i32 @finn_vec3_normalize(float* %17, float* %11)
%19 = bitcast [3 x float]* %8 to i8*
%20 = getelementptr inbounds [3 x float], [3 x float]* %8, i64 0, i64 0
%21 = call i32 @finn_vec3_cross(float* %20, float* %17, float* %13)
%22 = call float @finn_vec3_dot(float* %17, float* %1)
%23 = call float @finn_vec3_dot(float* %20, float* %1)
%24 = call float @finn_vec3_dot(float* %13, float* %1)
%25 = call i32 @finn_mat4_identity(float* %0)
%26 = load float, float* %17
store float %26, float* %0
%27 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 1
%28 = load float, float* %27
%29 = getelementptr inbounds float, float* %0, i64 1
store float %28, float* %29
%30 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 2
%31 = load float, float* %30
%32 = getelementptr inbounds float, float* %0, i64 2
store float %31, float* %32
%33 = load float, float* %20
%34 = getelementptr inbounds float, float* %0, i64 4
store float %33, float* %34
%35 = getelementptr inbounds [3 x float], [3 x float]* %8, i64 0, i64 1
%36 = load float, float* %35
%37 = getelementptr inbounds float, float* %0, i64 5
store float %36, float* %37
%38 = getelementptr inbounds [3 x float], [3 x float]* %8, i64 0, i64 2
%39 = load float, float* %38
%40 = getelementptr inbounds float, float* %0, i64 6
store float %39, float* %40
%41 = load float, float* %13
%42 = fneg float %41
%43 = getelementptr inbounds float, float* %0, i64 8
store float %42, float* %43
%44 = getelementptr inbounds [3 x float], [3 x float]* %6, i64 0, i64 1
%45 = load float, float* %44
%46 = fneg float %45
%47 = getelementptr inbounds float, float* %0, i64 9
store float %46, float* %47
%48 = getelementptr inbounds [3 x float], [3 x float]* %6, i64 0, i64 2
%49 = load float, float* %48
%50 = fneg float %49
%51 = getelementptr inbounds float, float* %0, i64 10
store float %50, float* %51
%52 = getelementptr inbounds float, float* %0, i64 12
store float %22, float* %52
%53 = getelementptr inbounds float, float* %0, i64 13
store float %23, float* %53
%54 = getelementptr inbounds float, float* %0, i64 14
store float %24, float* %54
%55 = getelementptr inbounds float, float* %0, i64 15
store float 1.000000e+00, float* %55
ret void
}