void mat44Perspective(double left, double right, double bottom, double top,
                      double far, double near, double proj[4][4]) {
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      proj[i][j] = 0;
    }
  }
  proj[0][0] = -(2 * near) / (right - left);
  proj[1][1] = -(2 * near) / (top - bottom);
  proj[2][2] = (near + far) / (far - near);
  proj[0][2] = (right + left) / (right - left);
  proj[1][2] = (top + bottom) / (top - bottom);
  proj[3][2] = -1;
  proj[2][3] = (2 * near * far) / (near - far);
}


x86 assembly (clang, -O0):
<mat44Perspective>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  %xmm4,-0x28(%rbp)
movsd  %xmm5,-0x30(%rbp)
mov    %rdi,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x4,-0x3c(%rbp)
jge    1184 <mat44Perspective+0x84>
movl   $0x0,-0x40(%rbp)
cmpl   $0x4,-0x40(%rbp)
jge    1171 <mat44Perspective+0x71>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
shl    $0x5,%rcx
add    %rcx,%rax
movslq -0x40(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    113e <mat44Perspective+0x3e>
jmp    1176 <mat44Perspective+0x76>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    112d <mat44Perspective+0x2d>
movsd  0xe74(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  -0x10(%rbp),%xmm1
subsd  -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  0xe3a(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  -0x20(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,0x28(%rax)
movsd  -0x30(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
subsd  -0x30(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,0x50(%rax)
movsd  -0x10(%rbp),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
subsd  -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,0x30(%rax)
mov    -0x38(%rbp),%rax
movsd  0xda0(%rip),%xmm0
movsd  %xmm0,0x70(%rax)
movsd  0xd8b(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
subsd  -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,0x58(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<mat44Perspective>:
xorps  %xmm6,%xmm6
movups %xmm6,0x8(%rdi)
movups %xmm6,0x68(%rdi)
movups %xmm6,0x58(%rdi)
movups %xmm6,0x48(%rdi)
movups %xmm6,0x38(%rdi)
movups %xmm6,0x18(%rdi)
movq   $0x0,0x78(%rdi)
movapd %xmm5,%xmm8
addsd  %xmm5,%xmm8
movapd 0xecb(%rip),%xmm6
xorpd  %xmm8,%xmm6
movapd %xmm1,%xmm9
subsd  %xmm0,%xmm9
movapd %xmm6,%xmm7
divsd  %xmm9,%xmm7
movsd  %xmm7,(%rdi)
movapd %xmm3,%xmm7
subsd  %xmm2,%xmm7
addsd  %xmm1,%xmm0
divsd  %xmm9,%xmm0
movsd  %xmm0,0x10(%rdi)
addsd  %xmm3,%xmm2
unpcklpd %xmm2,%xmm6
unpcklpd %xmm7,%xmm7
divpd  %xmm7,%xmm6
movupd %xmm6,0x28(%rdi)
movabs $0xbff0000000000000,%rax
mov    %rax,0x70(%rdi)
movapd %xmm5,%xmm0
movapd %xmm4,%xmm1
addsd  %xmm5,%xmm1
movapd %xmm4,%xmm2
unpcklpd %xmm5,%xmm2
unpcklpd %xmm4,%xmm5
unpcklpd %xmm4,%xmm4
unpcklpd %xmm8,%xmm0
mulpd  %xmm4,%xmm0
shufpd $0x2,%xmm0,%xmm1
subpd  %xmm5,%xmm2
divpd  %xmm2,%xmm1
movupd %xmm1,0x50(%rdi)
ret

LLVM IR (-O0):
define void @mat44Perspective(double %0, double %1, double %2, double %3, double %4, double %5, [4 x double]* %6) {
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca [4 x double]*
%15 = alloca i32
%16 = alloca i32
store double %0, double* %8
store double %1, double* %9
store double %2, double* %10
store double %3, double* %11
store double %4, double* %12
store double %5, double* %13
store [4 x double]* %6, [4 x double]** %14
store i32 0, i32* %15
br label %17
17: ; preds = %36, %7
%18 = load i32, i32* %15
%19 = icmp slt i32 %18, 4
br i1 %19, label %20, label %39
20: ; preds = %17
store i32 0, i32* %16
br label %21
21: ; preds = %32, %20
%22 = load i32, i32* %16
%23 = icmp slt i32 %22, 4
br i1 %23, label %24, label %35
24: ; preds = %21
%25 = load [4 x double]*, [4 x double]** %14
%26 = load i32, i32* %15
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [4 x double], [4 x double]* %25, i64 %27
%29 = load i32, i32* %16
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [4 x double], [4 x double]* %28, i64 0, i64 %30
store double 0.000000e+00, double* %31
br label %32
32: ; preds = %24
%33 = load i32, i32* %16
%34 = add nsw i32 %33, 1
store i32 %34, i32* %16
br label %21
35: ; preds = %21
br label %36
36: ; preds = %35
%37 = load i32, i32* %15
%38 = add nsw i32 %37, 1
store i32 %38, i32* %15
br label %17
39: ; preds = %17
%40 = load double, double* %13
%41 = fmul double 2.000000e+00, %40
%42 = fneg double %41
%43 = load double, double* %9
%44 = load double, double* %8
%45 = fsub double %43, %44
%46 = fdiv double %42, %45
%47 = load [4 x double]*, [4 x double]** %14
%48 = getelementptr inbounds [4 x double], [4 x double]* %47, i64 0
%49 = getelementptr inbounds [4 x double], [4 x double]* %48, i64 0, i64 0
store double %46, double* %49
%50 = load double, double* %13
%51 = fmul double 2.000000e+00, %50
%52 = fneg double %51
%53 = load double, double* %11
%54 = load double, double* %10
%55 = fsub double %53, %54
%56 = fdiv double %52, %55
%57 = load [4 x double]*, [4 x double]** %14
%58 = getelementptr inbounds [4 x double], [4 x double]* %57, i64 1
%59 = getelementptr inbounds [4 x double], [4 x double]* %58, i64 0, i64 1
store double %56, double* %59
%60 = load double, double* %13
%61 = load double, double* %12
%62 = fadd double %60, %61
%63 = load double, double* %12
%64 = load double, double* %13
%65 = fsub double %63, %64
%66 = fdiv double %62, %65
%67 = load [4 x double]*, [4 x double]** %14
%68 = getelementptr inbounds [4 x double], [4 x double]* %67, i64 2
%69 = getelementptr inbounds [4 x double], [4 x double]* %68, i64 0, i64 2
store double %66, double* %69
%70 = load double, double* %9
%71 = load double, double* %8
%72 = fadd double %70, %71
%73 = load double, double* %9
%74 = load double, double* %8
%75 = fsub double %73, %74
%76 = fdiv double %72, %75
%77 = load [4 x double]*, [4 x double]** %14
%78 = getelementptr inbounds [4 x double], [4 x double]* %77, i64 0
%79 = getelementptr inbounds [4 x double], [4 x double]* %78, i64 0, i64 2
store double %76, double* %79
%80 = load double, double* %11
%81 = load double, double* %10
%82 = fadd double %80, %81
%83 = load double, double* %11
%84 = load double, double* %10
%85 = fsub double %83, %84
%86 = fdiv double %82, %85
%87 = load [4 x double]*, [4 x double]** %14
%88 = getelementptr inbounds [4 x double], [4 x double]* %87, i64 1
%89 = getelementptr inbounds [4 x double], [4 x double]* %88, i64 0, i64 2
store double %86, double* %89
%90 = load [4 x double]*, [4 x double]** %14
%91 = getelementptr inbounds [4 x double], [4 x double]* %90, i64 3
%92 = getelementptr inbounds [4 x double], [4 x double]* %91, i64 0, i64 2
store double -1.000000e+00, double* %92
%93 = load double, double* %13
%94 = fmul double 2.000000e+00, %93
%95 = load double, double* %12
%96 = fmul double %94, %95
%97 = load double, double* %13
%98 = load double, double* %12
%99 = fsub double %97, %98
%100 = fdiv double %96, %99
%101 = load [4 x double]*, [4 x double]** %14
%102 = getelementptr inbounds [4 x double], [4 x double]* %101, i64 2
%103 = getelementptr inbounds [4 x double], [4 x double]* %102, i64 0, i64 3
store double %100, double* %103
ret void
}

LLVM IR (-O2):
define void @mat44Perspective(double %0, double %1, double %2, double %3, double %4, double %5, [4 x double]* nocapture writeonly %6) {
%8 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 1
%9 = bitcast double* %8 to i8*
%10 = fmul double %5, 2.000000e+00
%11 = fneg double %10
%12 = fsub double %1, %0
%13 = fdiv double %11, %12
%14 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 0
store double %13, double* %14
%15 = fsub double %3, %2
%16 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 1, i64 1
%17 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 2, i64 2
%18 = fadd double %0, %1
%19 = fdiv double %18, %12
%20 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 2
store double %19, double* %20
%21 = fadd double %2, %3
%22 = insertelement <2 x double> poison, double %11, i64 0
%23 = insertelement <2 x double> %22, double %21, i64 1
%24 = insertelement <2 x double> poison, double %15, i64 0
%25 = shufflevector <2 x double> %24, <2 x double> poison, <2 x i32> zeroinitializer
%26 = fdiv <2 x double> %23, %25
%27 = bitcast double* %16 to <2 x double>*
store <2 x double> %26, <2 x double>* %27
%28 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 3, i64 2
store double -1.000000e+00, double* %28
%29 = insertelement <2 x double> poison, double %4, i64 0
%30 = shufflevector <2 x double> %29, <2 x double> poison, <2 x i32> zeroinitializer
%31 = insertelement <2 x double> poison, double %5, i64 0
%32 = insertelement <2 x double> %31, double %10, i64 1
%33 = fadd <2 x double> %30, %32
%34 = fmul <2 x double> %30, %32
%35 = shufflevector <2 x double> %33, <2 x double> %34, <2 x i32> <i32 0, i32 3>
%36 = insertelement <2 x double> %29, double %5, i64 1
%37 = insertelement <2 x double> %31, double %4, i64 1
%38 = fsub <2 x double> %36, %37
%39 = fdiv <2 x double> %35, %38
%40 = bitcast double* %17 to <2 x double>*
store <2 x double> %39, <2 x double>* %40
ret void
}