#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*/ memset(float *, int /*<<< orphan*/, int);
float tan(float);
void finn_mat4_perspective(float *result, float fov, float aspect, float near,
                           float far) {
  const float tanHalfFov = tan(fov / 2.0f);
  memset(result, 0, sizeof(float) * 16);
  result[0] = 1.0f / (aspect * tanHalfFov);
  result[5] = 1.0f / (tanHalfFov);
  result[10] = -(far + near) / (far - near);
  result[11] = -1.0f;
  result[14] = -(2.0f * far * near) / (far - near);
}


x86 assembly (clang, -O0):
<finn_mat4_perspective>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
movss  %xmm1,-0x10(%rbp)
movss  %xmm2,-0x14(%rbp)
movss  %xmm3,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
movss  0xeb3(%rip),%xmm1
divss  %xmm1,%xmm0
call   1040 <tan@plt>
movss  %xmm0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
movss  -0x10(%rbp),%xmm1
mulss  -0x1c(%rbp),%xmm1
movss  0xe8b(%rip),%xmm0
divss  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
movss  0xe77(%rip),%xmm0
divss  -0x1c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x14(%rax)
movss  -0x18(%rbp),%xmm0
addss  -0x14(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  -0x18(%rbp),%xmm1
subss  -0x14(%rbp),%xmm1
divss  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x28(%rax)
mov    -0x8(%rbp),%rax
movss  0xe2b(%rip),%xmm0
movss  %xmm0,0x2c(%rax)
movss  0xe1a(%rip),%xmm0
mulss  -0x18(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  -0x18(%rbp),%xmm1
subss  -0x14(%rbp),%xmm1
divss  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x38(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<finn_mat4_perspective>:
push   %rbx
sub    $0x10,%rsp
movss  %xmm3,0xc(%rsp)
movss  %xmm2,0x8(%rsp)
movss  %xmm1,0x4(%rsp)
mov    %rdi,%rbx
mulss  0xebe(%rip),%xmm0
call   1040 <tan@plt>
movss  %xmm0,(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
movss  0x4(%rsp),%xmm2
movss  (%rsp),%xmm3
mulss  %xmm3,%xmm2
movss  0xe92(%rip),%xmm0
movaps %xmm0,%xmm1
divss  %xmm2,%xmm1
movss  %xmm1,(%rbx)
divss  %xmm3,%xmm0
movss  %xmm0,0x14(%rbx)
movss  0x8(%rsp),%xmm3
movaps %xmm3,%xmm0
movss  0xc(%rsp),%xmm2
addss  %xmm2,%xmm0
xorps  0xe70(%rip),%xmm0
movaps %xmm2,%xmm1
subss  %xmm3,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,0x28(%rbx)
mulss  0xe50(%rip),%xmm2
movl   $0xbf800000,0x2c(%rbx)
mulss  %xmm3,%xmm2
divss  %xmm1,%xmm2
movss  %xmm2,0x38(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @finn_mat4_perspective(float* %0, float %1, float %2, float %3, float %4) {
%6 = alloca float*
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float
store float* %0, float** %6
store float %1, float* %7
store float %2, float* %8
store float %3, float* %9
store float %4, float* %10
%12 = load float, float* %7
%13 = fdiv float %12, 2.000000e+00
%14 = call float @tan(float %13)
store float %14, float* %11
%15 = load float*, float** %6
%16 = call i32 @memset(float* %15, i32 0, i32 64)
%17 = load float, float* %8
%18 = load float, float* %11
%19 = fmul float %17, %18
%20 = fdiv float 1.000000e+00, %19
%21 = load float*, float** %6
%22 = getelementptr inbounds float, float* %21, i64 0
store float %20, float* %22
%23 = load float, float* %11
%24 = fdiv float 1.000000e+00, %23
%25 = load float*, float** %6
%26 = getelementptr inbounds float, float* %25, i64 5
store float %24, float* %26
%27 = load float, float* %10
%28 = load float, float* %9
%29 = fadd float %27, %28
%30 = fneg float %29
%31 = load float, float* %10
%32 = load float, float* %9
%33 = fsub float %31, %32
%34 = fdiv float %30, %33
%35 = load float*, float** %6
%36 = getelementptr inbounds float, float* %35, i64 10
store float %34, float* %36
%37 = load float*, float** %6
%38 = getelementptr inbounds float, float* %37, i64 11
store float -1.000000e+00, float* %38
%39 = load float, float* %10
%40 = fmul float 2.000000e+00, %39
%41 = load float, float* %9
%42 = fmul float %40, %41
%43 = fneg float %42
%44 = load float, float* %10
%45 = load float, float* %9
%46 = fsub float %44, %45
%47 = fdiv float %43, %46
%48 = load float*, float** %6
%49 = getelementptr inbounds float, float* %48, i64 14
store float %47, float* %49
ret void
}

LLVM IR (-O2):
define void @finn_mat4_perspective(float* %0, float %1, float %2, float %3, float %4) {
%6 = fmul float %1, 5.000000e-01
%7 = tail call float @tan(float %6)
%8 = tail call i32 @memset(float* %0, i32 0, i32 64)
%9 = fmul float %7, %2
%10 = fdiv float 1.000000e+00, %9
store float %10, float* %0
%11 = fdiv float 1.000000e+00, %7
%12 = getelementptr inbounds float, float* %0, i64 5
store float %11, float* %12
%13 = fadd float %3, %4
%14 = fneg float %13
%15 = fsub float %4, %3
%16 = fdiv float %14, %15
%17 = getelementptr inbounds float, float* %0, i64 10
store float %16, float* %17
%18 = getelementptr inbounds float, float* %0, i64 11
store float -1.000000e+00, float* %18
%19 = fmul float %4, -2.000000e+00
%20 = fmul float %19, %3
%21 = fdiv float %20, %15
%22 = getelementptr inbounds float, float* %0, i64 14
store float %21, float* %22
ret void
}