#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*/ vec3_cross(float *, float *, float const *);
float vec_dot(float *, float const *, int);
int /*<<< orphan*/ vec_norm(float *, float *, int);
void mat4_lookat(float out[16], const float eye[3], const float at[3],
                 const float up[3]) {
  float forward[3] = {at[0] - eye[0], at[1] - eye[1], at[2] - eye[2]};
  vec_norm(forward, forward, 3);
  float side[3];
  vec3_cross(side, forward, up);
  vec_norm(side, side, 3);
  float new_up[3];
  vec3_cross(new_up, side, forward);
  out[3] = out[7] = out[11] = 0.0f;
  out[0] = side[0];
  out[1] = new_up[0];
  out[2] = -forward[0];
  out[4] = side[1];
  out[5] = new_up[1];
  out[6] = -forward[1];
  out[8] = side[2];
  out[9] = new_up[2];
  out[10] = -forward[2];
  out[12] = -vec_dot(side, eye, 3);
  out[13] = -vec_dot(new_up, eye, 3);
  out[14] = vec_dot(forward, eye, 3);
  out[15] = 1.0f;
}


x86 assembly (clang, -O0):
<mat4_lookat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x10(%rbp),%rax
subss  (%rax),%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
movss  0x4(%rax),%xmm0
mov    -0x10(%rbp),%rax
subss  0x4(%rax),%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movss  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
subss  0x8(%rax),%xmm0
movss  %xmm0,-0x24(%rbp)
lea    -0x2c(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
mov    $0x3,%edx
call   1050 <vec_norm@plt>
lea    -0x38(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <vec3_cross@plt>
lea    -0x38(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0x3,%edx
call   1050 <vec_norm@plt>
lea    -0x44(%rbp),%rdi
lea    -0x38(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1040 <vec3_cross@plt>
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x2c(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x1c(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0xc(%rax)
movss  -0x38(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x44(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x4(%rax)
movss  -0x2c(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x8(%rax)
movss  -0x34(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x10(%rax)
movss  -0x40(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x14(%rax)
movss  -0x28(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x18(%rax)
movss  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x20(%rax)
movss  -0x3c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x24(%rax)
movss  -0x24(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x28(%rax)
lea    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x3,%edx
call   1030 <vec_dot@plt>
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x30(%rax)
lea    -0x44(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x3,%edx
call   1030 <vec_dot@plt>
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x34(%rax)
lea    -0x2c(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x3,%edx
call   1030 <vec_dot@plt>
mov    -0x8(%rbp),%rax
movss  %xmm0,0x38(%rax)
mov    -0x8(%rbp),%rax
movss  0xcf0(%rip),%xmm0
movss  %xmm0,0x3c(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mat4_lookat>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rcx,%r13
mov    %rsi,%r14
mov    %rdi,%rbx
movss  (%rdx),%xmm0
subss  (%rsi),%xmm0
movss  %xmm0,0xc(%rsp)
movss  0x4(%rdx),%xmm0
subss  0x4(%rsi),%xmm0
movss  %xmm0,0x10(%rsp)
movss  0x8(%rdx),%xmm0
subss  0x8(%rsi),%xmm0
movss  %xmm0,0x14(%rsp)
lea    0xc(%rsp),%r15
mov    %r15,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1050 <vec_norm@plt>
lea    0x24(%rsp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1040 <vec3_cross@plt>
mov    %r12,%rdi
mov    %r12,%rsi
mov    $0x3,%edx
call   1050 <vec_norm@plt>
lea    0x18(%rsp),%r13
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1040 <vec3_cross@plt>
movl   $0x0,0x2c(%rbx)
movl   $0x0,0x1c(%rbx)
movl   $0x0,0xc(%rbx)
movss  0x24(%rsp),%xmm0
movss  %xmm0,(%rbx)
movss  0x18(%rsp),%xmm0
movss  %xmm0,0x4(%rbx)
movss  0xc(%rsp),%xmm0
movaps 0xe0a(%rip),%xmm1
xorps  %xmm1,%xmm0
movss  %xmm0,0x8(%rbx)
movss  0x28(%rsp),%xmm0
movss  %xmm0,0x10(%rbx)
movss  0x1c(%rsp),%xmm0
movss  %xmm0,0x14(%rbx)
movss  0x10(%rsp),%xmm0
xorps  %xmm1,%xmm0
movss  %xmm0,0x18(%rbx)
movss  0x2c(%rsp),%xmm0
movss  %xmm0,0x20(%rbx)
movss  0x20(%rsp),%xmm0
movss  %xmm0,0x24(%rbx)
movss  0x14(%rsp),%xmm0
xorps  %xmm1,%xmm0
movss  %xmm0,0x28(%rbx)
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <vec_dot@plt>
xorps  0xda3(%rip),%xmm0
movss  %xmm0,0x30(%rbx)
mov    %r13,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <vec_dot@plt>
xorps  0xd87(%rip),%xmm0
movss  %xmm0,0x34(%rbx)
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <vec_dot@plt>
movss  %xmm0,0x38(%rbx)
movl   $0x3f800000,0x3c(%rbx)
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @mat4_lookat(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]
store float* %0, float** %5
store float* %1, float** %6
store float* %2, float** %7
store float* %3, float** %8
%12 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%13 = load float*, float** %7
%14 = getelementptr inbounds float, float* %13, i64 0
%15 = load float, float* %14
%16 = load float*, float** %6
%17 = getelementptr inbounds float, float* %16, i64 0
%18 = load float, float* %17
%19 = fsub float %15, %18
store float %19, float* %12
%20 = getelementptr inbounds float, float* %12, i64 1
%21 = load float*, float** %7
%22 = getelementptr inbounds float, float* %21, i64 1
%23 = load float, float* %22
%24 = load float*, float** %6
%25 = getelementptr inbounds float, float* %24, i64 1
%26 = load float, float* %25
%27 = fsub float %23, %26
store float %27, float* %20
%28 = getelementptr inbounds float, float* %20, i64 1
%29 = load float*, float** %7
%30 = getelementptr inbounds float, float* %29, i64 2
%31 = load float, float* %30
%32 = load float*, float** %6
%33 = getelementptr inbounds float, float* %32, i64 2
%34 = load float, float* %33
%35 = fsub float %31, %34
store float %35, float* %28
%36 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%37 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%38 = call i32 @vec_norm(float* %36, float* %37, i32 3)
%39 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%40 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%41 = load float*, float** %8
%42 = call i32 @vec3_cross(float* %39, float* %40, float* %41)
%43 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%44 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%45 = call i32 @vec_norm(float* %43, float* %44, i32 3)
%46 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%47 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%48 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%49 = call i32 @vec3_cross(float* %46, float* %47, float* %48)
%50 = load float*, float** %5
%51 = getelementptr inbounds float, float* %50, i64 11
store float 0.000000e+00, float* %51
%52 = load float*, float** %5
%53 = getelementptr inbounds float, float* %52, i64 7
store float 0.000000e+00, float* %53
%54 = load float*, float** %5
%55 = getelementptr inbounds float, float* %54, i64 3
store float 0.000000e+00, float* %55
%56 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%57 = load float, float* %56
%58 = load float*, float** %5
%59 = getelementptr inbounds float, float* %58, i64 0
store float %57, float* %59
%60 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%61 = load float, float* %60
%62 = load float*, float** %5
%63 = getelementptr inbounds float, float* %62, i64 1
store float %61, float* %63
%64 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%65 = load float, float* %64
%66 = fneg float %65
%67 = load float*, float** %5
%68 = getelementptr inbounds float, float* %67, i64 2
store float %66, float* %68
%69 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 1
%70 = load float, float* %69
%71 = load float*, float** %5
%72 = getelementptr inbounds float, float* %71, i64 4
store float %70, float* %72
%73 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 1
%74 = load float, float* %73
%75 = load float*, float** %5
%76 = getelementptr inbounds float, float* %75, i64 5
store float %74, float* %76
%77 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 1
%78 = load float, float* %77
%79 = fneg float %78
%80 = load float*, float** %5
%81 = getelementptr inbounds float, float* %80, i64 6
store float %79, float* %81
%82 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 2
%83 = load float, float* %82
%84 = load float*, float** %5
%85 = getelementptr inbounds float, float* %84, i64 8
store float %83, float* %85
%86 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 2
%87 = load float, float* %86
%88 = load float*, float** %5
%89 = getelementptr inbounds float, float* %88, i64 9
store float %87, float* %89
%90 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 2
%91 = load float, float* %90
%92 = fneg float %91
%93 = load float*, float** %5
%94 = getelementptr inbounds float, float* %93, i64 10
store float %92, float* %94
%95 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%96 = load float*, float** %6
%97 = call float @vec_dot(float* %95, float* %96, i32 3)
%98 = fneg float %97
%99 = load float*, float** %5
%100 = getelementptr inbounds float, float* %99, i64 12
store float %98, float* %100
%101 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%102 = load float*, float** %6
%103 = call float @vec_dot(float* %101, float* %102, i32 3)
%104 = fneg float %103
%105 = load float*, float** %5
%106 = getelementptr inbounds float, float* %105, i64 13
store float %104, float* %106
%107 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%108 = load float*, float** %6
%109 = call float @vec_dot(float* %107, float* %108, i32 3)
%110 = load float*, float** %5
%111 = getelementptr inbounds float, float* %110, i64 14
store float %109, float* %111
%112 = load float*, float** %5
%113 = getelementptr inbounds float, float* %112, i64 15
store float 1.000000e+00, float* %113
ret void
}

LLVM IR (-O2):
define void @mat4_lookat(float* nocapture writeonly %0, float* %1, float* nocapture %2, float* %3) {
%5 = alloca [3 x float]
%6 = alloca [3 x float]
%7 = alloca [3 x float]
%8 = bitcast [3 x float]* %5 to i8*
%9 = getelementptr inbounds [3 x float], [3 x float]* %5, i64 0, i64 0
%10 = load float, float* %2
%11 = load float, float* %1
%12 = fsub float %10, %11
store float %12, float* %9
%13 = getelementptr inbounds [3 x float], [3 x float]* %5, i64 0, i64 1
%14 = getelementptr inbounds float, float* %2, i64 1
%15 = load float, float* %14
%16 = getelementptr inbounds float, float* %1, i64 1
%17 = load float, float* %16
%18 = fsub float %15, %17
store float %18, float* %13
%19 = getelementptr inbounds [3 x float], [3 x float]* %5, i64 0, i64 2
%20 = getelementptr inbounds float, float* %2, i64 2
%21 = load float, float* %20
%22 = getelementptr inbounds float, float* %1, i64 2
%23 = load float, float* %22
%24 = fsub float %21, %23
store float %24, float* %19
%25 = call i32 @vec_norm(float* %9, float* %9, i32 3)
%26 = bitcast [3 x float]* %6 to i8*
%27 = getelementptr inbounds [3 x float], [3 x float]* %6, i64 0, i64 0
%28 = call i32 @vec3_cross(float* %27, float* %9, float* %3)
%29 = call i32 @vec_norm(float* %27, float* %27, i32 3)
%30 = bitcast [3 x float]* %7 to i8*
%31 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 0
%32 = call i32 @vec3_cross(float* %31, float* %27, float* %9)
%33 = getelementptr inbounds float, float* %0, i64 11
store float 0.000000e+00, float* %33
%34 = getelementptr inbounds float, float* %0, i64 7
store float 0.000000e+00, float* %34
%35 = getelementptr inbounds float, float* %0, i64 3
store float 0.000000e+00, float* %35
%36 = load float, float* %27
store float %36, float* %0
%37 = load float, float* %31
%38 = getelementptr inbounds float, float* %0, i64 1
store float %37, float* %38
%39 = load float, float* %9
%40 = fneg float %39
%41 = getelementptr inbounds float, float* %0, i64 2
store float %40, float* %41
%42 = getelementptr inbounds [3 x float], [3 x float]* %6, i64 0, i64 1
%43 = load float, float* %42
%44 = getelementptr inbounds float, float* %0, i64 4
store float %43, float* %44
%45 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 1
%46 = load float, float* %45
%47 = getelementptr inbounds float, float* %0, i64 5
store float %46, float* %47
%48 = load float, float* %13
%49 = fneg float %48
%50 = getelementptr inbounds float, float* %0, i64 6
store float %49, float* %50
%51 = getelementptr inbounds [3 x float], [3 x float]* %6, i64 0, i64 2
%52 = load float, float* %51
%53 = getelementptr inbounds float, float* %0, i64 8
store float %52, float* %53
%54 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 2
%55 = load float, float* %54
%56 = getelementptr inbounds float, float* %0, i64 9
store float %55, float* %56
%57 = load float, float* %19
%58 = fneg float %57
%59 = getelementptr inbounds float, float* %0, i64 10
store float %58, float* %59
%60 = call float @vec_dot(float* %27, float* %1, i32 3)
%61 = fneg float %60
%62 = getelementptr inbounds float, float* %0, i64 12
store float %61, float* %62
%63 = call float @vec_dot(float* %31, float* %1, i32 3)
%64 = fneg float %63
%65 = getelementptr inbounds float, float* %0, i64 13
store float %64, float* %65
%66 = call float @vec_dot(float* %9, float* %1, i32 3)
%67 = getelementptr inbounds float, float* %0, i64 14
store float %66, float* %67
%68 = getelementptr inbounds float, float* %0, i64 15
store float 1.000000e+00, float* %68
ret void
}