#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 M_PI;
int /*<<< orphan*/ mat_identity(float *);
float tanf(float);
void mat_perspective(float *m, float aspect, float near, float far,
                     float fview) {
  mat_identity(m);
  float t, dz;
  dz = far - near;
  t = 1.0f / tanf(M_PI * fview / 360.0f);
  aspect = (aspect == 0.0f) ? 0.0000001f : aspect;
  dz = (dz == 0.0f) ? 0.0000001f : dz;
  m[0] = t / aspect;
  m[5] = t;
  m[10] = -(far + near) / dz;
  m[11] = -1.0f;
  m[14] = -2.0f * near * far / dz;
  m[15] = 0.0f;
}


x86 assembly (clang, -O0):
<mat_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)
mov    -0x8(%rbp),%rdi
call   1030 <mat_identity@plt>
movss  -0x14(%rbp),%xmm0
subss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
mov    0x2e89(%rip),%rax
movss  (%rax),%xmm0
mulss  -0x18(%rbp),%xmm0
movss  0xe94(%rip),%xmm1
divss  %xmm1,%xmm0
call   1040 <tanf@plt>
movaps %xmm0,%xmm1
movss  0xe7c(%rip),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0xc(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11b6 <mat_perspective+0x96>
jp     11b6 <mat_perspective+0x96>
movss  0xe5c(%rip),%xmm0
movss  %xmm0,-0x24(%rbp)
jmp    11c0 <mat_perspective+0xa0>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11f3 <mat_perspective+0xd3>
jp     11f3 <mat_perspective+0xd3>
movss  0xe1f(%rip),%xmm0
movss  %xmm0,-0x28(%rbp)
jmp    11fd <mat_perspective+0xdd>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x1c(%rbp),%xmm0
divss  -0xc(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x1c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x14(%rax)
movss  -0x14(%rbp),%xmm0
addss  -0x10(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
divss  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x28(%rax)
mov    -0x8(%rbp),%rax
movss  0xdb8(%rip),%xmm0
movss  %xmm0,0x2c(%rax)
movss  0xda7(%rip),%xmm0
mulss  -0x10(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
divss  -0x20(%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):
<mat_perspective>:
push   %rbx
sub    $0x30,%rsp
movss  %xmm3,0xc(%rsp)
movss  %xmm2,0x8(%rsp)
movss  %xmm1,0x4(%rsp)
movaps %xmm0,0x10(%rsp)
mov    %rdi,%rbx
call   1030 <mat_identity@plt>
movss  0x8(%rsp),%xmm0
subss  0x4(%rsp),%xmm0
movaps %xmm0,0x20(%rsp)
mov    0x2e8c(%rip),%rax
movss  0xc(%rsp),%xmm0
mulss  (%rax),%xmm0
divss  0xe92(%rip),%xmm0
call   1040 <tanf@plt>
movss  0xe89(%rip),%xmm1
divss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
movaps 0x10(%rsp),%xmm5
movaps %xmm5,%xmm2
cmpeqss %xmm0,%xmm2
movss  0xe71(%rip),%xmm3
movaps %xmm2,%xmm4
andps  %xmm3,%xmm4
andnps %xmm5,%xmm2
orps   %xmm4,%xmm2
movaps 0x20(%rsp),%xmm5
cmpeqss %xmm5,%xmm0
movaps %xmm0,%xmm4
andnps %xmm5,%xmm4
andps  %xmm3,%xmm0
orps   %xmm4,%xmm0
movaps %xmm1,%xmm3
divss  %xmm2,%xmm3
movss  %xmm3,(%rbx)
movss  %xmm1,0x14(%rbx)
movss  0x4(%rsp),%xmm3
movaps %xmm3,%xmm1
movss  0x8(%rsp),%xmm2
addss  %xmm2,%xmm1
xorps  0xe2d(%rip),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,0x28(%rbx)
movl   $0xbf800000,0x2c(%rbx)
movaps %xmm3,%xmm1
mulss  0xe0e(%rip),%xmm1
mulss  %xmm2,%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,0x38(%rbx)
movl   $0x0,0x3c(%rbx)
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@M_PI = global float 0.000000e+00
define void @mat_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** %6
%14 = call i32 @mat_identity(float* %13)
%15 = load float, float* %9
%16 = load float, float* %8
%17 = fsub float %15, %16
store float %17, float* %12
%18 = load float, float* @M_PI
%19 = load float, float* %10
%20 = fmul float %18, %19
%21 = fdiv float %20, 3.600000e+02
%22 = call float @tanf(float %21)
%23 = fdiv float 1.000000e+00, %22
store float %23, float* %11
%24 = load float, float* %7
%25 = fcmp oeq float %24, 0.000000e+00
br i1 %25, label %26, label %27
26: ; preds = %5
br label %29
27: ; preds = %5
%28 = load float, float* %7
br label %29
29: ; preds = %27, %26
%30 = phi float [ 0x3E7AD7F2A0000000, %26 ], [ %28, %27 ]
store float %30, float* %7
%31 = load float, float* %12
%32 = fcmp oeq float %31, 0.000000e+00
br i1 %32, label %33, label %34
33: ; preds = %29
br label %36
34: ; preds = %29
%35 = load float, float* %12
br label %36
36: ; preds = %34, %33
%37 = phi float [ 0x3E7AD7F2A0000000, %33 ], [ %35, %34 ]
store float %37, float* %12
%38 = load float, float* %11
%39 = load float, float* %7
%40 = fdiv float %38, %39
%41 = load float*, float** %6
%42 = getelementptr inbounds float, float* %41, i64 0
store float %40, float* %42
%43 = load float, float* %11
%44 = load float*, float** %6
%45 = getelementptr inbounds float, float* %44, i64 5
store float %43, float* %45
%46 = load float, float* %9
%47 = load float, float* %8
%48 = fadd float %46, %47
%49 = fneg float %48
%50 = load float, float* %12
%51 = fdiv float %49, %50
%52 = load float*, float** %6
%53 = getelementptr inbounds float, float* %52, i64 10
store float %51, float* %53
%54 = load float*, float** %6
%55 = getelementptr inbounds float, float* %54, i64 11
store float -1.000000e+00, float* %55
%56 = load float, float* %8
%57 = fmul float -2.000000e+00, %56
%58 = load float, float* %9
%59 = fmul float %57, %58
%60 = load float, float* %12
%61 = fdiv float %59, %60
%62 = load float*, float** %6
%63 = getelementptr inbounds float, float* %62, i64 14
store float %61, float* %63
%64 = load float*, float** %6
%65 = getelementptr inbounds float, float* %64, i64 15
store float 0.000000e+00, float* %65
ret void
}

LLVM IR (-O2):
@M_PI = global float 0.000000e+00
define void @mat_perspective(float* %0, float %1, float %2, float %3, float %4) {
%6 = tail call i32 @mat_identity(float* %0)
%7 = fsub float %3, %2
%8 = load float, float* @M_PI
%9 = fmul float %8, %4
%10 = fdiv float %9, 3.600000e+02
%11 = tail call float @tanf(float %10)
%12 = fdiv float 1.000000e+00, %11
%13 = fcmp oeq float %1, 0.000000e+00
%14 = select i1 %13, float 0x3E7AD7F2A0000000, float %1
%15 = fcmp oeq float %7, 0.000000e+00
%16 = select i1 %15, float 0x3E7AD7F2A0000000, float %7
%17 = fdiv float %12, %14
store float %17, float* %0
%18 = getelementptr inbounds float, float* %0, i64 5
store float %12, float* %18
%19 = fadd float %2, %3
%20 = fneg float %19
%21 = fdiv float %20, %16
%22 = getelementptr inbounds float, float* %0, i64 10
store float %21, float* %22
%23 = getelementptr inbounds float, float* %0, i64 11
store float -1.000000e+00, float* %23
%24 = fmul float %2, -2.000000e+00
%25 = fmul float %24, %3
%26 = fdiv float %25, %16
%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 void
}