void mat4_lookat(float m[4][4], const float eye[3], const float center[3],
                 const float up[3]) {
  float f[3], s[3], u[3], ret[4][4];
  mat4_set_identity(ret);
  vec3_sub(center, eye, f);
  vec3_normalize(f, f);
  vec3_cross(f, up, s);
  vec3_normalize(s, s);
  vec3_cross(s, f, u);
  vec3_normalize(u, u);
  vec3_copy(s, ret[0]);
  vec3_copy(u, ret[1]);
  vec3_neg(f, ret[2]);
  mat4_transpose(ret, ret);
  mat4_translate(ret, -eye[0], -eye[1], -eye[2], ret);
  mat4_copy(ret, m);
}


x86 assembly (clang, -O0):
<mat4_lookat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x90(%rbp),%rdi
mov    $0x0,%al
call   1060 <mat4_set_identity@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
mov    $0x0,%al
call   1080 <vec3_sub@plt>
lea    -0x2c(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
mov    $0x0,%al
call   10b0 <vec3_normalize@plt>
lea    -0x2c(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x38(%rbp),%rdx
mov    $0x0,%al
call   1040 <vec3_cross@plt>
lea    -0x38(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0x0,%al
call   10b0 <vec3_normalize@plt>
lea    -0x38(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
lea    -0x44(%rbp),%rdx
mov    $0x0,%al
call   1040 <vec3_cross@plt>
lea    -0x44(%rbp),%rdi
lea    -0x44(%rbp),%rsi
mov    $0x0,%al
call   10b0 <vec3_normalize@plt>
lea    -0x38(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x0,%al
call   1070 <vec3_copy@plt>
lea    -0x44(%rbp),%rdi
lea    -0x90(%rbp),%rsi
add    $0x10,%rsi
mov    $0x0,%al
call   1070 <vec3_copy@plt>
lea    -0x2c(%rbp),%rdi
lea    -0x90(%rbp),%rsi
add    $0x20,%rsi
mov    $0x0,%al
call   1090 <vec3_neg@plt>
lea    -0x90(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x0,%al
call   10a0 <mat4_transpose@plt>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x10(%rbp),%rax
movss  0x4(%rax),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
cvtss2sd %xmm1,%xmm1
mov    -0x10(%rbp),%rax
movss  0x8(%rax),%xmm2
movd   %xmm2,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm2
cvtss2sd %xmm2,%xmm2
lea    -0x90(%rbp),%rsi
mov    $0x3,%al
call   1030 <mat4_translate@plt>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <mat4_copy@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mat4_lookat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rcx,%r13
mov    %rdx,%rbp
mov    %rsi,%r14
mov    %rdi,(%rsp)
lea    0x30(%rsp),%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <mat4_set_identity@plt>
lea    0x24(%rsp),%r12
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1080 <vec3_sub@plt>
mov    %r12,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   10b0 <vec3_normalize@plt>
lea    0x18(%rsp),%rbp
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <vec3_cross@plt>
mov    %rbp,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   10b0 <vec3_normalize@plt>
lea    0xc(%rsp),%rbx
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <vec3_cross@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10b0 <vec3_normalize@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <vec3_copy@plt>
lea    0x40(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <vec3_copy@plt>
lea    0x50(%rsp),%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   1090 <vec3_neg@plt>
mov    %r15,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   10a0 <mat4_transpose@plt>
movss  (%r14),%xmm0
movss  0x4(%r14),%xmm1
movss  0x8(%r14),%xmm2
movaps 0xd90(%rip),%xmm3
xorps  %xmm3,%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm3,%xmm1
cvtss2sd %xmm1,%xmm1
xorps  %xmm3,%xmm2
cvtss2sd %xmm2,%xmm2
mov    %r15,%rdi
mov    %r15,%rsi
mov    $0x3,%al
call   1030 <mat4_translate@plt>
mov    %r15,%rdi
mov    (%rsp),%rsi
xor    %eax,%eax
call   1050 <mat4_copy@plt>
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @mat4_lookat([4 x float]* %0, float* %1, float* %2, float* %3) {
%5 = alloca [4 x 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 [4 x [4 x float]]
store [4 x float]* %0, [4 x float]** %5
store float* %1, float** %6
store float* %2, float** %7
store float* %3, float** %8
%13 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %12, i64 0, i64 0
%14 = call i32 ([4 x float]*, ...) bitcast (i32 (...)* @mat4_set_identity to i32 ([4 x float]*, ...)*)([4 x float]* %13)
%15 = load float*, float** %7
%16 = load float*, float** %6
%17 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%18 = call i32 (float*, float*, float*, ...) bitcast (i32 (...)* @vec3_sub to i32 (float*, float*, float*, ...)*)(float* %15, float* %16, float* %17)
%19 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%20 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%21 = call i32 (float*, float*, ...) bitcast (i32 (...)* @vec3_normalize to i32 (float*, float*, ...)*)(float* %19, float* %20)
%22 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%23 = load float*, float** %8
%24 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%25 = call i32 (float*, float*, float*, ...) bitcast (i32 (...)* @vec3_cross to i32 (float*, float*, float*, ...)*)(float* %22, float* %23, float* %24)
%26 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%27 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%28 = call i32 (float*, float*, ...) bitcast (i32 (...)* @vec3_normalize to i32 (float*, float*, ...)*)(float* %26, float* %27)
%29 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%30 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%31 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%32 = call i32 (float*, float*, float*, ...) bitcast (i32 (...)* @vec3_cross to i32 (float*, float*, float*, ...)*)(float* %29, float* %30, float* %31)
%33 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%34 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%35 = call i32 (float*, float*, ...) bitcast (i32 (...)* @vec3_normalize to i32 (float*, float*, ...)*)(float* %33, float* %34)
%36 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%37 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %12, i64 0, i64 0
%38 = getelementptr inbounds [4 x float], [4 x float]* %37, i64 0, i64 0
%39 = call i32 (float*, float*, ...) bitcast (i32 (...)* @vec3_copy to i32 (float*, float*, ...)*)(float* %36, float* %38)
%40 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%41 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %12, i64 0, i64 1
%42 = getelementptr inbounds [4 x float], [4 x float]* %41, i64 0, i64 0
%43 = call i32 (float*, float*, ...) bitcast (i32 (...)* @vec3_copy to i32 (float*, float*, ...)*)(float* %40, float* %42)
%44 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%45 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %12, i64 0, i64 2
%46 = getelementptr inbounds [4 x float], [4 x float]* %45, i64 0, i64 0
%47 = call i32 (float*, float*, ...) bitcast (i32 (...)* @vec3_neg to i32 (float*, float*, ...)*)(float* %44, float* %46)
%48 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %12, i64 0, i64 0
%49 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %12, i64 0, i64 0
%50 = call i32 ([4 x float]*, [4 x float]*, ...) bitcast (i32 (...)* @mat4_transpose to i32 ([4 x float]*, [4 x float]*, ...)*)([4 x float]* %48, [4 x float]* %49)
%51 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %12, i64 0, i64 0
%52 = load float*, float** %6
%53 = getelementptr inbounds float, float* %52, i64 0
%54 = load float, float* %53
%55 = fneg float %54
%56 = fpext float %55 to double
%57 = load float*, float** %6
%58 = getelementptr inbounds float, float* %57, i64 1
%59 = load float, float* %58
%60 = fneg float %59
%61 = fpext float %60 to double
%62 = load float*, float** %6
%63 = getelementptr inbounds float, float* %62, i64 2
%64 = load float, float* %63
%65 = fneg float %64
%66 = fpext float %65 to double
%67 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %12, i64 0, i64 0
%68 = call i32 ([4 x float]*, double, double, double, [4 x float]*, ...) bitcast (i32 (...)* @mat4_translate to i32 ([4 x float]*, double, double, double, [4 x float]*, ...)*)([4 x float]* %51, double %56, double %61, double %66, [4 x float]* %67)
%69 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %12, i64 0, i64 0
%70 = load [4 x float]*, [4 x float]** %5
%71 = call i32 ([4 x float]*, [4 x float]*, ...) bitcast (i32 (...)* @mat4_copy to i32 ([4 x float]*, [4 x float]*, ...)*)([4 x float]* %69, [4 x float]* %70)
ret void
}

LLVM IR (-O2):
define void @mat4_lookat([4 x 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 [4 x [4 x float]]
%9 = bitcast [3 x float]* %5 to i8*
%10 = bitcast [3 x float]* %6 to i8*
%11 = bitcast [3 x float]* %7 to i8*
%12 = bitcast [4 x [4 x float]]* %8 to i8*
%13 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %8, i64 0, i64 0
%14 = call i32 ([4 x float]*, ...) bitcast (i32 (...)* @mat4_set_identity to i32 ([4 x float]*, ...)*)([4 x float]* %13)
%15 = getelementptr inbounds [3 x float], [3 x float]* %5, i64 0, i64 0
%16 = call i32 (float*, float*, float*, ...) bitcast (i32 (...)* @vec3_sub to i32 (float*, float*, float*, ...)*)(float* %2, float* %1, float* %15)
%17 = call i32 (float*, float*, ...) bitcast (i32 (...)* @vec3_normalize to i32 (float*, float*, ...)*)(float* %15, float* %15)
%18 = getelementptr inbounds [3 x float], [3 x float]* %6, i64 0, i64 0
%19 = call i32 (float*, float*, float*, ...) bitcast (i32 (...)* @vec3_cross to i32 (float*, float*, float*, ...)*)(float* %15, float* %3, float* %18)
%20 = call i32 (float*, float*, ...) bitcast (i32 (...)* @vec3_normalize to i32 (float*, float*, ...)*)(float* %18, float* %18)
%21 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 0
%22 = call i32 (float*, float*, float*, ...) bitcast (i32 (...)* @vec3_cross to i32 (float*, float*, float*, ...)*)(float* %18, float* %15, float* %21)
%23 = call i32 (float*, float*, ...) bitcast (i32 (...)* @vec3_normalize to i32 (float*, float*, ...)*)(float* %21, float* %21)
%24 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %8, i64 0, i64 0, i64 0
%25 = call i32 (float*, float*, ...) bitcast (i32 (...)* @vec3_copy to i32 (float*, float*, ...)*)(float* %18, float* %24)
%26 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %8, i64 0, i64 1, i64 0
%27 = call i32 (float*, float*, ...) bitcast (i32 (...)* @vec3_copy to i32 (float*, float*, ...)*)(float* %21, float* %26)
%28 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %8, i64 0, i64 2, i64 0
%29 = call i32 (float*, float*, ...) bitcast (i32 (...)* @vec3_neg to i32 (float*, float*, ...)*)(float* %15, float* %28)
%30 = call i32 ([4 x float]*, [4 x float]*, ...) bitcast (i32 (...)* @mat4_transpose to i32 ([4 x float]*, [4 x float]*, ...)*)([4 x float]* %13, [4 x float]* %13)
%31 = load float, float* %1
%32 = fneg float %31
%33 = fpext float %32 to double
%34 = getelementptr inbounds float, float* %1, i64 1
%35 = load float, float* %34
%36 = fneg float %35
%37 = fpext float %36 to double
%38 = getelementptr inbounds float, float* %1, i64 2
%39 = load float, float* %38
%40 = fneg float %39
%41 = fpext float %40 to double
%42 = call i32 ([4 x float]*, double, double, double, [4 x float]*, ...) bitcast (i32 (...)* @mat4_translate to i32 ([4 x float]*, double, double, double, [4 x float]*, ...)*)([4 x float]* %13, double %33, double %37, double %41, [4 x float]* %13)
%43 = call i32 ([4 x float]*, [4 x float]*, ...) bitcast (i32 (...)* @mat4_copy to i32 ([4 x float]*, [4 x float]*, ...)*)([4 x float]* %13, [4 x float]* %0)
ret void
}