#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*/ CrossProd3fv(float *, float const *, float *);
float DotProd3fv(float *, float const *);
int /*<<< orphan*/ Normalize3fv(float *);
int /*<<< orphan*/ Subtract3fv(float *, float const *, float const *);
float *LookAt(float *M, const float Eye[3], const float LookAtPt[3],
              const float ViewUp[3]) {
  float X[3], Y[3], Z[3];
  Subtract3fv(Z, Eye, LookAtPt);
  Normalize3fv(Z);
  CrossProd3fv(X, ViewUp, Z);
  Normalize3fv(X);
  CrossProd3fv(Y, Z, X);
  Normalize3fv(Y);
  M[0] = X[0];
  M[4] = X[1];
  M[8] = X[2];
  M[12] = -DotProd3fv(X, Eye);
  M[1] = Y[0];
  M[5] = Y[1];
  M[9] = Y[2];
  M[13] = -DotProd3fv(Y, Eye);
  M[2] = Z[0];
  M[6] = Z[1];
  M[10] = Z[2];
  M[14] = -DotProd3fv(Z, Eye);
  M[3] = 0;
  M[7] = 0;
  M[11] = 0;
  M[15] = 1;
  return (M);
}


x86 assembly (clang, -O0):
<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)
lea    -0x44(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <Subtract3fv@plt>
lea    -0x44(%rbp),%rdi
call   1050 <Normalize3fv@plt>
lea    -0x2c(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x44(%rbp),%rdx
call   1040 <CrossProd3fv@plt>
lea    -0x2c(%rbp),%rdi
call   1050 <Normalize3fv@plt>
lea    -0x38(%rbp),%rdi
lea    -0x44(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1040 <CrossProd3fv@plt>
lea    -0x38(%rbp),%rdi
call   1050 <Normalize3fv@plt>
movss  -0x2c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x10(%rax)
movss  -0x24(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x20(%rax)
lea    -0x2c(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <DotProd3fv@plt>
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x30(%rax)
movss  -0x38(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x4(%rax)
movss  -0x34(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x14(%rax)
movss  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x24(%rax)
lea    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <DotProd3fv@plt>
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x34(%rax)
movss  -0x44(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x8(%rax)
movss  -0x40(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x18(%rax)
movss  -0x3c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x28(%rax)
lea    -0x44(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <DotProd3fv@plt>
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x38(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0xc(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x1c(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x2c(%rax)
mov    -0x8(%rbp),%rax
movss  0xd44(%rip),%xmm0
movss  %xmm0,0x3c(%rax)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LookAt>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rcx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xc(%rsp),%r15
mov    %r15,%rdi
call   1030 <Subtract3fv@plt>
mov    %r15,%rdi
call   1050 <Normalize3fv@plt>
lea    0x24(%rsp),%r13
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1040 <CrossProd3fv@plt>
mov    %r13,%rdi
call   1050 <Normalize3fv@plt>
lea    0x18(%rsp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1040 <CrossProd3fv@plt>
mov    %r12,%rdi
call   1050 <Normalize3fv@plt>
movss  0x24(%rsp),%xmm0
movss  %xmm0,(%rbx)
movss  0x28(%rsp),%xmm0
movss  %xmm0,0x10(%rbx)
movss  0x2c(%rsp),%xmm0
movss  %xmm0,0x20(%rbx)
mov    %r13,%rdi
mov    %r14,%rsi
call   1060 <DotProd3fv@plt>
xorps  0xe2d(%rip),%xmm0
movss  %xmm0,0x30(%rbx)
movss  0x18(%rsp),%xmm0
movss  %xmm0,0x4(%rbx)
movss  0x1c(%rsp),%xmm0
movss  %xmm0,0x14(%rbx)
movss  0x20(%rsp),%xmm0
movss  %xmm0,0x24(%rbx)
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <DotProd3fv@plt>
xorps  0xdf5(%rip),%xmm0
movss  %xmm0,0x34(%rbx)
movss  0xc(%rsp),%xmm0
movss  %xmm0,0x8(%rbx)
movss  0x10(%rsp),%xmm0
movss  %xmm0,0x18(%rbx)
movss  0x14(%rsp),%xmm0
movss  %xmm0,0x28(%rbx)
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <DotProd3fv@plt>
xorps  0xdbd(%rip),%xmm0
movss  %xmm0,0x38(%rbx)
movl   $0x0,0xc(%rbx)
movl   $0x0,0x1c(%rbx)
movl   $0x0,0x2c(%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* @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]* %11, i64 0, i64 0
%13 = load float*, float** %6
%14 = load float*, float** %7
%15 = call i32 @Subtract3fv(float* %12, float* %13, float* %14)
%16 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%17 = call i32 @Normalize3fv(float* %16)
%18 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%19 = load float*, float** %8
%20 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%21 = call i32 @CrossProd3fv(float* %18, float* %19, float* %20)
%22 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%23 = call i32 @Normalize3fv(float* %22)
%24 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%25 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%26 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%27 = call i32 @CrossProd3fv(float* %24, float* %25, float* %26)
%28 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%29 = call i32 @Normalize3fv(float* %28)
%30 = getelementptr inbounds [3 x float], [3 x float]* %9, 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]* %9, i64 0, i64 1
%35 = load float, float* %34
%36 = load float*, float** %5
%37 = getelementptr inbounds float, float* %36, i64 4
store float %35, float* %37
%38 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 2
%39 = load float, float* %38
%40 = load float*, float** %5
%41 = getelementptr inbounds float, float* %40, i64 8
store float %39, float* %41
%42 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%43 = load float*, float** %6
%44 = call float @DotProd3fv(float* %42, float* %43)
%45 = fneg float %44
%46 = load float*, float** %5
%47 = getelementptr inbounds float, float* %46, i64 12
store float %45, float* %47
%48 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%49 = load float, float* %48
%50 = load float*, float** %5
%51 = getelementptr inbounds float, float* %50, i64 1
store float %49, float* %51
%52 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 1
%53 = load float, float* %52
%54 = load float*, float** %5
%55 = getelementptr inbounds float, float* %54, i64 5
store float %53, float* %55
%56 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 2
%57 = load float, float* %56
%58 = load float*, float** %5
%59 = getelementptr inbounds float, float* %58, i64 9
store float %57, float* %59
%60 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%61 = load float*, float** %6
%62 = call float @DotProd3fv(float* %60, float* %61)
%63 = fneg float %62
%64 = load float*, float** %5
%65 = getelementptr inbounds float, float* %64, i64 13
store float %63, float* %65
%66 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%67 = load float, float* %66
%68 = load float*, float** %5
%69 = getelementptr inbounds float, float* %68, i64 2
store float %67, float* %69
%70 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 1
%71 = load float, float* %70
%72 = load float*, float** %5
%73 = getelementptr inbounds float, float* %72, i64 6
store float %71, float* %73
%74 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 2
%75 = load float, float* %74
%76 = load float*, float** %5
%77 = getelementptr inbounds float, float* %76, i64 10
store float %75, float* %77
%78 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%79 = load float*, float** %6
%80 = call float @DotProd3fv(float* %78, float* %79)
%81 = fneg float %80
%82 = load float*, float** %5
%83 = getelementptr inbounds float, float* %82, i64 14
store float %81, float* %83
%84 = load float*, float** %5
%85 = getelementptr inbounds float, float* %84, i64 3
store float 0.000000e+00, float* %85
%86 = load float*, float** %5
%87 = getelementptr inbounds float, float* %86, i64 7
store float 0.000000e+00, float* %87
%88 = load float*, float** %5
%89 = getelementptr inbounds float, float* %88, i64 11
store float 0.000000e+00, float* %89
%90 = load float*, float** %5
%91 = getelementptr inbounds float, float* %90, i64 15
store float 1.000000e+00, float* %91
%92 = load float*, float** %5
ret float* %92
}

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