#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double acos(double);
double atan2(double, double);
double cos(double);
int fabs(double);
double sin(double);
void lmattoabg(double *r, double *abg) {
  abg[1] = acos(r[8]);
  abg[2] = atan2(r[6], -r[7]);
  abg[0] = atan2(r[2], r[5]);
  if (fabs(sin(abg[2]) * cos(abg[0]) + cos(abg[2]) * cos(abg[1]) * sin(abg[0]) -
           r[1]) > 1e-6) {
    abg[1] = -acos(r[8]);
    abg[2] = atan2(-r[6], r[7]);
    abg[0] = atan2(-r[2], -r[5]);
  }
}


x86 assembly (clang, -O0):
<lmattoabg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x40(%rax),%xmm0
call   1040 <acos@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movsd  0x30(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x38(%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
call   1030 <atan2@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x28(%rax),%xmm1
call   1030 <atan2@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
call   1060 <sin@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
call   1070 <cos@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
call   1070 <cos@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
call   1070 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
call   1060 <sin@plt>
movsd  -0x28(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x18(%rbp),%xmm0
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
subsd  0x8(%rax),%xmm0
call   1050 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xd97(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1325 <lmattoabg+0x1d5>
mov    -0x8(%rbp),%rax
movsd  0x40(%rax),%xmm0
call   1040 <acos@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movsd  0x30(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x8(%rbp),%rax
movsd  0x38(%rax),%xmm1
call   1030 <atan2@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x8(%rbp),%rax
movsd  0x28(%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
call   1030 <atan2@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lmattoabg>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movsd  0x40(%rdi),%xmm0
call   1040 <acos@plt>
movsd  %xmm0,0x8(%r14)
movsd  0x30(%rbx),%xmm0
movsd  0x38(%rbx),%xmm1
xorps  0xe82(%rip),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,0x10(%r14)
movsd  0x10(%rbx),%xmm0
movsd  0x28(%rbx),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,(%r14)
movsd  0x10(%r14),%xmm0
call   1060 <sin@plt>
movsd  %xmm0,0x10(%rsp)
movsd  (%r14),%xmm0
call   1070 <cos@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%r14),%xmm0
call   1070 <cos@plt>
movsd  %xmm0,(%rsp)
movsd  0x8(%r14),%xmm0
call   1070 <cos@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  (%r14),%xmm0
call   1060 <sin@plt>
mulsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  0x10(%rsp),%xmm1
addsd  %xmm1,%xmm0
subsd  0x8(%rbx),%xmm0
call   1050 <fabs@plt>
test   %eax,%eax
jle    1265 <lmattoabg+0x115>
movsd  0x40(%rbx),%xmm0
call   1040 <acos@plt>
movaps 0xddf(%rip),%xmm1
xorps  %xmm1,%xmm0
movlps %xmm0,0x8(%r14)
movsd  0x30(%rbx),%xmm0
xorps  %xmm1,%xmm0
movsd  0x38(%rbx),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,0x10(%r14)
movsd  0x10(%rbx),%xmm0
movsd  0x28(%rbx),%xmm1
movapd 0xdad(%rip),%xmm2
xorpd  %xmm2,%xmm0
xorpd  %xmm2,%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @lmattoabg(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
store double* %0, double** %3
store double* %1, double** %4
%5 = load double*, double** %3
%6 = getelementptr inbounds double, double* %5, i64 8
%7 = load double, double* %6
%8 = call double @acos(double %7)
%9 = load double*, double** %4
%10 = getelementptr inbounds double, double* %9, i64 1
store double %8, double* %10
%11 = load double*, double** %3
%12 = getelementptr inbounds double, double* %11, i64 6
%13 = load double, double* %12
%14 = load double*, double** %3
%15 = getelementptr inbounds double, double* %14, i64 7
%16 = load double, double* %15
%17 = fneg double %16
%18 = call double @atan2(double %13, double %17)
%19 = load double*, double** %4
%20 = getelementptr inbounds double, double* %19, i64 2
store double %18, double* %20
%21 = load double*, double** %3
%22 = getelementptr inbounds double, double* %21, i64 2
%23 = load double, double* %22
%24 = load double*, double** %3
%25 = getelementptr inbounds double, double* %24, i64 5
%26 = load double, double* %25
%27 = call double @atan2(double %23, double %26)
%28 = load double*, double** %4
%29 = getelementptr inbounds double, double* %28, i64 0
store double %27, double* %29
%30 = load double*, double** %4
%31 = getelementptr inbounds double, double* %30, i64 2
%32 = load double, double* %31
%33 = call double @sin(double %32)
%34 = load double*, double** %4
%35 = getelementptr inbounds double, double* %34, i64 0
%36 = load double, double* %35
%37 = call double @cos(double %36)
%38 = load double*, double** %4
%39 = getelementptr inbounds double, double* %38, i64 2
%40 = load double, double* %39
%41 = call double @cos(double %40)
%42 = load double*, double** %4
%43 = getelementptr inbounds double, double* %42, i64 1
%44 = load double, double* %43
%45 = call double @cos(double %44)
%46 = fmul double %41, %45
%47 = load double*, double** %4
%48 = getelementptr inbounds double, double* %47, i64 0
%49 = load double, double* %48
%50 = call double @sin(double %49)
%51 = fmul double %46, %50
%52 = call double @llvm.fmuladd.f64(double %33, double %37, double %51)
%53 = load double*, double** %3
%54 = getelementptr inbounds double, double* %53, i64 1
%55 = load double, double* %54
%56 = fsub double %52, %55
%57 = call i32 @fabs(double %56)
%58 = sitofp i32 %57 to double
%59 = fcmp ogt double %58, 0x3EB0C6F7A0B5ED8D
br i1 %59, label %60, label %89
60: ; preds = %2
%61 = load double*, double** %3
%62 = getelementptr inbounds double, double* %61, i64 8
%63 = load double, double* %62
%64 = call double @acos(double %63)
%65 = fneg double %64
%66 = load double*, double** %4
%67 = getelementptr inbounds double, double* %66, i64 1
store double %65, double* %67
%68 = load double*, double** %3
%69 = getelementptr inbounds double, double* %68, i64 6
%70 = load double, double* %69
%71 = fneg double %70
%72 = load double*, double** %3
%73 = getelementptr inbounds double, double* %72, i64 7
%74 = load double, double* %73
%75 = call double @atan2(double %71, double %74)
%76 = load double*, double** %4
%77 = getelementptr inbounds double, double* %76, i64 2
store double %75, double* %77
%78 = load double*, double** %3
%79 = getelementptr inbounds double, double* %78, i64 2
%80 = load double, double* %79
%81 = fneg double %80
%82 = load double*, double** %3
%83 = getelementptr inbounds double, double* %82, i64 5
%84 = load double, double* %83
%85 = fneg double %84
%86 = call double @atan2(double %81, double %85)
%87 = load double*, double** %4
%88 = getelementptr inbounds double, double* %87, i64 0
store double %86, double* %88
br label %89
89: ; preds = %60, %2
ret void
}

LLVM IR (-O2):
define void @lmattoabg(double* nocapture %0, double* nocapture %1) {
%3 = getelementptr inbounds double, double* %0, i64 8
%4 = load double, double* %3
%5 = tail call double @acos(double %4)
%6 = getelementptr inbounds double, double* %1, i64 1
store double %5, double* %6
%7 = getelementptr inbounds double, double* %0, i64 6
%8 = load double, double* %7
%9 = getelementptr inbounds double, double* %0, i64 7
%10 = load double, double* %9
%11 = fneg double %10
%12 = tail call double @atan2(double %8, double %11)
%13 = getelementptr inbounds double, double* %1, i64 2
store double %12, double* %13
%14 = getelementptr inbounds double, double* %0, i64 2
%15 = load double, double* %14
%16 = getelementptr inbounds double, double* %0, i64 5
%17 = load double, double* %16
%18 = tail call double @atan2(double %15, double %17)
store double %18, double* %1
%19 = load double, double* %13
%20 = tail call double @sin(double %19)
%21 = load double, double* %1
%22 = tail call double @cos(double %21)
%23 = load double, double* %13
%24 = tail call double @cos(double %23)
%25 = load double, double* %6
%26 = tail call double @cos(double %25)
%27 = fmul double %24, %26
%28 = load double, double* %1
%29 = tail call double @sin(double %28)
%30 = fmul double %27, %29
%31 = tail call double @llvm.fmuladd.f64(double %20, double %22, double %30)
%32 = getelementptr inbounds double, double* %0, i64 1
%33 = load double, double* %32
%34 = fsub double %31, %33
%35 = tail call i32 @fabs(double %34)
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %50
37: ; preds = %2
%38 = load double, double* %3
%39 = tail call double @acos(double %38)
%40 = fneg double %39
store double %40, double* %6
%41 = load double, double* %7
%42 = fneg double %41
%43 = load double, double* %9
%44 = tail call double @atan2(double %42, double %43)
store double %44, double* %13
%45 = load double, double* %14
%46 = fneg double %45
%47 = load double, double* %16
%48 = fneg double %47
%49 = tail call double @atan2(double %46, double %48)
store double %49, double* %1
br label %50
50: ; preds = %37, %2
ret void
}