#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 */
double tan(double);
void perspective_matrix(double fovy, double aspect, double znear, double zfar,
                        float *P) {
  int i;
  double f;
  f = 1.0 / tan(fovy * 0.5);
  for (i = 0; i < 16; i++) {
    P[i] = 0.0;
  }
  P[0] = f / aspect;
  P[5] = f;
  P[10] = (znear + zfar) / (znear - zfar);
  P[11] = -1.0;
  P[14] = (2.0 * znear * zfar) / (znear - zfar);
  P[15] = 0.0;
}


x86 assembly (clang, -O0):
<perspective_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
mov    %rdi,-0x28(%rbp)
movsd  0xed0(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
call   1030 <tan@plt>
movaps %xmm0,%xmm1
movsd  0xeb3(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x10,-0x2c(%rbp)
jge    1185 <perspective_matrix+0x75>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    115d <perspective_matrix+0x4d>
movsd  -0x38(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x28(%rbp),%rax
movss  %xmm0,(%rax)
movsd  -0x38(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x28(%rbp),%rax
movss  %xmm0,0x14(%rax)
movsd  -0x18(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x28(%rbp),%rax
movss  %xmm0,0x28(%rax)
mov    -0x28(%rbp),%rax
movss  0xe3a(%rip),%xmm0
movss  %xmm0,0x2c(%rax)
movsd  0xe25(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x28(%rbp),%rax
movss  %xmm0,0x38(%rax)
mov    -0x28(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x3c(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perspective_matrix>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movsd  %xmm3,0x18(%rsp)
movsd  %xmm2,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
mulsd  0xece(%rip),%xmm0
call   1030 <tan@plt>
xorps  %xmm1,%xmm1
movups %xmm1,0x14(%rbx)
movups %xmm1,0x24(%rbx)
movups %xmm1,0x4(%rbx)
movsd  0xeba(%rip),%xmm1
divsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movl   $0x0,0x34(%rbx)
divsd  0x8(%rsp),%xmm1
cvtsd2ss %xmm1,%xmm1
movss  %xmm1,(%rbx)
movss  %xmm0,0x14(%rbx)
movsd  0x10(%rsp),%xmm2
movapd %xmm2,%xmm0
movsd  0x18(%rsp),%xmm3
addsd  %xmm3,%xmm0
movapd %xmm2,%xmm1
subsd  %xmm3,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x28(%rbx)
movl   $0xbf800000,0x2c(%rbx)
addsd  %xmm2,%xmm2
mulsd  %xmm3,%xmm2
divsd  %xmm1,%xmm2
xorps  %xmm0,%xmm0
cvtsd2ss %xmm2,%xmm0
movss  %xmm0,0x38(%rbx)
movl   $0x0,0x3c(%rbx)
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @perspective_matrix(double %0, double %1, double %2, double %3, float* %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca float*
%11 = alloca i32
%12 = alloca double
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
store float* %4, float** %10
%13 = load double, double* %6
%14 = fmul double %13, 5.000000e-01
%15 = call double @tan(double %14)
%16 = fdiv double 1.000000e+00, %15
store double %16, double* %12
store i32 0, i32* %11
br label %17
17: ; preds = %25, %5
%18 = load i32, i32* %11
%19 = icmp slt i32 %18, 16
br i1 %19, label %20, label %28
20: ; preds = %17
%21 = load float*, float** %10
%22 = load i32, i32* %11
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds float, float* %21, i64 %23
store float 0.000000e+00, float* %24
br label %25
25: ; preds = %20
%26 = load i32, i32* %11
%27 = add nsw i32 %26, 1
store i32 %27, i32* %11
br label %17
28: ; preds = %17
%29 = load double, double* %12
%30 = load double, double* %7
%31 = fdiv double %29, %30
%32 = fptrunc double %31 to float
%33 = load float*, float** %10
%34 = getelementptr inbounds float, float* %33, i64 0
store float %32, float* %34
%35 = load double, double* %12
%36 = fptrunc double %35 to float
%37 = load float*, float** %10
%38 = getelementptr inbounds float, float* %37, i64 5
store float %36, float* %38
%39 = load double, double* %8
%40 = load double, double* %9
%41 = fadd double %39, %40
%42 = load double, double* %8
%43 = load double, double* %9
%44 = fsub double %42, %43
%45 = fdiv double %41, %44
%46 = fptrunc double %45 to float
%47 = load float*, float** %10
%48 = getelementptr inbounds float, float* %47, i64 10
store float %46, float* %48
%49 = load float*, float** %10
%50 = getelementptr inbounds float, float* %49, i64 11
store float -1.000000e+00, float* %50
%51 = load double, double* %8
%52 = fmul double 2.000000e+00, %51
%53 = load double, double* %9
%54 = fmul double %52, %53
%55 = load double, double* %8
%56 = load double, double* %9
%57 = fsub double %55, %56
%58 = fdiv double %54, %57
%59 = fptrunc double %58 to float
%60 = load float*, float** %10
%61 = getelementptr inbounds float, float* %60, i64 14
store float %59, float* %61
%62 = load float*, float** %10
%63 = getelementptr inbounds float, float* %62, i64 15
store float 0.000000e+00, float* %63
ret void
}

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