; LLVM IR from johnb003/PlasmaSim :: adMath/src/adQuaternion.ll (ZN2ad10Quaternion8GetEulerERdS1_S1_)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%"class.ad::Quaternion" = type { double, double, double, double }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN2ad10Quaternion8GetEulerERdS1_S1_(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %3) #2 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca double, align 8
  %10 = alloca i32, align 4
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %14 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %15 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 0
  %16 = load double, ptr %15, align 8, !tbaa !9
  %17 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 1
  %18 = load double, ptr %17, align 8, !tbaa !12
  %19 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 2
  %20 = load double, ptr %19, align 8, !tbaa !13
  %21 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 3
  %22 = load double, ptr %21, align 8, !tbaa !14
  %23 = fmul double %20, %22
  %24 = call double @llvm.fmuladd.f64(double %16, double %18, double %23)
  store double %24, ptr %9, align 8, !tbaa !15
  %25 = load double, ptr %9, align 8, !tbaa !15
  %26 = fcmp ogt double %25, 4.990000e-01
  br i1 %26, label %27, label %37

27:                                               ; preds = %4
  %28 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 0
  %29 = load double, ptr %28, align 8, !tbaa !9
  %30 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 3
  %31 = load double, ptr %30, align 8, !tbaa !14
  %32 = call double @atan2(double noundef %29, double noundef %31) #4
  %33 = fmul double 2.000000e+00, %32
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  store double %33, ptr %34, align 8, !tbaa !15
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  store double 0x3FF921FB54442D18, ptr %35, align 8, !tbaa !15
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  store double 0.000000e+00, ptr %36, align 8, !tbaa !15
  store i32 1, ptr %10, align 4
  br label %109

37:                                               ; preds = %4
  %38 = load double, ptr %9, align 8, !tbaa !15
  %39 = fcmp olt double %38, -4.990000e-01
  br i1 %39, label %40, label %50

40:                                               ; preds = %37
  %41 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 0
  %42 = load double, ptr %41, align 8, !tbaa !9
  %43 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 3
  %44 = load double, ptr %43, align 8, !tbaa !14
  %45 = call double @atan2(double noundef %42, double noundef %44) #4
  %46 = fmul double -2.000000e+00, %45
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  store double %46, ptr %47, align 8, !tbaa !15
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  store double 0xBFF921FB54442D18, ptr %48, align 8, !tbaa !15
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  store double 0.000000e+00, ptr %49, align 8, !tbaa !15
  store i32 1, ptr %10, align 4
  br label %109

50:                                               ; preds = %37
  br label %51

51:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %52 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 0
  %53 = load double, ptr %52, align 8, !tbaa !9
  %54 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 0
  %55 = load double, ptr %54, align 8, !tbaa !9
  %56 = fmul double %53, %55
  store double %56, ptr %11, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %57 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 1
  %58 = load double, ptr %57, align 8, !tbaa !12
  %59 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 1
  %60 = load double, ptr %59, align 8, !tbaa !12
  %61 = fmul double %58, %60
  store double %61, ptr %12, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %62 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 2
  %63 = load double, ptr %62, align 8, !tbaa !13
  %64 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 2
  %65 = load double, ptr %64, align 8, !tbaa !13
  %66 = fmul double %63, %65
  store double %66, ptr %13, align 8, !tbaa !15
  %67 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 1
  %68 = load double, ptr %67, align 8, !tbaa !12
  %69 = fmul double 2.000000e+00, %68
  %70 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 3
  %71 = load double, ptr %70, align 8, !tbaa !14
  %72 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 0
  %73 = load double, ptr %72, align 8, !tbaa !9
  %74 = fmul double 2.000000e+00, %73
  %75 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 2
  %76 = load double, ptr %75, align 8, !tbaa !13
  %77 = fmul double %74, %76
  %78 = fneg double %77
  %79 = call double @llvm.fmuladd.f64(double %69, double %71, double %78)
  %80 = load double, ptr %12, align 8, !tbaa !15
  %81 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %80, double 1.000000e+00)
  %82 = load double, ptr %13, align 8, !tbaa !15
  %83 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %82, double %81)
  %84 = call double @atan2(double noundef %79, double noundef %83) #4
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  store double %84, ptr %85, align 8, !tbaa !15
  %86 = load double, ptr %9, align 8, !tbaa !15
  %87 = fmul double 2.000000e+00, %86
  %88 = call double @asin(double noundef %87) #4
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  store double %88, ptr %89, align 8, !tbaa !15
  %90 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 0
  %91 = load double, ptr %90, align 8, !tbaa !9
  %92 = fmul double 2.000000e+00, %91
  %93 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 3
  %94 = load double, ptr %93, align 8, !tbaa !14
  %95 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 1
  %96 = load double, ptr %95, align 8, !tbaa !12
  %97 = fmul double 2.000000e+00, %96
  %98 = getelementptr inbounds %"class.ad::Quaternion", ptr %14, i32 0, i32 2
  %99 = load double, ptr %98, align 8, !tbaa !13
  %100 = fmul double %97, %99
  %101 = fneg double %100
  %102 = call double @llvm.fmuladd.f64(double %92, double %94, double %101)
  %103 = load double, ptr %11, align 8, !tbaa !15
  %104 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %103, double 1.000000e+00)
  %105 = load double, ptr %13, align 8, !tbaa !15
  %106 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %105, double %104)
  %107 = call double @atan2(double noundef %102, double noundef %106) #4
  %108 = load ptr, ptr %7, align 8, !tbaa !5
  store double %107, ptr %108, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  store i32 0, ptr %10, align 4
  br label %109

