#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 *);
float vec3_dot(float *, float *);
int /*<<< orphan*/ vec3_normalize(float *, float *);
int /*<<< orphan*/ vec3_subtract(float *, float *, float *);
float *mat4_look_at(float *result, float *position, float *target, float *up) {
  float tmp_forward[3];
  float tmp_side[3];
  float tmp_up[3];
  vec3_subtract(tmp_forward, target, position);
  vec3_normalize(tmp_forward, tmp_forward);
  vec3_cross(tmp_side, tmp_forward, up);
  vec3_normalize(tmp_side, tmp_side);
  vec3_cross(tmp_up, tmp_side, tmp_forward);
  result[0] = tmp_side[0];
  result[1] = tmp_up[0];
  result[2] = -tmp_forward[0];
  result[3] = 0.0f;
  result[4] = tmp_side[1];
  result[5] = tmp_up[1];
  result[6] = -tmp_forward[1];
  result[7] = 0.0f;
  result[8] = tmp_side[2];
  result[9] = tmp_up[2];
  result[10] = -tmp_forward[2];
  result[11] = 0.0f;
  result[12] = -vec3_dot(tmp_side, position);
  result[13] = -vec3_dot(tmp_up, position);
  result[14] = vec3_dot(tmp_forward, position);
  result[15] = 1.0f;
  return result;
}


x86 assembly (clang, -O0):
<mat4_look_at>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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   1030 <vec3_subtract@plt>
lea    -0x2c(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1060 <vec3_normalize@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
call   1060 <vec3_normalize@plt>
lea    -0x44(%rbp),%rdi
lea    -0x38(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1040 <vec3_cross@plt>
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)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0xc(%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)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x1c(%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)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x2c(%rax)
lea    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <vec3_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
call   1050 <vec3_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
call   1050 <vec3_dot@plt>
mov    -0x8(%rbp),%rax
movss  %xmm0,0x38(%rax)
mov    -0x8(%rbp),%rax
movss  0xd2b(%rip),%xmm0
movss  %xmm0,0x3c(%rax)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mat4_look_at>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rcx,%r13
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x24(%rsp),%r15
mov    %r15,%rdi
mov    %rdx,%rsi
mov    %r14,%rdx
call   1030 <vec3_subtract@plt>
mov    %r15,%rdi
mov    %r15,%rsi
call   1060 <vec3_normalize@plt>
lea    0x18(%rsp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1040 <vec3_cross@plt>
mov    %r12,%rdi
mov    %r12,%rsi
call   1060 <vec3_normalize@plt>
lea    0xc(%rsp),%r13
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1040 <vec3_cross@plt>
movss  0x18(%rsp),%xmm0
movss  %xmm0,(%rbx)
movss  0xc(%rsp),%xmm0
movss  %xmm0,0x4(%rbx)
movss  0x24(%rsp),%xmm0
movaps 0xe39(%rip),%xmm1
xorps  %xmm1,%xmm0
movss  %xmm0,0x8(%rbx)
movl   $0x0,0xc(%rbx)
movss  0x1c(%rsp),%xmm0
movss  %xmm0,0x10(%rbx)
movss  0x10(%rsp),%xmm0
movss  %xmm0,0x14(%rbx)
movss  0x28(%rsp),%xmm0
xorps  %xmm1,%xmm0
movss  %xmm0,0x18(%rbx)
movl   $0x0,0x1c(%rbx)
movss  0x20(%rsp),%xmm0
movss  %xmm0,0x20(%rbx)
movss  0x14(%rsp),%xmm0
movss  %xmm0,0x24(%rbx)
movss  0x2c(%rsp),%xmm0
xorps  %xmm1,%xmm0
movss  %xmm0,0x28(%rbx)
movl   $0x0,0x2c(%rbx)
mov    %r12,%rdi
mov    %r14,%rsi
call   1050 <vec3_dot@plt>
xorps  0xdc2(%rip),%xmm0
movss  %xmm0,0x30(%rbx)
mov    %r13,%rdi
mov    %r14,%rsi
call   1050 <vec3_dot@plt>
xorps  0xdab(%rip),%xmm0
movss  %xmm0,0x34(%rbx)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <vec3_dot@plt>
movss  %xmm0,0x38(%rbx)
movl   $0x3f800000,0x3c(%rbx)
mov    %rbx,%rax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define float* @mat4_look_at(float* returned writeonly %0, float* %1, float* %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 = bitcast [3 x float]* %6 to i8*
%10 = bitcast [3 x float]* %7 to i8*
%11 = getelementptr inbounds [3 x float], [3 x float]* %5, i64 0, i64 0
%12 = call i32 @vec3_subtract(float* %11, float* %2, float* %1)
%13 = call i32 @vec3_normalize(float* %11, float* %11)
%14 = getelementptr inbounds [3 x float], [3 x float]* %6, i64 0, i64 0
%15 = call i32 @vec3_cross(float* %14, float* %11, float* %3)
%16 = call i32 @vec3_normalize(float* %14, float* %14)
%17 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 0
%18 = call i32 @vec3_cross(float* %17, float* %14, float* %11)
%19 = load float, float* %14
store float %19, float* %0
%20 = load float, float* %17
%21 = getelementptr inbounds float, float* %0, i64 1
store float %20, float* %21
%22 = load float, float* %11
%23 = fneg float %22
%24 = getelementptr inbounds float, float* %0, i64 2
store float %23, float* %24
%25 = getelementptr inbounds float, float* %0, i64 3
store float 0.000000e+00, float* %25
%26 = getelementptr inbounds [3 x float], [3 x float]* %6, i64 0, i64 1
%27 = load float, float* %26
%28 = getelementptr inbounds float, float* %0, i64 4
store float %27, float* %28
%29 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 1
%30 = load float, float* %29
%31 = getelementptr inbounds float, float* %0, i64 5
store float %30, float* %31
%32 = getelementptr inbounds [3 x float], [3 x float]* %5, i64 0, i64 1
%33 = load float, float* %32
%34 = fneg float %33
%35 = getelementptr inbounds float, float* %0, i64 6
store float %34, float* %35
%36 = getelementptr inbounds float, float* %0, i64 7
store float 0.000000e+00, float* %36
%37 = getelementptr inbounds [3 x float], [3 x float]* %6, i64 0, i64 2
%38 = load float, float* %37
%39 = getelementptr inbounds float, float* %0, i64 8
store float %38, float* %39
%40 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 2
%41 = load float, float* %40
%42 = getelementptr inbounds float, float* %0, i64 9
store float %41, float* %42
%43 = getelementptr inbounds [3 x float], [3 x float]* %5, i64 0, i64 2
%44 = load float, float* %43
%45 = fneg float %44
%46 = getelementptr inbounds float, float* %0, i64 10
store float %45, float* %46
%47 = getelementptr inbounds float, float* %0, i64 11
store float 0.000000e+00, float* %47
%48 = call float @vec3_dot(float* %14, float* %1)
%49 = fneg float %48
%50 = getelementptr inbounds float, float* %0, i64 12
store float %49, float* %50
%51 = call float @vec3_dot(float* %17, float* %1)
%52 = fneg float %51
%53 = getelementptr inbounds float, float* %0, i64 13
store float %52, float* %53
%54 = call float @vec3_dot(float* %11, float* %1)
%55 = getelementptr inbounds float, float* %0, i64 14
store float %54, float* %55
%56 = getelementptr inbounds float, float* %0, i64 15
store float 1.000000e+00, float* %56
ret float* %0
}