#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 */
typedef int GLdouble;

/* Variables and functions */
int /*<<< orphan*/ __gluMakeIdentityd(int *);
double cos(double);
int /*<<< orphan*/ glMultMatrixd(int *);
double sin(double);
void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear,
                    GLdouble zFar) {
  GLdouble m[4][4];
  double sine, cotangent, deltaZ;
  double radians = fovy / 2 * 3.14159265358979323846 / 180;
  deltaZ = zFar - zNear;
  sine = sin(radians);
  if ((deltaZ == 0) || (sine == 0) || (aspect == 0)) {
    return;
  }
  cotangent = cos(radians) / sine;
  __gluMakeIdentityd(&m[0][0]);
  m[0][0] = cotangent / aspect;
  m[1][1] = cotangent;
  m[2][2] = -(zFar + zNear) / deltaZ;
  m[2][3] = -1;
  m[3][2] = -2 * zNear * zFar / deltaZ;
  m[3][3] = 0;
  glMultMatrixd(&m[0][0]);
}


x86 assembly (clang, -O0):
<gluPerspective>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  0xe9d(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe89(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x70(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x68(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11bb <gluPerspective+0x7b>
jp     11bb <gluPerspective+0x7b>
jmp    11e2 <gluPerspective+0xa2>
movsd  -0x58(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11d8 <gluPerspective+0x98>
jp     11d8 <gluPerspective+0x98>
jmp    11e2 <gluPerspective+0xa2>
cmpl   $0x0,-0x8(%rbp)
jne    11e7 <gluPerspective+0xa7>
jmp    126d <gluPerspective+0x12d>
movsd  -0x70(%rbp),%xmm0
call   1050 <cos@plt>
divsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
lea    -0x50(%rbp),%rdi
call   1060 <__gluMakeIdentityd@plt>
movsd  -0x60(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x50(%rbp)
cvttsd2si -0x60(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%ecx
add    -0xc(%rbp),%ecx
xor    %eax,%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm0
divsd  -0x68(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x28(%rbp)
movl   $0xffffffff,-0x24(%rbp)
imul   $0xfffffffe,-0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
cvtsi2sd %eax,%xmm0
divsd  -0x68(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x50(%rbp),%rdi
call   1040 <glMultMatrixd@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gluPerspective>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %esi,%ebp
mov    %edi,%eax
shr    $0x1f,%eax
add    %edi,%eax
sar    %eax
cvtsi2sd %eax,%xmm0
mulsd  0xe9a(%rip),%xmm0
divsd  0xe9a(%rip),%xmm0
movsd  %xmm0,(%rsp)
call   1030 <sin@plt>
test   %ebp,%ebp
je     1244 <gluPerspective+0x104>
mov    %r14d,%eax
sub    %ebx,%eax
je     1244 <gluPerspective+0x104>
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    119f <gluPerspective+0x5f>
jnp    1244 <gluPerspective+0x104>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
movsd  %xmm1,(%rsp)
call   1050 <cos@plt>
divsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    0x10(%rsp),%r15
mov    %r15,%rdi
call   1060 <__gluMakeIdentityd@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  (%rsp),%xmm1
cvttsd2si %xmm1,%eax
divsd  %xmm0,%xmm1
cvttsd2si %xmm1,%ecx
mov    %ecx,0x10(%rsp)
lea    (%rbx,%r14,1),%ecx
neg    %ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mov    %eax,0x24(%rsp)
movsd  0x8(%rsp),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,0x38(%rsp)
movl   $0xffffffff,0x3c(%rsp)
ff
imul   %r14d,%ebx
add    %ebx,%ebx
neg    %ebx
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,0x48(%rsp)
movl   $0x0,0x4c(%rsp)
mov    %r15,%rdi
call   1040 <glMultMatrixd@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @gluPerspective(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [4 x [4 x i32]]
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%14 = load i32, i32* %5
%15 = sdiv i32 %14, 2
%16 = sitofp i32 %15 to double
%17 = fmul double %16, 0x400921FB54442D18
%18 = fdiv double %17, 1.800000e+02
store double %18, double* %13
%19 = load i32, i32* %8
%20 = load i32, i32* %7
%21 = sub nsw i32 %19, %20
%22 = sitofp i32 %21 to double
store double %22, double* %12
%23 = load double, double* %13
%24 = call double @sin(double %23)
store double %24, double* %10
%25 = load double, double* %12
%26 = fcmp oeq double %25, 0.000000e+00
br i1 %26, label %33, label %27
27: ; preds = %4
%28 = load double, double* %10
%29 = fcmp oeq double %28, 0.000000e+00
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = load i32, i32* %6
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %30, %27, %4
br label %80
34: ; preds = %30
%35 = load double, double* %13
%36 = call double @cos(double %35)
%37 = load double, double* %10
%38 = fdiv double %36, %37
store double %38, double* %11
%39 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %9, i64 0, i64 0
%40 = getelementptr inbounds [4 x i32], [4 x i32]* %39, i64 0, i64 0
%41 = call i32 @__gluMakeIdentityd(i32* %40)
%42 = load double, double* %11
%43 = load i32, i32* %6
%44 = sitofp i32 %43 to double
%45 = fdiv double %42, %44
%46 = fptosi double %45 to i32
%47 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %9, i64 0, i64 0
%48 = getelementptr inbounds [4 x i32], [4 x i32]* %47, i64 0, i64 0
store i32 %46, i32* %48
%49 = load double, double* %11
%50 = fptosi double %49 to i32
%51 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %9, i64 0, i64 1
%52 = getelementptr inbounds [4 x i32], [4 x i32]* %51, i64 0, i64 1
store i32 %50, i32* %52
%53 = load i32, i32* %8
%54 = load i32, i32* %7
%55 = add nsw i32 %53, %54
%56 = sub nsw i32 0, %55
%57 = sitofp i32 %56 to double
%58 = load double, double* %12
%59 = fdiv double %57, %58
%60 = fptosi double %59 to i32
%61 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %9, i64 0, i64 2
%62 = getelementptr inbounds [4 x i32], [4 x i32]* %61, i64 0, i64 2
store i32 %60, i32* %62
%63 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %9, i64 0, i64 2
%64 = getelementptr inbounds [4 x i32], [4 x i32]* %63, i64 0, i64 3
store i32 -1, i32* %64
%65 = load i32, i32* %7
%66 = mul nsw i32 -2, %65
%67 = load i32, i32* %8
%68 = mul nsw i32 %66, %67
%69 = sitofp i32 %68 to double
%70 = load double, double* %12
%71 = fdiv double %69, %70
%72 = fptosi double %71 to i32
%73 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %9, i64 0, i64 3
%74 = getelementptr inbounds [4 x i32], [4 x i32]* %73, i64 0, i64 2
store i32 %72, i32* %74
%75 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %9, i64 0, i64 3
%76 = getelementptr inbounds [4 x i32], [4 x i32]* %75, i64 0, i64 3
store i32 0, i32* %76
%77 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %9, i64 0, i64 0
%78 = getelementptr inbounds [4 x i32], [4 x i32]* %77, i64 0, i64 0
%79 = call i32 @glMultMatrixd(i32* %78)
br label %80
80: ; preds = %34, %33
ret void
}

LLVM IR (-O2):
define void @gluPerspective(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [4 x [4 x i32]]
%6 = bitcast [4 x [4 x i32]]* %5 to i8*
%7 = sdiv i32 %0, 2
%8 = sitofp i32 %7 to double
%9 = fmul double %8, 0x400921FB54442D18
%10 = fdiv double %9, 1.800000e+02
%11 = sub nsw i32 %3, %2
%12 = sitofp i32 %11 to double
%13 = tail call double @sin(double %10)
%14 = icmp eq i32 %11, 0
%15 = fcmp oeq double %13, 0.000000e+00
%16 = select i1 %14, i1 true, i1 %15
%17 = icmp eq i32 %1, 0
%18 = or i1 %17, %16
br i1 %18, label %44, label %19
19: ; preds = %4
%20 = tail call double @cos(double %10)
%21 = fdiv double %20, %13
%22 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %5, i64 0, i64 0, i64 0
%23 = call i32 @__gluMakeIdentityd(i32* %22)
%24 = sitofp i32 %1 to double
%25 = fdiv double %21, %24
%26 = fptosi double %25 to i32
store i32 %26, i32* %22
%27 = fptosi double %21 to i32
%28 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %5, i64 0, i64 1, i64 1
store i32 %27, i32* %28
%29 = add nsw i32 %2, %3
%30 = sub nsw i32 0, %29
%31 = sitofp i32 %30 to double
%32 = fdiv double %31, %12
%33 = fptosi double %32 to i32
%34 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %5, i64 0, i64 2, i64 2
store i32 %33, i32* %34
%35 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %5, i64 0, i64 2, i64 3
store i32 -1, i32* %35
%36 = mul nsw i32 %2, -2
%37 = mul nsw i32 %36, %3
%38 = sitofp i32 %37 to double
%39 = fdiv double %38, %12
%40 = fptosi double %39 to i32
%41 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %5, i64 0, i64 3, i64 2
store i32 %40, i32* %41
%42 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %5, i64 0, i64 3, i64 3
store i32 0, i32* %42
%43 = call i32 @glMultMatrixd(i32* %22)
br label %44
44: ; preds = %4, %19
ret void
}