; LLVM IR from nubot-nudt/simatch :: src/auto_referee/src/Quaternion.ll (ZNK6gazebo4math10Quaternion6GetExpEv)

; 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.gazebo::math::Quaternion" = type { double, double, double, double }

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

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

; Function Attrs: nounwind
declare double @sin(double noundef) #2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK6gazebo4math10Quaternion6GetExpEv(ptr dead_on_unwind noalias writable sret(%"class.gazebo::math::Quaternion") align 8 %0, ptr noundef nonnull align 8 dereferenceable(32) %1) #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca i1, align 1
  %8 = alloca double, align 8
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %10 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %9, i32 0, i32 1
  %11 = load double, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %9, i32 0, i32 1
  %13 = load double, ptr %12, align 8, !tbaa !9
  %14 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %9, i32 0, i32 2
  %15 = load double, ptr %14, align 8, !tbaa !12
  %16 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %9, i32 0, i32 2
  %17 = load double, ptr %16, align 8, !tbaa !12
  %18 = fmul double %15, %17
  %19 = call double @llvm.fmuladd.f64(double %11, double %13, double %18)
  %20 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %9, i32 0, i32 3
  %21 = load double, ptr %20, align 8, !tbaa !13
  %22 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %9, i32 0, i32 3
  %23 = load double, ptr %22, align 8, !tbaa !13
  %24 = call double @llvm.fmuladd.f64(double %21, double %23, double %19)
  %25 = call double @sqrt(double noundef %24) #4
  store double %25, ptr %5, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %26 = load double, ptr %5, align 8, !tbaa !14
  %27 = call double @sin(double noundef %26) #4
  store double %27, ptr %6, align 8, !tbaa !14
  store i1 false, ptr %7, align 1
  call void @_ZN6gazebo4math10QuaternionC1Ev(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %28 = load double, ptr %5, align 8, !tbaa !14
  %29 = call double @cos(double noundef %28) #4
  %30 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %0, i32 0, i32 0
  store double %29, ptr %30, align 8, !tbaa !15
  %31 = load double, ptr %6, align 8, !tbaa !14
  %32 = call double @llvm.fabs.f64(double %31)
  %33 = fcmp oge double %32, 1.000000e-03
  br i1 %33, label %34, label %53

34:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %35 = load double, ptr %6, align 8, !tbaa !14
  %36 = load double, ptr %5, align 8, !tbaa !14
  %37 = fdiv double %35, %36
  store double %37, ptr %8, align 8, !tbaa !14
  %38 = load double, ptr %8, align 8, !tbaa !14
  %39 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %9, i32 0, i32 1
  %40 = load double, ptr %39, align 8, !tbaa !9
  %41 = fmul double %38, %40
  %42 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %0, i32 0, i32 1
  store double %41, ptr %42, align 8, !tbaa !9
  %43 = load double, ptr %8, align 8, !tbaa !14
  %44 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %9, i32 0, i32 2
  %45 = load double, ptr %44, align 8, !tbaa !12
  %46 = fmul double %43, %45
  %47 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %0, i32 0, i32 2
  store double %46, ptr %47, align 8, !tbaa !12
  %48 = load double, ptr %8, align 8, !tbaa !14
  %49 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %9, i32 0, i32 3
  %50 = load double, ptr %49, align 8, !tbaa !13
  %51 = fmul double %48, %50
  %52 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %0, i32 0, i32 3
  store double %51, ptr %52, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %63

53:                                               ; preds = %2
  %54 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %9, i32 0, i32 1
  %55 = load double, ptr %54, align 8, !tbaa !9
  %56 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %0, i32 0, i32 1
  store double %55, ptr %56, align 8, !tbaa !9
  %57 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %9, i32 0, i32 2
  %58 = load double, ptr %57, align 8, !tbaa !12
  %59 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %0, i32 0, i32 2
  store double %58, ptr %59, align 8, !tbaa !12
  %60 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %9, i32 0, i32 3
  %61 = load double, ptr %60, align 8, !tbaa !13
  %62 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %0, i32 0, i32 3
  store double %61, ptr %62, align 8, !tbaa !13
  br label %63

63:                                               ; preds = %53, %34
  store i1 true, ptr %7, align 1
  %64 = load i1, ptr %7, align 1
  br i1 %64, label %66, label %65

65:                                               ; preds = %63
  call void @_ZN6gazebo4math10QuaternionD1Ev(ptr noundef nonnull align 8 dereferenceable(32) %0) #4
  br label %66

66:                                               ; preds = %65, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

; Function Attrs: nounwind
declare double @sqrt(double noundef) #2

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

; Function Attrs: nounwind
declare double @cos(double noundef) #2

declare void @_ZN6gazebo4math10QuaternionC1Ev(ptr)

declare void @_ZN6gazebo4math10QuaternionD1Ev(ptr)

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { mustprogress 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 #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 8}
!10 = !{!"_ZTSN6gazebo4math10QuaternionE", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!11 = !{!"double", !7, i64 0}
!12 = !{!10, !11, i64 16}
!13 = !{!10, !11, i64 24}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !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"

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK6gazebo4math10Quaternion6GetExpEv(ptr dead_on_unwind noalias writable sret(%"class.gazebo::math::Quaternion") align 8 %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(32) %1) local_unnamed_addr #2 align 2 {
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  %4 = load double, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %6 = load double, ptr %5, align 8, !tbaa !10
  %7 = fmul double %6, %6
  %8 = tail call double @llvm.fmuladd.f64(double %4, double %4, double %7)
  %9 = getelementptr inbounds i8, ptr %1, i64 24
  %10 = load double, ptr %9, align 8, !tbaa !11
  %11 = tail call double @llvm.fmuladd.f64(double %10, double %10, double %8)
  %sqrt = tail call double @llvm.sqrt.f64(double %11)
  %12 = tail call double @sin(double noundef %sqrt) #4
  tail call void @_ZN6gazebo4math10QuaternionC1Ev(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %13 = tail call double @cos(double noundef %sqrt) #4
  store double %13, ptr %0, align 8, !tbaa !12
  %14 = tail call double @llvm.fabs.f64(double %12)
  %15 = fcmp ult double %14, 1.000000e-03
  br i1 %15, label %24, label %16

16:                                               ; preds = %2
  %17 = fdiv double %12, %sqrt
  %18 = load <2 x double>, ptr %3, align 8, !tbaa !13
  %19 = insertelement <2 x double> poison, double %17, i64 0
  %20 = shufflevector <2 x double> %19, <2 x double> poison, <2 x i32> zeroinitializer
  %21 = fmul <2 x double> %20, %18
  %22 = load double, ptr %9, align 8, !tbaa !11
  %23 = fmul double %17, %22
  br label %27

24:                                               ; preds = %2
  %25 = load <2 x double>, ptr %3, align 8, !tbaa !13
  %26 = load double, ptr %9, align 8, !tbaa !11
  br label %27

27:                                               ; preds = %16, %24
  %.sink = phi double [ %26, %24 ], [ %23, %16 ]
  %28 = phi <2 x double> [ %25, %24 ], [ %21, %16 ]
  %29 = getelementptr inbounds i8, ptr %0, i64 8
  store <2 x double> %28, ptr %29, align 8
  %30 = getelementptr inbounds i8, ptr %0, i64 24
  store double %.sink, ptr %30, align 8
  ret void
}

; 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)
declare double @cos(double noundef) local_unnamed_addr #1

declare void @_ZN6gazebo4math10QuaternionC1Ev(ptr) local_unnamed_addr

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #2 = { mustprogress 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 8}
!6 = !{!"_ZTSN6gazebo4math10QuaternionE", !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 16}
!11 = !{!6, !7, i64 24}
!12 = !{!6, !7, i64 0}
!13 = !{!7, !7, i64 0}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass