void homography_from_four_points(double H[3][3], double x[2], double w[2],
                                 double z[2], double y[2]) {
  double t = 1;
  double p = x[0];
  double q = x[1];
  double A = w[0] - z[0];
  double B = y[0] - z[0];
  double C = w[1] - z[1];
  double D = y[1] - z[1];
  double P = z[0] - y[0] - w[0] + p;
  double Q = z[1] - y[1] - w[1] + q;
  double DET = A * D - B * C;
  double r = (D * P - B * Q) / DET;
  double s = (A * Q - C * P) / DET;
  double a = w[0] * (1 + r) - p;
  double b = y[0] * (1 + s) - p;
  double c = w[1] * (1 + r) - q;
  double d = y[1] * (1 + s) - q;
  H[0][0] = a;
  H[0][1] = b;
  H[0][2] = p;
  H[1][0] = c;
  H[1][1] = d;
  H[1][2] = q;
  H[2][0] = r;
  H[2][1] = s;
  H[2][2] = t;
}


x86 assembly (clang, -O0):
<homography_from_four_points>:
push   %rbp
mov    %rsp,%rbp
sub    $0x28,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movsd  0xedc(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x20(%rbp),%rax
subsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x28(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x20(%rbp),%rax
subsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x28(%rbp),%rax
subsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
subsd  (%rax),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x20(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x28(%rbp),%rax
subsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
subsd  0x8(%rax),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm1
mulsd  -0x58(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm1
mulsd  -0x70(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x70(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm1
mulsd  -0x68(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xd58(%rip),%xmm2
addsd  -0x80(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xd17(%rip),%xmm2
addsd  -0x88(%rbp),%xmm2
ff
movsd  -0x38(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  0xcd2(%rip),%xmm2
addsd  -0x80(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
mov    -0x28(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  0xc90(%rip),%xmm2
addsd  -0x88(%rbp),%xmm2
ff
movsd  -0x40(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0x90(%rbp),%xmm0
ff
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x98(%rbp),%xmm0
ff
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x38(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  -0xa0(%rbp),%xmm0
ff
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x18(%rax)
movsd  -0xa8(%rbp),%xmm0
ff
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x20(%rax)
movsd  -0x40(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x28(%rax)
movsd  -0x80(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x30(%rax)
movsd  -0x88(%rbp),%xmm0
ff
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x38(%rax)
movsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x40(%rax)
add    $0x28,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<homography_from_four_points>:
movupd (%rsi),%xmm0
movupd (%rdx),%xmm1
movupd (%rcx),%xmm3
movupd (%r8),%xmm2
movapd %xmm1,%xmm5
movsd  %xmm2,%xmm5
subpd  %xmm3,%xmm5
movapd %xmm2,%xmm4
movsd  %xmm1,%xmm4
subpd  %xmm3,%xmm4
movapd %xmm4,%xmm6
unpckhpd %xmm4,%xmm6
mulsd  %xmm4,%xmm6
shufpd $0x1,%xmm4,%xmm4
subpd  %xmm2,%xmm3
subpd  %xmm1,%xmm3
addpd  %xmm0,%xmm3
movapd 0xeb2(%rip),%xmm7
xorpd  %xmm5,%xmm7
mulpd  %xmm3,%xmm4
shufpd $0x1,%xmm3,%xmm3
mulpd  %xmm5,%xmm3
unpckhpd %xmm5,%xmm5
mulsd  %xmm7,%xmm5
addsd  %xmm5,%xmm6
subpd  %xmm3,%xmm4
unpcklpd %xmm6,%xmm6
divpd  %xmm6,%xmm4
movapd 0xe91(%rip),%xmm3
addpd  %xmm4,%xmm3
movapd %xmm1,%xmm5
unpcklpd %xmm2,%xmm5
movapd %xmm0,%xmm6
unpcklpd %xmm0,%xmm6
mulpd  %xmm3,%xmm5
subpd  %xmm6,%xmm5
movapd %xmm0,%xmm6
unpckhpd %xmm0,%xmm6
unpckhpd %xmm2,%xmm1
mulpd  %xmm3,%xmm1
subpd  %xmm6,%xmm1
movupd %xmm5,(%rdi)
movlpd %xmm0,0x10(%rdi)
movupd %xmm1,0x18(%rdi)
movhpd %xmm0,0x28(%rdi)
movupd %xmm4,0x30(%rdi)
movabs $0x3ff0000000000000,%rax
mov    %rax,0x40(%rdi)
ret

LLVM IR (-O0):
define void @homography_from_four_points([3 x double]* %0, double* %1, double* %2, double* %3, double* %4) {
%6 = alloca [3 x double]*
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca double
%24 = alloca double
%25 = alloca double
%26 = alloca double
store [3 x double]* %0, [3 x double]** %6
store double* %1, double** %7
store double* %2, double** %8
store double* %3, double** %9
store double* %4, double** %10
store double 1.000000e+00, double* %11
%27 = load double*, double** %7
%28 = getelementptr inbounds double, double* %27, i64 0
%29 = load double, double* %28
store double %29, double* %12
%30 = load double*, double** %7
%31 = getelementptr inbounds double, double* %30, i64 1
%32 = load double, double* %31
store double %32, double* %13
%33 = load double*, double** %8
%34 = getelementptr inbounds double, double* %33, i64 0
%35 = load double, double* %34
%36 = load double*, double** %9
%37 = getelementptr inbounds double, double* %36, i64 0
%38 = load double, double* %37
%39 = fsub double %35, %38
store double %39, double* %14
%40 = load double*, double** %10
%41 = getelementptr inbounds double, double* %40, i64 0
%42 = load double, double* %41
%43 = load double*, double** %9
%44 = getelementptr inbounds double, double* %43, i64 0
%45 = load double, double* %44
%46 = fsub double %42, %45
store double %46, double* %15
%47 = load double*, double** %8
%48 = getelementptr inbounds double, double* %47, i64 1
%49 = load double, double* %48
%50 = load double*, double** %9
%51 = getelementptr inbounds double, double* %50, i64 1
%52 = load double, double* %51
%53 = fsub double %49, %52
store double %53, double* %16
%54 = load double*, double** %10
%55 = getelementptr inbounds double, double* %54, i64 1
%56 = load double, double* %55
%57 = load double*, double** %9
%58 = getelementptr inbounds double, double* %57, i64 1
%59 = load double, double* %58
%60 = fsub double %56, %59
store double %60, double* %17
%61 = load double*, double** %9
%62 = getelementptr inbounds double, double* %61, i64 0
%63 = load double, double* %62
%64 = load double*, double** %10
%65 = getelementptr inbounds double, double* %64, i64 0
%66 = load double, double* %65
%67 = fsub double %63, %66
%68 = load double*, double** %8
%69 = getelementptr inbounds double, double* %68, i64 0
%70 = load double, double* %69
%71 = fsub double %67, %70
%72 = load double, double* %12
%73 = fadd double %71, %72
store double %73, double* %18
%74 = load double*, double** %9
%75 = getelementptr inbounds double, double* %74, i64 1
%76 = load double, double* %75
%77 = load double*, double** %10
%78 = getelementptr inbounds double, double* %77, i64 1
%79 = load double, double* %78
%80 = fsub double %76, %79
%81 = load double*, double** %8
%82 = getelementptr inbounds double, double* %81, i64 1
%83 = load double, double* %82
%84 = fsub double %80, %83
%85 = load double, double* %13
%86 = fadd double %84, %85
store double %86, double* %19
%87 = load double, double* %14
%88 = load double, double* %17
%89 = load double, double* %15
%90 = load double, double* %16
%91 = fmul double %89, %90
%92 = fneg double %91
%93 = call double @llvm.fmuladd.f64(double %87, double %88, double %92)
store double %93, double* %20
%94 = load double, double* %17
%95 = load double, double* %18
%96 = load double, double* %15
%97 = load double, double* %19
%98 = fmul double %96, %97
%99 = fneg double %98
%100 = call double @llvm.fmuladd.f64(double %94, double %95, double %99)
%101 = load double, double* %20
%102 = fdiv double %100, %101
store double %102, double* %21
%103 = load double, double* %14
%104 = load double, double* %19
%105 = load double, double* %16
%106 = load double, double* %18
%107 = fmul double %105, %106
%108 = fneg double %107
%109 = call double @llvm.fmuladd.f64(double %103, double %104, double %108)
%110 = load double, double* %20
%111 = fdiv double %109, %110
store double %111, double* %22
%112 = load double*, double** %8
%113 = getelementptr inbounds double, double* %112, i64 0
%114 = load double, double* %113
%115 = load double, double* %21
%116 = fadd double 1.000000e+00, %115
%117 = load double, double* %12
%118 = fneg double %117
%119 = call double @llvm.fmuladd.f64(double %114, double %116, double %118)
store double %119, double* %23
%120 = load double*, double** %10
%121 = getelementptr inbounds double, double* %120, i64 0
%122 = load double, double* %121
%123 = load double, double* %22
%124 = fadd double 1.000000e+00, %123
%125 = load double, double* %12
%126 = fneg double %125
%127 = call double @llvm.fmuladd.f64(double %122, double %124, double %126)
store double %127, double* %24
%128 = load double*, double** %8
%129 = getelementptr inbounds double, double* %128, i64 1
%130 = load double, double* %129
%131 = load double, double* %21
%132 = fadd double 1.000000e+00, %131
%133 = load double, double* %13
%134 = fneg double %133
%135 = call double @llvm.fmuladd.f64(double %130, double %132, double %134)
store double %135, double* %25
%136 = load double*, double** %10
%137 = getelementptr inbounds double, double* %136, i64 1
%138 = load double, double* %137
%139 = load double, double* %22
%140 = fadd double 1.000000e+00, %139
%141 = load double, double* %13
%142 = fneg double %141
%143 = call double @llvm.fmuladd.f64(double %138, double %140, double %142)
store double %143, double* %26
%144 = load double, double* %23
%145 = load [3 x double]*, [3 x double]** %6
%146 = getelementptr inbounds [3 x double], [3 x double]* %145, i64 0
%147 = getelementptr inbounds [3 x double], [3 x double]* %146, i64 0, i64 0
store double %144, double* %147
%148 = load double, double* %24
%149 = load [3 x double]*, [3 x double]** %6
%150 = getelementptr inbounds [3 x double], [3 x double]* %149, i64 0
%151 = getelementptr inbounds [3 x double], [3 x double]* %150, i64 0, i64 1
store double %148, double* %151
%152 = load double, double* %12
%153 = load [3 x double]*, [3 x double]** %6
%154 = getelementptr inbounds [3 x double], [3 x double]* %153, i64 0
%155 = getelementptr inbounds [3 x double], [3 x double]* %154, i64 0, i64 2
store double %152, double* %155
%156 = load double, double* %25
%157 = load [3 x double]*, [3 x double]** %6
%158 = getelementptr inbounds [3 x double], [3 x double]* %157, i64 1
%159 = getelementptr inbounds [3 x double], [3 x double]* %158, i64 0, i64 0
store double %156, double* %159
%160 = load double, double* %26
%161 = load [3 x double]*, [3 x double]** %6
%162 = getelementptr inbounds [3 x double], [3 x double]* %161, i64 1
%163 = getelementptr inbounds [3 x double], [3 x double]* %162, i64 0, i64 1
store double %160, double* %163
%164 = load double, double* %13
%165 = load [3 x double]*, [3 x double]** %6
%166 = getelementptr inbounds [3 x double], [3 x double]* %165, i64 1
%167 = getelementptr inbounds [3 x double], [3 x double]* %166, i64 0, i64 2
store double %164, double* %167
%168 = load double, double* %21
%169 = load [3 x double]*, [3 x double]** %6
%170 = getelementptr inbounds [3 x double], [3 x double]* %169, i64 2
%171 = getelementptr inbounds [3 x double], [3 x double]* %170, i64 0, i64 0
store double %168, double* %171
%172 = load double, double* %22
%173 = load [3 x double]*, [3 x double]** %6
%174 = getelementptr inbounds [3 x double], [3 x double]* %173, i64 2
%175 = getelementptr inbounds [3 x double], [3 x double]* %174, i64 0, i64 1
store double %172, double* %175
%176 = load double, double* %11
%177 = load [3 x double]*, [3 x double]** %6
%178 = getelementptr inbounds [3 x double], [3 x double]* %177, i64 2
%179 = getelementptr inbounds [3 x double], [3 x double]* %178, i64 0, i64 2
store double %176, double* %179
ret void
}

LLVM IR (-O2):
define void @homography_from_four_points([3 x double]* nocapture writeonly %0, double* nocapture %1, double* nocapture %2, double* nocapture %3, double* nocapture %4) {
%6 = bitcast double* %1 to <2 x double>*
%7 = load <2 x double>, <2 x double>* %6
%8 = bitcast double* %2 to <2 x double>*
%9 = load <2 x double>, <2 x double>* %8
%10 = bitcast double* %3 to <2 x double>*
%11 = load <2 x double>, <2 x double>* %10
%12 = bitcast double* %4 to <2 x double>*
%13 = load <2 x double>, <2 x double>* %12
%14 = shufflevector <2 x double> %13, <2 x double> %9, <2 x i32> <i32 0, i32 3>
%15 = fsub <2 x double> %14, %11
%16 = shufflevector <2 x double> %9, <2 x double> %13, <2 x i32> <i32 0, i32 3>
%17 = fsub <2 x double> %16, %11
%18 = shufflevector <2 x double> %17, <2 x double> poison, <2 x i32> <i32 1, i32 0>
%19 = fsub <2 x double> %11, %13
%20 = fsub <2 x double> %19, %9
%21 = fadd <2 x double> %7, %20
%22 = fneg <2 x double> %15
%23 = shufflevector <2 x double> %15, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%24 = fmul <2 x double> %23, %22
%25 = extractelement <2 x double> %24, i64 0
%26 = extractelement <2 x double> %17, i64 0
%27 = extractelement <2 x double> %17, i64 1
%28 = tail call double @llvm.fmuladd.f64(double %26, double %27, double %25)
%29 = shufflevector <2 x double> %21, <2 x double> undef, <2 x i32> <i32 1, i32 0>
%30 = fmul <2 x double> %29, %22
%31 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %18, <2 x double> %21, <2 x double> %30)
%32 = insertelement <2 x double> poison, double %28, i64 0
%33 = shufflevector <2 x double> %32, <2 x double> poison, <2 x i32> zeroinitializer
%34 = fdiv <2 x double> %31, %33
%35 = extractelement <2 x double> %7, i64 0
%36 = fneg double %35
%37 = fadd <2 x double> %34, <double 1.000000e+00, double 1.000000e+00>
%38 = shufflevector <2 x double> %9, <2 x double> %13, <2 x i32> <i32 0, i32 2>
%39 = insertelement <2 x double> poison, double %36, i64 0
%40 = shufflevector <2 x double> %39, <2 x double> poison, <2 x i32> zeroinitializer
%41 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %38, <2 x double> %37, <2 x double> %40)
%42 = extractelement <2 x double> %7, i64 1
%43 = fneg double %42
%44 = shufflevector <2 x double> %9, <2 x double> %13, <2 x i32> <i32 1, i32 3>
%45 = insertelement <2 x double> poison, double %43, i64 0
%46 = shufflevector <2 x double> %45, <2 x double> poison, <2 x i32> zeroinitializer
%47 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %44, <2 x double> %37, <2 x double> %46)
%48 = bitcast [3 x double]* %0 to <2 x double>*
store <2 x double> %41, <2 x double>* %48
%49 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 0, i64 2
store double %35, double* %49
%50 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 1, i64 0
%51 = bitcast double* %50 to <2 x double>*
store <2 x double> %47, <2 x double>* %51
%52 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 1, i64 2
store double %42, double* %52
%53 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 2, i64 0
%54 = bitcast double* %53 to <2 x double>*
store <2 x double> %34, <2 x double>* %54
%55 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 2, i64 2
store double 1.000000e+00, double* %55
ret void
}