109:                                              ; preds = %51, %40, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %110 = load i32, ptr %10, align 4
  switch i32 %110, label %112 [
    i32 0, label %111
    i32 1, label %111
  ]

111:                                              ; preds = %109, %109
  ret void

112:                                              ; preds = %109
  unreachable
}

; Function Attrs: nounwind
declare double @atan2(double noundef, double noundef) #3

; Function Attrs: nounwind
declare double @asin(double noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTSN2ad10QuaternionE", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!11 = !{!"double", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!10, !11, i64 16}
!14 = !{!10, !11, i64 24}
!15 = !{!11, !11, i64 0}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(write, argmem: readwrite) uwtable
define dso_local void @_ZN2ad10Quaternion8GetEulerERdS1_S1_(ptr nocapture noundef nonnull readonly align 8 dereferenceable(32) %0, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %1, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %2, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %3) local_unnamed_addr #1 align 2 {
  %5 = load double, ptr %0, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load double, ptr %6, align 8, !tbaa !10
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load double, ptr %8, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load double, ptr %10, align 8, !tbaa !12
  %12 = fmul double %9, %11
  %13 = tail call double @llvm.fmuladd.f64(double %5, double %7, double %12)
  %14 = fcmp ogt double %13, 4.990000e-01
  br i1 %14, label %15, label %18

15:                                               ; preds = %4
  %16 = tail call double @atan2(double noundef %5, double noundef %11) #3
  %17 = fmul double %16, 2.000000e+00
  store double %17, ptr %1, align 8, !tbaa !13
  store double 0x3FF921FB54442D18, ptr %2, align 8, !tbaa !13
  store double 0.000000e+00, ptr %3, align 8, !tbaa !13
  br label %47

18:                                               ; preds = %4
  %19 = fcmp olt double %13, -4.990000e-01
  br i1 %19, label %20, label %23

20:                                               ; preds = %18
  %21 = tail call double @atan2(double noundef %5, double noundef %11) #3
  %22 = fmul double %21, -2.000000e+00
  store double %22, ptr %1, align 8, !tbaa !13
  store double 0xBFF921FB54442D18, ptr %2, align 8, !tbaa !13
  store double 0.000000e+00, ptr %3, align 8, !tbaa !13
  br label %47

23:                                               ; preds = %18
  %24 = fmul double %5, %5
  %25 = fmul double %7, %7
  %26 = fmul double %9, %9
  %27 = fmul double %7, 2.000000e+00
  %28 = fmul double %5, -2.000000e+00
  %29 = fmul double %28, %9
  %30 = tail call double @llvm.fmuladd.f64(double %27, double %11, double %29)
  %31 = tail call double @llvm.fmuladd.f64(double %25, double -2.000000e+00, double 1.000000e+00)
  %32 = tail call double @llvm.fmuladd.f64(double %26, double -2.000000e+00, double %31)
  %33 = tail call double @atan2(double noundef %30, double noundef %32) #3
  store double %33, ptr %1, align 8, !tbaa !13
  %34 = fmul double %13, 2.000000e+00
  %35 = tail call double @asin(double noundef %34) #3
  store double %35, ptr %3, align 8, !tbaa !13
  %36 = load double, ptr %0, align 8, !tbaa !5
  %37 = fmul double %36, 2.000000e+00
  %38 = load double, ptr %10, align 8, !tbaa !12
  %39 = load double, ptr %6, align 8, !tbaa !10
  %40 = load double, ptr %8, align 8, !tbaa !11
  %41 = fmul double %39, -2.000000e+00
  %42 = fmul double %41, %40
  %43 = tail call double @llvm.fmuladd.f64(double %37, double %38, double %42)
  %44 = tail call double @llvm.fmuladd.f64(double %24, double -2.000000e+00, double 1.000000e+00)
  %45 = tail call double @llvm.fmuladd.f64(double %26, double -2.000000e+00, double %44)
  %46 = tail call double @atan2(double noundef %43, double noundef %45) #3
  store double %46, ptr %2, align 8, !tbaa !13
  br label %47

47:                                               ; preds = %23, %20, %15
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @atan2(double noundef, double noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @asin(double noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(write, argmem: readwrite) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress nofree nounwind willreturn memory(write) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !7, i64 0}
!6 = !{!"_ZTSN2ad10QuaternionE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!6, !7, i64 16}
!12 = !{!6, !7, i64 24}
!13 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass