#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 */
float asin(float);
float atan2(float const, float const);
float sqrt(int);
void Rot2Euler(const float *rotMat, float *eulerAngles) {
  float sinth = -(*(rotMat + 6));
  if (sinth > 1) {
    sinth = 1;
  } else if (sinth < -1) {
    sinth = -1;
  }
  float theta = asin(sinth);
  float costh = sqrt(1 - sinth * sinth);
  float phi, psi;
  if (costh < 1.0e-6) {
    phi = atan2((*(rotMat + 1)), (*(rotMat + 4)));
    psi = 0;
  } else {
    phi = atan2((*(rotMat + 7)), (*(rotMat + 8)));
    psi = atan2((*(rotMat + 3)), (*(rotMat)));
  }
  *(eulerAngles) = phi;
  *(eulerAngles + 1) = theta;
  *(eulerAngles + 2) = psi;
}


x86 assembly (clang, -O0):
<Rot2Euler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movss  0x18(%rax),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
movss  0xe98(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    1183 <Rot2Euler+0x53>
movss  0xe87(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    11a7 <Rot2Euler+0x77>
movss  0xe79(%rip),%xmm0
ucomiss -0x14(%rbp),%xmm0
jbe    11a2 <Rot2Euler+0x72>
movss  0xe67(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    11a7 <Rot2Euler+0x77>
movss  -0x14(%rbp),%xmm0
call   1040 <asin@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x14(%rbp),%xmm0
movss  -0x14(%rbp),%xmm1
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm1,%xmm0
movss  0xe27(%rip),%xmm1
addss  %xmm1,%xmm0
cvttss2si %xmm0,%edi
call   1050 <sqrt@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe0c(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    122f <Rot2Euler+0xff>
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  0x10(%rax),%xmm1
call   1030 <atan2@plt>
movss  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
jmp    1266 <Rot2Euler+0x136>
mov    -0x8(%rbp),%rax
movss  0x1c(%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  0x20(%rax),%xmm1
call   1030 <atan2@plt>
movss  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movss  0xc(%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm1
call   1030 <atan2@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x18(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,0x4(%rax)
movss  -0x24(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,0x8(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Rot2Euler>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movss  0x18(%rdi),%xmm0
movss  0xeb9(%rip),%xmm2
movss  0xeb5(%rip),%xmm1
ucomiss %xmm0,%xmm1
ja     116c <Rot2Euler+0x3c>
ucomiss 0xea5(%rip),%xmm0
jbe    1162 <Rot2Euler+0x32>
movaps %xmm1,%xmm2
jmp    116c <Rot2Euler+0x3c>
xorps  0xea7(%rip),%xmm0
movaps %xmm0,%xmm2
movss  %xmm2,(%rsp)
movaps %xmm2,%xmm0
call   1040 <asin@plt>
movss  %xmm0,0x4(%rsp)
movss  (%rsp),%xmm1
mulss  %xmm1,%xmm1
movss  0xe70(%rip),%xmm0
subss  %xmm1,%xmm0
cvttss2si %xmm0,%edi
call   1050 <sqrt@plt>
cvtss2sd %xmm0,%xmm0
movsd  0xe77(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    11c6 <Rot2Euler+0x96>
movss  0x4(%rbx),%xmm0
movss  0x10(%rbx),%xmm1
call   1030 <atan2@plt>
movaps %xmm0,%xmm1
xorps  %xmm0,%xmm0
jmp    11ed <Rot2Euler+0xbd>
movss  0x1c(%rbx),%xmm0
movss  0x20(%rbx),%xmm1
call   1030 <atan2@plt>
movss  %xmm0,(%rsp)
movss  (%rbx),%xmm1
movss  0xc(%rbx),%xmm0
call   1030 <atan2@plt>
movss  (%rsp),%xmm1
movss  %xmm1,(%r14)
movss  0x4(%rsp),%xmm1
movss  %xmm1,0x4(%r14)
movss  %xmm0,0x8(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @Rot2Euler(float* %0, float* %1) {
%3 = alloca float*
%4 = alloca float*
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
store float* %0, float** %3
store float* %1, float** %4
%10 = load float*, float** %3
%11 = getelementptr inbounds float, float* %10, i64 6
%12 = load float, float* %11
%13 = fneg float %12
store float %13, float* %5
%14 = load float, float* %5
%15 = fcmp ogt float %14, 1.000000e+00
br i1 %15, label %16, label %17
16: ; preds = %2
store float 1.000000e+00, float* %5
br label %22
17: ; preds = %2
%18 = load float, float* %5
%19 = fcmp olt float %18, -1.000000e+00
br i1 %19, label %20, label %21
20: ; preds = %17
store float -1.000000e+00, float* %5
br label %21
21: ; preds = %20, %17
br label %22
22: ; preds = %21, %16
%23 = load float, float* %5
%24 = call float @asin(float %23)
store float %24, float* %6
%25 = load float, float* %5
%26 = load float, float* %5
%27 = fneg float %25
%28 = call float @llvm.fmuladd.f32(float %27, float %26, float 1.000000e+00)
%29 = fptosi float %28 to i32
%30 = call float @sqrt(i32 %29)
store float %30, float* %7
%31 = load float, float* %7
%32 = fpext float %31 to double
%33 = fcmp olt double %32, 0x3EB0C6F7A0B5ED8D
br i1 %33, label %34, label %42
34: ; preds = %22
%35 = load float*, float** %3
%36 = getelementptr inbounds float, float* %35, i64 1
%37 = load float, float* %36
%38 = load float*, float** %3
%39 = getelementptr inbounds float, float* %38, i64 4
%40 = load float, float* %39
%41 = call float @atan2(float %37, float %40)
store float %41, float* %8
store float 0.000000e+00, float* %9
br label %56
42: ; preds = %22
%43 = load float*, float** %3
%44 = getelementptr inbounds float, float* %43, i64 7
%45 = load float, float* %44
%46 = load float*, float** %3
%47 = getelementptr inbounds float, float* %46, i64 8
%48 = load float, float* %47
%49 = call float @atan2(float %45, float %48)
store float %49, float* %8
%50 = load float*, float** %3
%51 = getelementptr inbounds float, float* %50, i64 3
%52 = load float, float* %51
%53 = load float*, float** %3
%54 = load float, float* %53
%55 = call float @atan2(float %52, float %54)
store float %55, float* %9
br label %56
56: ; preds = %42, %34
%57 = load float, float* %8
%58 = load float*, float** %4
store float %57, float* %58
%59 = load float, float* %6
%60 = load float*, float** %4
%61 = getelementptr inbounds float, float* %60, i64 1
store float %59, float* %61
%62 = load float, float* %9
%63 = load float*, float** %4
%64 = getelementptr inbounds float, float* %63, i64 2
store float %62, float* %64
ret void
}

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