void apply_homography(double y[2], double H[3][3], double x[2]) {
  double X = H[0][0] * x[0] + H[0][1] * x[1] + H[0][2];
  double Y = H[1][0] * x[0] + H[1][1] * x[1] + H[1][2];
  double Z = H[2][0] * x[0] + H[2][1] * x[1] + H[2][2];
  y[0] = X / Z;
  y[1] = Y / Z;
}


x86 assembly (clang, -O0):
<apply_homography>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
addsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x20(%rax),%xmm1
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
addsd  0x28(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x30(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x38(%rax),%xmm1
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
addsd  0x40(%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<apply_homography>:
movsd  (%rdx),%xmm0
movsd  0x8(%rdx),%xmm1
movapd %xmm1,%xmm2
unpcklpd %xmm1,%xmm2
movsd  (%rsi),%xmm3
movsd  0x8(%rsi),%xmm4
movhpd 0x20(%rsi),%xmm4
movsd  0x10(%rsi),%xmm5
mulpd  %xmm2,%xmm4
movhpd 0x18(%rsi),%xmm3
movapd %xmm0,%xmm2
unpcklpd %xmm0,%xmm2
mulpd  %xmm3,%xmm2
movhpd 0x28(%rsi),%xmm5
mulsd  0x38(%rsi),%xmm1
mulsd  0x30(%rsi),%xmm0
addpd  %xmm4,%xmm2
addsd  %xmm1,%xmm0
addsd  0x40(%rsi),%xmm0
addpd  %xmm2,%xmm5
unpcklpd %xmm0,%xmm0
divpd  %xmm0,%xmm5
movupd %xmm5,(%rdi)
ret

LLVM IR (-O0):
define void @apply_homography(double* %0, [3 x double]* %1, double* %2) {
%4 = alloca double*
%5 = alloca [3 x double]*
%6 = alloca double*
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double* %0, double** %4
store [3 x double]* %1, [3 x double]** %5
store double* %2, double** %6
%10 = load [3 x double]*, [3 x double]** %5
%11 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0
%12 = getelementptr inbounds [3 x double], [3 x double]* %11, i64 0, i64 0
%13 = load double, double* %12
%14 = load double*, double** %6
%15 = getelementptr inbounds double, double* %14, i64 0
%16 = load double, double* %15
%17 = load [3 x double]*, [3 x double]** %5
%18 = getelementptr inbounds [3 x double], [3 x double]* %17, i64 0
%19 = getelementptr inbounds [3 x double], [3 x double]* %18, i64 0, i64 1
%20 = load double, double* %19
%21 = load double*, double** %6
%22 = getelementptr inbounds double, double* %21, i64 1
%23 = load double, double* %22
%24 = fmul double %20, %23
%25 = call double @llvm.fmuladd.f64(double %13, double %16, double %24)
%26 = load [3 x double]*, [3 x double]** %5
%27 = getelementptr inbounds [3 x double], [3 x double]* %26, i64 0
%28 = getelementptr inbounds [3 x double], [3 x double]* %27, i64 0, i64 2
%29 = load double, double* %28
%30 = fadd double %25, %29
store double %30, double* %7
%31 = load [3 x double]*, [3 x double]** %5
%32 = getelementptr inbounds [3 x double], [3 x double]* %31, i64 1
%33 = getelementptr inbounds [3 x double], [3 x double]* %32, i64 0, i64 0
%34 = load double, double* %33
%35 = load double*, double** %6
%36 = getelementptr inbounds double, double* %35, i64 0
%37 = load double, double* %36
%38 = load [3 x double]*, [3 x double]** %5
%39 = getelementptr inbounds [3 x double], [3 x double]* %38, i64 1
%40 = getelementptr inbounds [3 x double], [3 x double]* %39, i64 0, i64 1
%41 = load double, double* %40
%42 = load double*, double** %6
%43 = getelementptr inbounds double, double* %42, i64 1
%44 = load double, double* %43
%45 = fmul double %41, %44
%46 = call double @llvm.fmuladd.f64(double %34, double %37, double %45)
%47 = load [3 x double]*, [3 x double]** %5
%48 = getelementptr inbounds [3 x double], [3 x double]* %47, i64 1
%49 = getelementptr inbounds [3 x double], [3 x double]* %48, i64 0, i64 2
%50 = load double, double* %49
%51 = fadd double %46, %50
store double %51, double* %8
%52 = load [3 x double]*, [3 x double]** %5
%53 = getelementptr inbounds [3 x double], [3 x double]* %52, i64 2
%54 = getelementptr inbounds [3 x double], [3 x double]* %53, i64 0, i64 0
%55 = load double, double* %54
%56 = load double*, double** %6
%57 = getelementptr inbounds double, double* %56, i64 0
%58 = load double, double* %57
%59 = load [3 x double]*, [3 x double]** %5
%60 = getelementptr inbounds [3 x double], [3 x double]* %59, i64 2
%61 = getelementptr inbounds [3 x double], [3 x double]* %60, i64 0, i64 1
%62 = load double, double* %61
%63 = load double*, double** %6
%64 = getelementptr inbounds double, double* %63, i64 1
%65 = load double, double* %64
%66 = fmul double %62, %65
%67 = call double @llvm.fmuladd.f64(double %55, double %58, double %66)
%68 = load [3 x double]*, [3 x double]** %5
%69 = getelementptr inbounds [3 x double], [3 x double]* %68, i64 2
%70 = getelementptr inbounds [3 x double], [3 x double]* %69, i64 0, i64 2
%71 = load double, double* %70
%72 = fadd double %67, %71
store double %72, double* %9
%73 = load double, double* %7
%74 = load double, double* %9
%75 = fdiv double %73, %74
%76 = load double*, double** %4
%77 = getelementptr inbounds double, double* %76, i64 0
store double %75, double* %77
%78 = load double, double* %8
%79 = load double, double* %9
%80 = fdiv double %78, %79
%81 = load double*, double** %4
%82 = getelementptr inbounds double, double* %81, i64 1
store double %80, double* %82
ret void
}

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