#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 asin(double);
double atan2(double, double);
double cos(double);
int fabs(double);
void ltr_int_matrix_to_euler(double matrix[3][3], double *pitch, double *yaw,
                             double *roll) {
  double tmp = matrix[0][2];
  if (tmp < -1.0f)
    tmp = -1.0f;
  if (tmp > 1.0f)
    tmp = 1.0f;
  *yaw = asin(tmp);
  double yc = cos(*yaw);
  if (fabs(yc) > 1e-5) {
    *pitch = atan2(-matrix[1][2] / yc, matrix[2][2] / yc);
    *roll = atan2(-matrix[0][1] / yc, matrix[0][0] / yc);
  } else {
    *pitch = 0.0f;
    *roll = atan2(matrix[1][0], matrix[1][1]);
  }
}


x86 assembly (clang, -O0):
<ltr_int_matrix_to_euler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe92(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1186 <ltr_int_matrix_to_euler+0x46>
movsd  0xe7f(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xe75(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11aa <ltr_int_matrix_to_euler+0x6a>
movsd  0xe63(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <asin@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
call   1060 <cos@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe2c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1272 <ltr_int_matrix_to_euler+0x132>
mov    -0x8(%rbp),%rax
movsd  0x28(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x40(%rax),%xmm1
divsd  -0x30(%rbp),%xmm1
call   1030 <atan2@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
divsd  -0x30(%rbp),%xmm1
call   1030 <atan2@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    129c <ltr_int_matrix_to_euler+0x15c>
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x20(%rax),%xmm1
call   1030 <atan2@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ltr_int_matrix_to_euler>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%rbx
movsd  0xea4(%rip),%xmm1
maxsd  0x10(%rdi),%xmm1
movsd  0xe9f(%rip),%xmm0
minsd  %xmm1,%xmm0
call   1050 <asin@plt>
movsd  %xmm0,(%r12)
call   1060 <cos@plt>
movsd  %xmm0,(%rsp)
call   1040 <fabs@plt>
test   %eax,%eax
jle    11d4 <ltr_int_matrix_to_euler+0x94>
movsd  0x28(%rbx),%xmm0
xorpd  0xe78(%rip),%xmm0
movsd  (%rsp),%xmm2
divsd  %xmm2,%xmm0
movsd  0x40(%rbx),%xmm1
divsd  %xmm2,%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,(%r15)
movsd  0x8(%rbx),%xmm0
xorpd  0xe4f(%rip),%xmm0
movsd  (%rsp),%xmm2
divsd  %xmm2,%xmm0
movsd  (%rbx),%xmm1
divsd  %xmm2,%xmm1
jmp    11e5 <ltr_int_matrix_to_euler+0xa5>
movq   $0x0,(%r15)
movsd  0x18(%rbx),%xmm0
movsd  0x20(%rbx),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @ltr_int_matrix_to_euler([3 x double]* %0, double* %1, double* %2, double* %3) {
%5 = alloca [3 x double]*
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
%10 = alloca double
store [3 x double]* %0, [3 x double]** %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %8
%11 = load [3 x double]*, [3 x double]** %5
%12 = getelementptr inbounds [3 x double], [3 x double]* %11, i64 0
%13 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 2
%14 = load double, double* %13
store double %14, double* %9
%15 = load double, double* %9
%16 = fcmp olt double %15, -1.000000e+00
br i1 %16, label %17, label %18
17: ; preds = %4
store double -1.000000e+00, double* %9
br label %18
18: ; preds = %17, %4
%19 = load double, double* %9
%20 = fcmp ogt double %19, 1.000000e+00
br i1 %20, label %21, label %22
21: ; preds = %18
store double 1.000000e+00, double* %9
br label %22
22: ; preds = %21, %18
%23 = load double, double* %9
%24 = call double @asin(double %23)
%25 = load double*, double** %7
store double %24, double* %25
%26 = load double*, double** %7
%27 = load double, double* %26
%28 = call double @cos(double %27)
store double %28, double* %10
%29 = load double, double* %10
%30 = call i32 @fabs(double %29)
%31 = sitofp i32 %30 to double
%32 = fcmp ogt double %31, 1.000000e-05
br i1 %32, label %33, label %64
33: ; preds = %22
%34 = load [3 x double]*, [3 x double]** %5
%35 = getelementptr inbounds [3 x double], [3 x double]* %34, i64 1
%36 = getelementptr inbounds [3 x double], [3 x double]* %35, i64 0, i64 2
%37 = load double, double* %36
%38 = fneg double %37
%39 = load double, double* %10
%40 = fdiv double %38, %39
%41 = load [3 x double]*, [3 x double]** %5
%42 = getelementptr inbounds [3 x double], [3 x double]* %41, i64 2
%43 = getelementptr inbounds [3 x double], [3 x double]* %42, i64 0, i64 2
%44 = load double, double* %43
%45 = load double, double* %10
%46 = fdiv double %44, %45
%47 = call double @atan2(double %40, double %46)
%48 = load double*, double** %6
store double %47, double* %48
%49 = load [3 x double]*, [3 x double]** %5
%50 = getelementptr inbounds [3 x double], [3 x double]* %49, i64 0
%51 = getelementptr inbounds [3 x double], [3 x double]* %50, i64 0, i64 1
%52 = load double, double* %51
%53 = fneg double %52
%54 = load double, double* %10
%55 = fdiv double %53, %54
%56 = load [3 x double]*, [3 x double]** %5
%57 = getelementptr inbounds [3 x double], [3 x double]* %56, i64 0
%58 = getelementptr inbounds [3 x double], [3 x double]* %57, i64 0, i64 0
%59 = load double, double* %58
%60 = load double, double* %10
%61 = fdiv double %59, %60
%62 = call double @atan2(double %55, double %61)
%63 = load double*, double** %8
store double %62, double* %63
br label %76
64: ; preds = %22
%65 = load double*, double** %6
store double 0.000000e+00, double* %65
%66 = load [3 x double]*, [3 x double]** %5
%67 = getelementptr inbounds [3 x double], [3 x double]* %66, i64 1
%68 = getelementptr inbounds [3 x double], [3 x double]* %67, i64 0, i64 0
%69 = load double, double* %68
%70 = load [3 x double]*, [3 x double]** %5
%71 = getelementptr inbounds [3 x double], [3 x double]* %70, i64 1
%72 = getelementptr inbounds [3 x double], [3 x double]* %71, i64 0, i64 1
%73 = load double, double* %72
%74 = call double @atan2(double %69, double %73)
%75 = load double*, double** %8
store double %74, double* %75
br label %76
76: ; preds = %64, %33
ret void
}

LLVM IR (-O2):
define void @ltr_int_matrix_to_euler([3 x double]* nocapture %0, double* nocapture writeonly %1, double* nocapture writeonly %2, double* nocapture writeonly %3) {
%5 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 0, i64 2
%6 = load double, double* %5
%7 = fcmp olt double %6, -1.000000e+00
%8 = select i1 %7, double -1.000000e+00, double %6
%9 = fcmp ogt double %8, 1.000000e+00
%10 = select i1 %9, double 1.000000e+00, double %8
%11 = tail call double @asin(double %10)
store double %11, double* %2
%12 = tail call double @cos(double %11)
%13 = tail call i32 @fabs(double %12)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %32
15: ; preds = %4
%16 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 1, i64 2
%17 = load double, double* %16
%18 = fneg double %17
%19 = fdiv double %18, %12
%20 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 2, i64 2
%21 = load double, double* %20
%22 = fdiv double %21, %12
%23 = tail call double @atan2(double %19, double %22)
store double %23, double* %1
%24 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 0, i64 1
%25 = load double, double* %24
%26 = fneg double %25
%27 = fdiv double %26, %12
%28 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 0, i64 0
%29 = load double, double* %28
%30 = fdiv double %29, %12
%31 = tail call double @atan2(double %27, double %30)
br label %38
32: ; preds = %4
store double 0.000000e+00, double* %1
%33 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 1, i64 0
%34 = load double, double* %33
%35 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 1, i64 1
%36 = load double, double* %35
%37 = tail call double @atan2(double %34, double %36)
br label %38
38: ; preds = %32, %15
%39 = phi double [ %37, %32 ], [ %31, %15 ]
store double %39, double* %3
ret void
}