#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 FLT_MAX;
double tanf(float);
void mat4_perspective(float *dst, float fovy, float aspect, float near,
                      float far) {
  float f = 1.0 / tanf(fovy / 2), nf;
  dst[0] = f / aspect;
  dst[1] = 0;
  dst[2] = 0;
  dst[3] = 0;
  dst[4] = 0;
  dst[5] = f;
  dst[6] = 0;
  dst[7] = 0;
  dst[8] = 0;
  dst[9] = 0;
  dst[11] = -1;
  dst[12] = 0;
  dst[13] = 0;
  dst[15] = 0;
  if (far != 0 && far != FLT_MAX) {
    nf = 1 / (near - far);
    dst[10] = (far + near) * nf;
    dst[14] = (2 * far * near) * nf;
  } else {
    dst[10] = -1;
    dst[14] = -2 * near;
  }
}


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  -0xc(%rbp),%xmm0
movss  0xec7(%rip),%xmm1
divss  %xmm1,%xmm0
call   1030 <tanf@plt>
movaps %xmm0,%xmm1
movsd  0xebf(%rip),%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
divss  -0x10(%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)
mov    -0x8(%rbp),%rax
movss  0xe16(%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)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x3c(%rax)
movss  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    122f <mat4_perspective+0x11f>
jp     122f <mat4_perspective+0x11f>
jmp    12a7 <mat4_perspective+0x197>
movss  -0x18(%rbp),%xmm0
mov    0x2dad(%rip),%rax
ucomiss (%rax),%xmm0
jne    124f <mat4_perspective+0x13f>
jp     124f <mat4_perspective+0x13f>
jmp    12a7 <mat4_perspective+0x197>
movss  -0x14(%rbp),%xmm1
subss  -0x18(%rbp),%xmm1
movss  0xdab(%rip),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x18(%rbp),%xmm0
addss  -0x14(%rbp),%xmm0
mulss  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x28(%rax)
movss  0xd7a(%rip),%xmm0
mulss  -0x18(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
mulss  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x38(%rax)
jmp    12ce <mat4_perspective+0x1be>
mov    -0x8(%rbp),%rax
movss  0xd4d(%rip),%xmm0
movss  %xmm0,0x28(%rax)
movss  0xd48(%rip),%xmm0
mulss  -0x14(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x38(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mat4_perspective>:
push   %rbx
sub    $0x10,%rsp
movss  %xmm3,0x8(%rsp)
movss  %xmm2,0x4(%rsp)
movss  %xmm1,0xc(%rsp)
mov    %rdi,%rbx
mulss  0xece(%rip),%xmm0
call   1030 <tanf@plt>
movss  0x8(%rsp),%xmm3
movsd  0xecb(%rip),%xmm1
divsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movaps %xmm0,%xmm1
divss  0xc(%rsp),%xmm1
movss  %xmm1,(%rbx)
xorps  %xmm1,%xmm1
movups %xmm1,0x4(%rbx)
movss  %xmm0,0x14(%rbx)
movups %xmm1,0x18(%rbx)
mov    $0xbf800000,%eax
mov    %rax,0x2c(%rbx)
movl   $0x0,0x34(%rbx)
movl   $0x0,0x3c(%rbx)
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm3
jne    118e <mat4_perspective+0x7e>
jnp    11d5 <mat4_perspective+0xc5>
mov    0x2e53(%rip),%rax
movss  (%rax),%xmm0
ucomiss %xmm3,%xmm0
jne    11a0 <mat4_perspective+0x90>
jnp    11d5 <mat4_perspective+0xc5>
movss  0x4(%rsp),%xmm2
movaps %xmm2,%xmm0
subss  %xmm3,%xmm0
movss  0xe57(%rip),%xmm1
divss  %xmm0,%xmm1
movaps %xmm2,%xmm0
addss  %xmm3,%xmm0
mulss  %xmm1,%xmm0
addss  %xmm3,%xmm3
mulss  %xmm2,%xmm3
mulss  %xmm1,%xmm3
movaps %xmm3,%xmm1
jmp    11eb <mat4_perspective+0xdb>
movss  0x4(%rsp),%xmm1
mulss  0xe21(%rip),%xmm1
movss  0xe1d(%rip),%xmm0
movss  %xmm0,0x28(%rbx)
movss  %xmm1,0x38(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@FLT_MAX = global float 0.000000e+00
define void @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
%12 = 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
%13 = load float, float* %7
%14 = fdiv float %13, 2.000000e+00
%15 = call double @tanf(float %14)
%16 = fdiv double 1.000000e+00, %15
%17 = fptrunc double %16 to float
store float %17, float* %11
%18 = load float, float* %11
%19 = load float, float* %8
%20 = fdiv float %18, %19
%21 = load float*, float** %6
%22 = getelementptr inbounds float, float* %21, i64 0
store float %20, float* %22
%23 = load float*, float** %6
%24 = getelementptr inbounds float, float* %23, i64 1
store float 0.000000e+00, float* %24
%25 = load float*, float** %6
%26 = getelementptr inbounds float, float* %25, i64 2
store float 0.000000e+00, float* %26
%27 = load float*, float** %6
%28 = getelementptr inbounds float, float* %27, i64 3
store float 0.000000e+00, float* %28
%29 = load float*, float** %6
%30 = getelementptr inbounds float, float* %29, i64 4
store float 0.000000e+00, float* %30
%31 = load float, float* %11
%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** %6
%43 = getelementptr inbounds float, float* %42, i64 11
store float -1.000000e+00, float* %43
%44 = load float*, float** %6
%45 = getelementptr inbounds float, float* %44, i64 12
store float 0.000000e+00, float* %45
%46 = load float*, float** %6
%47 = getelementptr inbounds float, float* %46, i64 13
store float 0.000000e+00, float* %47
%48 = load float*, float** %6
%49 = getelementptr inbounds float, float* %48, i64 15
store float 0.000000e+00, float* %49
%50 = load float, float* %10
%51 = fcmp une float %50, 0.000000e+00
br i1 %51, label %52, label %76
52: ; preds = %5
%53 = load float, float* %10
%54 = load float, float* @FLT_MAX
%55 = fcmp une float %53, %54
br i1 %55, label %56, label %76
56: ; preds = %52
%57 = load float, float* %9
%58 = load float, float* %10
%59 = fsub float %57, %58
%60 = fdiv float 1.000000e+00, %59
store float %60, float* %12
%61 = load float, float* %10
%62 = load float, float* %9
%63 = fadd float %61, %62
%64 = load float, float* %12
%65 = fmul float %63, %64
%66 = load float*, float** %6
%67 = getelementptr inbounds float, float* %66, i64 10
store float %65, float* %67
%68 = load float, float* %10
%69 = fmul float 2.000000e+00, %68
%70 = load float, float* %9
%71 = fmul float %69, %70
%72 = load float, float* %12
%73 = fmul float %71, %72
%74 = load float*, float** %6
%75 = getelementptr inbounds float, float* %74, i64 14
store float %73, float* %75
br label %83
76: ; preds = %52, %5
%77 = load float*, float** %6
%78 = getelementptr inbounds float, float* %77, i64 10
store float -1.000000e+00, float* %78
%79 = load float, float* %9
%80 = fmul float -2.000000e+00, %79
%81 = load float*, float** %6
%82 = getelementptr inbounds float, float* %81, i64 14
store float %80, float* %82
br label %83
83: ; preds = %76, %56
ret void
}

LLVM IR (-O2):
@FLT_MAX = global float 0.000000e+00
define void @mat4_perspective(float* nocapture writeonly %0, float %1, float %2, float %3, float %4) {
%6 = fmul float %1, 5.000000e-01
%7 = tail call double @tanf(float %6)
%8 = fdiv double 1.000000e+00, %7
%9 = fptrunc double %8 to float
%10 = fdiv float %9, %2
store float %10, float* %0
%11 = getelementptr inbounds float, float* %0, i64 1
%12 = getelementptr inbounds float, float* %0, i64 5
%13 = bitcast float* %11 to i8*
store float %9, float* %12
%14 = getelementptr inbounds float, float* %0, i64 6
%15 = getelementptr inbounds float, float* %0, i64 11
%16 = bitcast float* %14 to i8*
store float -1.000000e+00, float* %15
%17 = getelementptr inbounds float, float* %0, i64 12
store float 0.000000e+00, float* %17
%18 = getelementptr inbounds float, float* %0, i64 13
store float 0.000000e+00, float* %18
%19 = getelementptr inbounds float, float* %0, i64 15
store float 0.000000e+00, float* %19
%20 = fcmp une float %4, 0.000000e+00
%21 = load float, float* @FLT_MAX
%22 = fcmp une float %21, %4
%23 = select i1 %20, i1 %22, i1 false
br i1 %23, label %24, label %32
24: ; preds = %5
%25 = fsub float %3, %4
%26 = fdiv float 1.000000e+00, %25
%27 = fadd float %3, %4
%28 = fmul float %27, %26
%29 = fmul float %4, 2.000000e+00
%30 = fmul float %29, %3
%31 = fmul float %30, %26
br label %34
32: ; preds = %5
%33 = fmul float %3, -2.000000e+00
br label %34
34: ; preds = %32, %24
%35 = phi float [ %28, %24 ], [ -1.000000e+00, %32 ]
%36 = phi float [ %31, %24 ], [ %33, %32 ]
%37 = getelementptr inbounds float, float* %0, i64 10
store float %35, float* %37
%38 = getelementptr inbounds float, float* %0, i64 14
store float %36, float* %38
ret void
}