float matrixHeading(const float *const m) {
  if (m == (void *)0)
    return 0.0;
  if (fcmp(m[1], 1.0) || fcmp(m[1], -1.0))
    return atan2(m[8], m[10]);
  return atan2(-m[2], m[0]);
}


x86 assembly (clang, -O0):
<matrixHeading>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <matrixHeading+0x24>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11ef <matrixHeading+0xcf>
mov    -0x10(%rbp),%rax
movss  0x4(%rax),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xea7(%rip),%xmm1
mov    $0x2,%al
call   1040 <fcmp@plt>
cmp    $0x0,%eax
jne    118e <matrixHeading+0x6e>
mov    -0x10(%rbp),%rax
movss  0x4(%rax),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe8a(%rip),%xmm1
mov    $0x2,%al
call   1040 <fcmp@plt>
cmp    $0x0,%eax
je     11bb <matrixHeading+0x9b>
mov    -0x10(%rbp),%rax
movss  0x20(%rax),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x10(%rbp),%rax
movss  0x28(%rax),%xmm1
cvtss2sd %xmm1,%xmm1
call   1030 <atan2@plt>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11ef <matrixHeading+0xcf>
mov    -0x10(%rbp),%rax
movss  0x8(%rax),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm1
cvtss2sd %xmm1,%xmm1
call   1030 <atan2@plt>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrixHeading>:
test   %rdi,%rdi
je     1181 <matrixHeading+0x61>
push   %rbx
mov    %rdi,%rbx
movss  0x4(%rdi),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xec6(%rip),%xmm1
mov    $0x2,%al
call   1040 <fcmp@plt>
test   %eax,%eax
jne    1161 <matrixHeading+0x41>
movss  0x4(%rbx),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xeb2(%rip),%xmm1
mov    $0x2,%al
call   1040 <fcmp@plt>
test   %eax,%eax
je     1185 <matrixHeading+0x65>
movss  0x20(%rbx),%xmm0
add    $0x28,%rbx
cvtss2sd %xmm0,%xmm0
movss  (%rbx),%xmm1
cvtss2sd %xmm1,%xmm1
call   1030 <atan2@plt>
cvtsd2ss %xmm0,%xmm0
pop    %rbx
ret
xorps  %xmm0,%xmm0
ret
movss  0x8(%rbx),%xmm0
xorps  0xe7f(%rip),%xmm0
jmp    116a <matrixHeading+0x4a>

LLVM IR (-O0):
define float @matrixHeading(float* %0) {
%2 = alloca float
%3 = alloca float*
store float* %0, float** %3
%4 = load float*, float** %3
%5 = icmp eq float* %4, null
br i1 %5, label %6, label %7
6: ; preds = %1
store float 0.000000e+00, float* %2
br label %44
7: ; preds = %1
%8 = load float*, float** %3
%9 = getelementptr inbounds float, float* %8, i64 1
%10 = load float, float* %9
%11 = fpext float %10 to double
%12 = call i32 (double, double, ...) bitcast (i32 (...)* @fcmp to i32 (double, double, ...)*)(double %11, double 1.000000e+00)
%13 = icmp ne i32 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %7
%15 = load float*, float** %3
%16 = getelementptr inbounds float, float* %15, i64 1
%17 = load float, float* %16
%18 = fpext float %17 to double
%19 = call i32 (double, double, ...) bitcast (i32 (...)* @fcmp to i32 (double, double, ...)*)(double %18, double -1.000000e+00)
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %14, %7
%22 = load float*, float** %3
%23 = getelementptr inbounds float, float* %22, i64 8
%24 = load float, float* %23
%25 = fpext float %24 to double
%26 = load float*, float** %3
%27 = getelementptr inbounds float, float* %26, i64 10
%28 = load float, float* %27
%29 = fpext float %28 to double
%30 = call double @atan2(double %25, double %29)
%31 = fptrunc double %30 to float
store float %31, float* %2
br label %44
32: ; preds = %14
%33 = load float*, float** %3
%34 = getelementptr inbounds float, float* %33, i64 2
%35 = load float, float* %34
%36 = fneg float %35
%37 = fpext float %36 to double
%38 = load float*, float** %3
%39 = getelementptr inbounds float, float* %38, i64 0
%40 = load float, float* %39
%41 = fpext float %40 to double
%42 = call double @atan2(double %37, double %41)
%43 = fptrunc double %42 to float
store float %43, float* %2
br label %44
44: ; preds = %32, %21, %6
%45 = load float, float* %2
ret float %45
}

LLVM IR (-O2):
define float @matrixHeading(float* %0) {
%2 = icmp eq float* %0, null
br i1 %2, label %30, label %3
3: ; preds = %1
%4 = getelementptr inbounds float, float* %0, i64 1
%5 = load float, float* %4
%6 = fpext float %5 to double
%7 = tail call i32 (double, double, ...) bitcast (i32 (...)* @fcmp to i32 (double, double, ...)*)(double %6, double 1.000000e+00)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = load float, float* %4
%11 = fpext float %10 to double
%12 = tail call i32 (double, double, ...) bitcast (i32 (...)* @fcmp to i32 (double, double, ...)*)(double %11, double -1.000000e+00)
%13 = icmp eq i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %9, %3
%15 = getelementptr inbounds float, float* %0, i64 8
%16 = load float, float* %15
%17 = getelementptr inbounds float, float* %0, i64 10
br label %22
18: ; preds = %9
%19 = getelementptr inbounds float, float* %0, i64 2
%20 = load float, float* %19
%21 = fneg float %20
br label %22
22: ; preds = %14, %18
%23 = phi float* [ %0, %18 ], [ %17, %14 ]
%24 = phi float [ %21, %18 ], [ %16, %14 ]
%25 = fpext float %24 to double
%26 = load float, float* %23
%27 = fpext float %26 to double
%28 = tail call double @atan2(double %25, double %27)
%29 = fptrunc double %28 to float
br label %30
30: ; preds = %22, %1
%31 = phi float [ 0.000000e+00, %1 ], [ %29, %22 ]
ret float %31
}