#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 */
float tanf(float);
float *mat4_perspective(float *result, float fov_y, float aspect, float n,
                        float f) {
  float tan_half_fov_y = 1.0f / tanf(fov_y * 0.5f);
  result[0] = 1.0f / aspect * tan_half_fov_y;
  result[1] = 0.0f;
  result[2] = 0.0f;
  result[3] = 0.0f;
  result[4] = 0.0f;
  result[5] = 1.0f / tan_half_fov_y;
  result[6] = 0.0f;
  result[7] = 0.0f;
  result[8] = 0.0f;
  result[9] = 0.0f;
  result[10] = f / (n - f);
  result[11] = -1.0f;
  result[12] = 0.0f;
  result[13] = 0.0f;
  result[14] = -(f * n) / (f - n);
  result[15] = 0.0f;
  return result;
}


x86 assembly (clang, -O0):
<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  0xed0(%rip),%xmm0
mulss  -0xc(%rbp),%xmm0
call   1030 <tanf@plt>
movaps %xmm0,%xmm1
movss  0xeb7(%rip),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  0xea6(%rip),%xmm0
divss  -0x10(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x4(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0xc(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x10(%rax)
movss  0xe5c(%rip),%xmm0
divss  -0x1c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x14(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x18(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x1c(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x20(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x24(%rax)
movss  -0x18(%rbp),%xmm0
movss  -0x14(%rbp),%xmm1
subss  -0x18(%rbp),%xmm1
divss  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x28(%rax)
mov    -0x8(%rbp),%rax
movss  0xdf2(%rip),%xmm0
movss  %xmm0,0x2c(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x30(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x34(%rax)
movss  -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)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x3c(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mat4_perspective>:
push   %rbx
sub    $0x20,%rsp
movaps %xmm3,0x10(%rsp)
movss  %xmm2,0xc(%rsp)
movss  %xmm1,0x8(%rsp)
mov    %rdi,%rbx
mulss  0xecf(%rip),%xmm0
call   1030 <tanf@plt>
movss  0xec6(%rip),%xmm1
movaps %xmm1,%xmm2
divss  %xmm0,%xmm2
movaps %xmm1,%xmm0
divss  0x8(%rsp),%xmm0
mulss  %xmm2,%xmm0
movss  %xmm0,(%rbx)
divss  %xmm2,%xmm1
xorps  %xmm0,%xmm0
movups %xmm0,0x4(%rbx)
movss  %xmm1,0x14(%rbx)
movss  0xc(%rsp),%xmm4
movaps %xmm4,%xmm1
movaps 0x10(%rsp),%xmm3
subss  %xmm3,%xmm1
movaps %xmm3,%xmm2
divss  %xmm1,%xmm2
movups %xmm0,0x18(%rbx)
movss  %xmm2,0x28(%rbx)
mov    $0xbf800000,%eax
mov    %rax,0x2c(%rbx)
movl   $0x0,0x34(%rbx)
movaps 0xe71(%rip),%xmm0
xorps  %xmm3,%xmm0
mulss  %xmm4,%xmm0
subss  %xmm4,%xmm3
divss  %xmm3,%xmm0
movss  %xmm0,0x38(%rbx)
movl   $0x0,0x3c(%rbx)
mov    %rbx,%rax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define float* @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 = fmul float %12, 5.000000e-01
%14 = call float @tanf(float %13)
%15 = fdiv float 1.000000e+00, %14
store float %15, float* %11
%16 = load float, float* %8
%17 = fdiv float 1.000000e+00, %16
%18 = load float, float* %11
%19 = fmul float %17, %18
%20 = load float*, float** %6
%21 = getelementptr inbounds float, float* %20, i64 0
store float %19, float* %21
%22 = load float*, float** %6
%23 = getelementptr inbounds float, float* %22, i64 1
store float 0.000000e+00, float* %23
%24 = load float*, float** %6
%25 = getelementptr inbounds float, float* %24, i64 2
store float 0.000000e+00, float* %25
%26 = load float*, float** %6
%27 = getelementptr inbounds float, float* %26, i64 3
store float 0.000000e+00, float* %27
%28 = load float*, float** %6
%29 = getelementptr inbounds float, float* %28, i64 4
store float 0.000000e+00, float* %29
%30 = load float, float* %11
%31 = fdiv float 1.000000e+00, %30
%32 = load float*, float** %6
%33 = getelementptr inbounds float, float* %32, i64 5
store float %31, float* %33
%34 = load float*, float** %6
%35 = getelementptr inbounds float, float* %34, i64 6
store float 0.000000e+00, float* %35
%36 = load float*, float** %6
%37 = getelementptr inbounds float, float* %36, i64 7
store float 0.000000e+00, float* %37
%38 = load float*, float** %6
%39 = getelementptr inbounds float, float* %38, i64 8
store float 0.000000e+00, float* %39
%40 = load float*, float** %6
%41 = getelementptr inbounds float, float* %40, i64 9
store float 0.000000e+00, float* %41
%42 = load float, float* %10
%43 = load float, float* %9
%44 = load float, float* %10
%45 = fsub float %43, %44
%46 = fdiv float %42, %45
%47 = load float*, float** %6
%48 = getelementptr inbounds float, float* %47, i64 10
store float %46, float* %48
%49 = load float*, float** %6
%50 = getelementptr inbounds float, float* %49, i64 11
store float -1.000000e+00, float* %50
%51 = load float*, float** %6
%52 = getelementptr inbounds float, float* %51, i64 12
store float 0.000000e+00, float* %52
%53 = load float*, float** %6
%54 = getelementptr inbounds float, float* %53, i64 13
store float 0.000000e+00, float* %54
%55 = load float, float* %10
%56 = load float, float* %9
%57 = fmul float %55, %56
%58 = fneg float %57
%59 = load float, float* %10
%60 = load float, float* %9
%61 = fsub float %59, %60
%62 = fdiv float %58, %61
%63 = load float*, float** %6
%64 = getelementptr inbounds float, float* %63, i64 14
store float %62, float* %64
%65 = load float*, float** %6
%66 = getelementptr inbounds float, float* %65, i64 15
store float 0.000000e+00, float* %66
%67 = load float*, float** %6
ret float* %67
}

LLVM IR (-O2):
define float* @mat4_perspective(float* returned writeonly %0, float %1, float %2, float %3, float %4) {
%6 = fmul float %1, 5.000000e-01
%7 = tail call float @tanf(float %6)
%8 = fdiv float 1.000000e+00, %7
%9 = fdiv float 1.000000e+00, %2
%10 = fmul float %9, %8
store float %10, float* %0
%11 = getelementptr inbounds float, float* %0, i64 1
%12 = fdiv float 1.000000e+00, %8
%13 = getelementptr inbounds float, float* %0, i64 5
%14 = bitcast float* %11 to i8*
store float %12, float* %13
%15 = getelementptr inbounds float, float* %0, i64 6
%16 = fsub float %3, %4
%17 = fdiv float %4, %16
%18 = getelementptr inbounds float, float* %0, i64 10
%19 = bitcast float* %15 to i8*
store float %17, float* %18
%20 = getelementptr inbounds float, float* %0, i64 11
store float -1.000000e+00, float* %20
%21 = getelementptr inbounds float, float* %0, i64 12
store float 0.000000e+00, float* %21
%22 = getelementptr inbounds float, float* %0, i64 13
store float 0.000000e+00, float* %22
%23 = fneg float %4
%24 = fmul float %23, %3
%25 = fsub float %4, %3
%26 = fdiv float %24, %25
%27 = getelementptr inbounds float, float* %0, i64 14
store float %26, float* %27
%28 = getelementptr inbounds float, float* %0, i64 15
store float 0.000000e+00, float* %28
ret float* %0
}