#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 perspective(float *matrix, float fov, float aspect, float nearz,
                 float farz) {
  float range;
  range = tan(fov * 0.00872664625) * nearz;
  memset(matrix, 0, sizeof(float) * 16);
  matrix[0] = (2 * nearz) / ((range * aspect) - (-range * aspect));
  matrix[5] = (2 * nearz) / (2 * range);
  matrix[10] = -(farz + nearz) / (farz - nearz);
  matrix[11] = -1;
  matrix[14] = -(2 * farz * nearz) / (farz - nearz);
}


x86 assembly (clang, -O0):
<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
cvtss2sd %xmm0,%xmm0
movsd  0xeb7(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1040 <tan@plt>
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
movss  0xe80(%rip),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  -0x1c(%rbp),%xmm1
movss  -0x10(%rbp),%xmm3
movss  -0x1c(%rbp),%xmm2
movd   %xmm2,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm2
mulss  -0x10(%rbp),%xmm2
movd   %xmm2,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm2
mulss  %xmm3,%xmm1
addss  %xmm2,%xmm1
divss  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
movss  0xe31(%rip),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  0xe24(%rip),%xmm1
mulss  -0x1c(%rbp),%xmm1
divss  %xmm1,%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  0xddc(%rip),%xmm0
movss  %xmm0,0x2c(%rax)
movss  0xdcb(%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):
<perspective>:
push   %rbx
sub    $0x10,%rsp
movss  %xmm3,0xc(%rsp)
movss  %xmm2,(%rsp)
movss  %xmm1,0x8(%rsp)
mov    %rdi,%rbx
cvtss2sd %xmm0,%xmm0
mulsd  0xebb(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
call   1040 <tan@plt>
mulss  (%rsp),%xmm0
movss  %xmm0,0x4(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
movss  (%rsp),%xmm3
movaps %xmm3,%xmm0
addss  %xmm3,%xmm0
movss  0x8(%rsp),%xmm1
movss  0x4(%rsp),%xmm4
mulss  %xmm4,%xmm1
addss  %xmm1,%xmm1
movaps %xmm1,%xmm2
movaps %xmm0,%xmm1
divss  %xmm2,%xmm1
movss  %xmm1,(%rbx)
addss  %xmm4,%xmm4
divss  %xmm4,%xmm0
movss  %xmm0,0x14(%rbx)
movaps %xmm3,%xmm0
movss  0xc(%rsp),%xmm2
addss  %xmm2,%xmm0
xorps  0xe59(%rip),%xmm0
movaps %xmm2,%xmm1
subss  %xmm3,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,0x28(%rbx)
mulss  0xe51(%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 @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 = fpext float %12 to double
%14 = fmul double %13, 0x3F81DF46A1FAE711
%15 = fptrunc double %14 to float
%16 = call float @tan(float %15)
%17 = load float, float* %9
%18 = fmul float %16, %17
store float %18, float* %11
%19 = load float*, float** %6
%20 = call i32 @memset(float* %19, i32 0, i32 64)
%21 = load float, float* %9
%22 = fmul float 2.000000e+00, %21
%23 = load float, float* %11
%24 = load float, float* %8
%25 = load float, float* %11
%26 = fneg float %25
%27 = load float, float* %8
%28 = fmul float %26, %27
%29 = fneg float %28
%30 = call float @llvm.fmuladd.f32(float %23, float %24, float %29)
%31 = fdiv float %22, %30
%32 = load float*, float** %6
%33 = getelementptr inbounds float, float* %32, i64 0
store float %31, float* %33
%34 = load float, float* %9
%35 = fmul float 2.000000e+00, %34
%36 = load float, float* %11
%37 = fmul float 2.000000e+00, %36
%38 = fdiv float %35, %37
%39 = load float*, float** %6
%40 = getelementptr inbounds float, float* %39, i64 5
store float %38, float* %40
%41 = load float, float* %10
%42 = load float, float* %9
%43 = fadd float %41, %42
%44 = fneg float %43
%45 = load float, float* %10
%46 = load float, float* %9
%47 = fsub float %45, %46
%48 = fdiv float %44, %47
%49 = load float*, float** %6
%50 = getelementptr inbounds float, float* %49, i64 10
store float %48, float* %50
%51 = load float*, float** %6
%52 = getelementptr inbounds float, float* %51, i64 11
store float -1.000000e+00, float* %52
%53 = load float, float* %10
%54 = fmul float 2.000000e+00, %53
%55 = load float, float* %9
%56 = fmul float %54, %55
%57 = fneg float %56
%58 = load float, float* %10
%59 = load float, float* %9
%60 = fsub float %58, %59
%61 = fdiv float %57, %60
%62 = load float*, float** %6
%63 = getelementptr inbounds float, float* %62, i64 14
store float %61, float* %63
ret void
}

LLVM IR (-O2):
define void @perspective(float* %0, float %1, float %2, float %3, float %4) {
%6 = fpext float %1 to double
%7 = fmul double %6, 0x3F81DF46A1FAE711
%8 = fptrunc double %7 to float
%9 = tail call float @tan(float %8)
%10 = fmul float %9, %3
%11 = tail call i32 @memset(float* %0, i32 0, i32 64)
%12 = fmul float %3, 2.000000e+00
%13 = fmul float %10, %2
%14 = tail call float @llvm.fmuladd.f32(float %10, float %2, float %13)
%15 = fdiv float %12, %14
store float %15, float* %0
%16 = fmul float %10, 2.000000e+00
%17 = fdiv float %12, %16
%18 = getelementptr inbounds float, float* %0, i64 5
store float %17, float* %18
%19 = fadd float %3, %4
%20 = fneg float %19
%21 = fsub float %4, %3
%22 = fdiv float %20, %21
%23 = getelementptr inbounds float, float* %0, i64 10
store float %22, float* %23
%24 = getelementptr inbounds float, float* %0, i64 11
store float -1.000000e+00, float* %24
%25 = fmul float %4, -2.000000e+00
%26 = fmul float %25, %3
%27 = fdiv float %26, %21
%28 = getelementptr inbounds float, float* %0, i64 14
store float %27, float* %28
ret void
}