int bot_matrix_inverse_2x2d(const double m[4], double inverse[4]) {
  double det = m[0] * m[3] - m[1] * m[2];
  if (det == 0)
    return -1;
  inverse[0] = m[3] / det;
  inverse[1] = -m[1] / det;
  inverse[2] = -m[2] / det;
  inverse[3] = m[0] / det;
  return 0;
}


x86 assembly (clang, -O0):
<bot_matrix_inverse_2x2d>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x10(%rbp),%rax
mulsd  0x10(%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1177 <bot_matrix_inverse_2x2d+0x77>
jp     1177 <bot_matrix_inverse_2x2d+0x77>
movl   $0xffffffff,-0x4(%rbp)
jmp    1206 <bot_matrix_inverse_2x2d+0x106>
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x18(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<bot_matrix_inverse_2x2d>:
movsd  0x10(%rdi),%xmm2
mulsd  0x8(%rdi),%xmm2
movsd  0x18(%rdi),%xmm1
movsd  (%rdi),%xmm0
mulsd  %xmm1,%xmm0
subsd  %xmm2,%xmm0
mov    $0xffffffff,%eax
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jne    112d <bot_matrix_inverse_2x2d+0x2d>
jp     112d <bot_matrix_inverse_2x2d+0x2d>
ret
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsi)
movsd  0x8(%rdi),%xmm1
movapd 0xebe(%rip),%xmm2
xorpd  %xmm2,%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsi)
movsd  0x10(%rdi),%xmm1
xorpd  %xmm2,%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsi)
movsd  (%rdi),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsi)
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @bot_matrix_inverse_2x2d(double* %0, double* %1) {
%3 = alloca i32
%4 = alloca double*
%5 = alloca double*
%6 = alloca double
store double* %0, double** %4
store double* %1, double** %5
%7 = load double*, double** %4
%8 = getelementptr inbounds double, double* %7, i64 0
%9 = load double, double* %8
%10 = load double*, double** %4
%11 = getelementptr inbounds double, double* %10, i64 3
%12 = load double, double* %11
%13 = load double*, double** %4
%14 = getelementptr inbounds double, double* %13, i64 1
%15 = load double, double* %14
%16 = load double*, double** %4
%17 = getelementptr inbounds double, double* %16, i64 2
%18 = load double, double* %17
%19 = fmul double %15, %18
%20 = fneg double %19
%21 = call double @llvm.fmuladd.f64(double %9, double %12, double %20)
store double %21, double* %6
%22 = load double, double* %6
%23 = fcmp oeq double %22, 0.000000e+00
br i1 %23, label %24, label %25
24: ; preds = %2
store i32 -1, i32* %3
br label %56
25: ; preds = %2
%26 = load double*, double** %4
%27 = getelementptr inbounds double, double* %26, i64 3
%28 = load double, double* %27
%29 = load double, double* %6
%30 = fdiv double %28, %29
%31 = load double*, double** %5
%32 = getelementptr inbounds double, double* %31, i64 0
store double %30, double* %32
%33 = load double*, double** %4
%34 = getelementptr inbounds double, double* %33, i64 1
%35 = load double, double* %34
%36 = fneg double %35
%37 = load double, double* %6
%38 = fdiv double %36, %37
%39 = load double*, double** %5
%40 = getelementptr inbounds double, double* %39, i64 1
store double %38, double* %40
%41 = load double*, double** %4
%42 = getelementptr inbounds double, double* %41, i64 2
%43 = load double, double* %42
%44 = fneg double %43
%45 = load double, double* %6
%46 = fdiv double %44, %45
%47 = load double*, double** %5
%48 = getelementptr inbounds double, double* %47, i64 2
store double %46, double* %48
%49 = load double*, double** %4
%50 = getelementptr inbounds double, double* %49, i64 0
%51 = load double, double* %50
%52 = load double, double* %6
%53 = fdiv double %51, %52
%54 = load double*, double** %5
%55 = getelementptr inbounds double, double* %54, i64 3
store double %53, double* %55
store i32 0, i32* %3
br label %56
56: ; preds = %25, %24
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
define i32 @bot_matrix_inverse_2x2d(double* nocapture %0, double* nocapture writeonly %1) {
%3 = load double, double* %0
%4 = getelementptr inbounds double, double* %0, i64 3
%5 = load double, double* %4
%6 = getelementptr inbounds double, double* %0, i64 1
%7 = load double, double* %6
%8 = getelementptr inbounds double, double* %0, i64 2
%9 = load double, double* %8
%10 = fneg double %7
%11 = fmul double %9, %10
%12 = tail call double @llvm.fmuladd.f64(double %3, double %5, double %11)
%13 = fcmp oeq double %12, 0.000000e+00
br i1 %13, label %27, label %14
14: ; preds = %2
%15 = fdiv double %5, %12
store double %15, double* %1
%16 = load double, double* %6
%17 = fneg double %16
%18 = fdiv double %17, %12
%19 = getelementptr inbounds double, double* %1, i64 1
store double %18, double* %19
%20 = load double, double* %8
%21 = fneg double %20
%22 = fdiv double %21, %12
%23 = getelementptr inbounds double, double* %1, i64 2
store double %22, double* %23
%24 = load double, double* %0
%25 = fdiv double %24, %12
%26 = getelementptr inbounds double, double* %1, i64 3
store double %25, double* %26
br label %27
27: ; preds = %2, %14
%28 = phi i32 [ 0, %14 ], [ -1, %2 ]
ret i32 %28
}