#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);
void perspective(float *m, float fov, float aspect, float zNear, float zFar) {
  const float h = tanf(fov);
  const float w = h / aspect;
  const float depth = zNear - zFar;
  const float q = (zFar + zNear) / depth;
  const float qn = 2 * zFar * zNear / depth;
  m[0] = w;
  m[1] = 0;
  m[2] = 0;
  m[3] = 0;
  m[4] = 0;
  m[5] = h;
  m[6] = 0;
  m[7] = 0;
  m[8] = 0;
  m[9] = 0;
  m[10] = q;
  m[11] = -1;
  m[12] = 0;
  m[13] = 0;
  m[14] = qn;
  m[15] = 0;
}


x86 assembly (clang, -O0):
<perspective>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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
call   1030 <tanf@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
divss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x14(%rbp),%xmm0
subss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x18(%rbp),%xmm0
addss  -0x14(%rbp),%xmm0
divss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  0xe8b(%rip),%xmm0
mulss  -0x18(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
divss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x20(%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  -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  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x28(%rax)
mov    -0x8(%rbp),%rax
movss  0xdde(%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  -0x2c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x38(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x3c(%rax)
add    $0x30,%rsp
pop    %rbp
ret

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

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

LLVM IR (-O2):
define void @perspective(float* nocapture writeonly %0, float %1, float %2, float %3, float %4) {
%6 = tail call float @tanf(float %1)
%7 = fdiv float %6, %2
%8 = fsub float %3, %4
%9 = fadd float %3, %4
%10 = fdiv float %9, %8
%11 = fmul float %4, 2.000000e+00
%12 = fmul float %11, %3
%13 = fdiv float %12, %8
store float %7, float* %0
%14 = getelementptr inbounds float, float* %0, i64 1
%15 = getelementptr inbounds float, float* %0, i64 5
%16 = bitcast float* %14 to i8*
store float %6, float* %15
%17 = getelementptr inbounds float, float* %0, i64 6
%18 = getelementptr inbounds float, float* %0, i64 10
%19 = bitcast float* %17 to i8*
store float %10, 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 = getelementptr inbounds float, float* %0, i64 14
store float %13, float* %23
%24 = getelementptr inbounds float, float* %0, i64 15
store float 0.000000e+00, float* %24
ret void
}